Hello community, here is the log from the commit of package autoyast2 for openSUSE:Factory checked in at 2020-09-25 16:26:56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/autoyast2 (Old) and /work/SRC/openSUSE:Factory/.autoyast2.new.4249 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "autoyast2" Fri Sep 25 16:26:56 2020 rev:290 rq:837192 version:4.3.53 Changes: -------- --- /work/SRC/openSUSE:Factory/autoyast2/autoyast2.changes 2020-09-21 17:08:48.999212985 +0200 +++ /work/SRC/openSUSE:Factory/.autoyast2.new.4249/autoyast2.changes 2020-09-25 16:28:49.159746054 +0200 @@ -1,0 +2,25 @@ +Thu Sep 24 13:04:47 UTC 2020 - Imobach Gonzalez Sosa <igonzalezs...@suse.com> + +- Add the schema for 'backup' and 'upgrade' sections (bsc#1176834). +- 4.3.53 + +------------------------------------------------------------------- +Thu Sep 24 11:03:42 UTC 2020 - Imobach Gonzalez Sosa <igonzalezs...@suse.com> + +- Set 0o600 permissions to the generated profile when cloning + a system (bsc#1174202). + +------------------------------------------------------------------- +Mon Sep 21 15:04:10 UTC 2020 - Josef Reidinger <jreidin...@suse.com> + +- Add new action `yast2 autoyast check-profile` (related to + bsc#1175735) which features: +-- XML syntax check +-- XML schema validation +-- try to fetch the profile +-- generate dynamic profile erb or classes/rules +-- optional try to import profile and detect any issues with it +-- optional run of scripts including dynamic profiles in pre-script +-- 4.3.52 + +------------------------------------------------------------------- Old: ---- autoyast2-4.3.51.tar.bz2 New: ---- autoyast2-4.3.53.tar.bz2 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ autoyast2.spec ++++++ --- /var/tmp/diff_new_pack.UMI0qc/_old 2020-09-25 16:28:49.775746599 +0200 +++ /var/tmp/diff_new_pack.UMI0qc/_new 2020-09-25 16:28:49.779746603 +0200 @@ -22,7 +22,7 @@ %endif Name: autoyast2 -Version: 4.3.51 +Version: 4.3.53 Release: 0 Summary: YaST2 - Automated Installation License: GPL-2.0-only ++++++ autoyast2-4.3.51.tar.bz2 -> autoyast2-4.3.53.tar.bz2 ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoyast2-4.3.51/modconfig/README.md new/autoyast2-4.3.53/modconfig/README.md --- old/autoyast2-4.3.51/modconfig/README.md 1970-01-01 01:00:00.000000000 +0100 +++ new/autoyast2-4.3.53/modconfig/README.md 2020-09-24 17:13:19.000000000 +0200 @@ -0,0 +1,7 @@ +# AutoYaST-specific Desktop Files + +The files included in this directory are installed in the `/usr/share/autoinstall/modules` and are +only used by AutoYaST. The format of those files is [documented in the yast2 +repository](https://github.com/yast/yast-yast2/blob/master/doc/desktop_file.md). Additionally, these +files are used in order to decide which sections are included in the schema (check the +`src/autoyast-rnc` directory for the schema definition files). diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoyast2-4.3.51/modconfig/backup.desktop new/autoyast2-4.3.53/modconfig/backup.desktop --- old/autoyast2-4.3.51/modconfig/backup.desktop 1970-01-01 01:00:00.000000000 +0100 +++ new/autoyast2-4.3.53/modconfig/backup.desktop 2020-09-24 17:13:19.000000000 +0200 @@ -0,0 +1,24 @@ +[Desktop Entry] +Type=Application +Categories=Settings;System;Qt;X-SuSE-YaST;X-SuSE-YaST-Misc; + +X-KDE-ModuleType=Library +X-KDE-HasReadOnlyMode=true +X-SuSE-YaST-Call=backup + +X-SuSE-YaST-Group=System +X-SuSE-YaST-Argument= +X-SuSE-YaST-RootOnly=true +X-SuSE-YaST-AutoInst=write +X-SuSE-YaST-Geometry= +X-SuSE-YaST-SortKey= +X-SuSE-YaST-AutoInstResource=backup +X-SuSE-YaST-AutoInstPath=install +X-SuSE-YaST-AutoInstSchema=backup.rnc + +Icon=yast-backup +Exec= + +Name=Backup Options +GenericName=Backup Autoinstallation Options +StartupNotify=true diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoyast2-4.3.51/modconfig/upgrade.desktop new/autoyast2-4.3.53/modconfig/upgrade.desktop --- old/autoyast2-4.3.51/modconfig/upgrade.desktop 1970-01-01 01:00:00.000000000 +0100 +++ new/autoyast2-4.3.53/modconfig/upgrade.desktop 2020-09-24 17:13:19.000000000 +0200 @@ -0,0 +1,24 @@ +[Desktop Entry] +Type=Application +Categories=Settings;System;Qt;X-SuSE-YaST;X-SuSE-YaST-Misc; + +X-KDE-ModuleType=Library +X-KDE-HasReadOnlyMode=true +X-SuSE-YaST-Call=upgrade + +X-SuSE-YaST-Group=System +X-SuSE-YaST-Argument= +X-SuSE-YaST-RootOnly=true +X-SuSE-YaST-AutoInst=write +X-SuSE-YaST-Geometry= +X-SuSE-YaST-SortKey= +X-SuSE-YaST-AutoInstResource=upgrade +X-SuSE-YaST-AutoInstPath=install +X-SuSE-YaST-AutoInstSchema=upgrade.rnc + +Icon=yast-upgrade +Exec= + +Name=Upgrade Options +GenericName=Upgrade Autoinstallation Options +StartupNotify=true diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoyast2-4.3.51/package/autoyast2.changes new/autoyast2-4.3.53/package/autoyast2.changes --- old/autoyast2-4.3.51/package/autoyast2.changes 2020-09-21 12:12:20.000000000 +0200 +++ new/autoyast2-4.3.53/package/autoyast2.changes 2020-09-24 17:13:19.000000000 +0200 @@ -1,11 +1,36 @@ ------------------------------------------------------------------- +Thu Sep 24 13:04:47 UTC 2020 - Imobach Gonzalez Sosa <igonzalezs...@suse.com> + +- Add the schema for 'backup' and 'upgrade' sections (bsc#1176834). +- 4.3.53 + +------------------------------------------------------------------- +Thu Sep 24 11:03:42 UTC 2020 - Imobach Gonzalez Sosa <igonzalezs...@suse.com> + +- Set 0o600 permissions to the generated profile when cloning + a system (bsc#1174202). + +------------------------------------------------------------------- +Mon Sep 21 15:04:10 UTC 2020 - Josef Reidinger <jreidin...@suse.com> + +- Add new action `yast2 autoyast check-profile` (related to + bsc#1175735) which features: +-- XML syntax check +-- XML schema validation +-- try to fetch the profile +-- generate dynamic profile erb or classes/rules +-- optional try to import profile and detect any issues with it +-- optional run of scripts including dynamic profiles in pre-script +-- 4.3.52 + +------------------------------------------------------------------- Fri Sep 18 12:20:10 CEST 2020 - sch...@suse.de - Removing package evaluation via AY schema. Using autoyast(...) supplements instead (bsc#1146494). - 4.3.51 -------------------------------------------------------------------- +------------------------------------------------------------------- Thu Sep 17 20:03:44 UTC 2020 - Knut Anderssen <kanders...@suse.com> - Import general and report sections in case that some pre-script diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoyast2-4.3.51/package/autoyast2.spec new/autoyast2-4.3.53/package/autoyast2.spec --- old/autoyast2-4.3.51/package/autoyast2.spec 2020-09-21 12:12:20.000000000 +0200 +++ new/autoyast2-4.3.53/package/autoyast2.spec 2020-09-24 17:13:19.000000000 +0200 @@ -22,7 +22,7 @@ %endif Name: autoyast2 -Version: 4.3.51 +Version: 4.3.53 Release: 0 Summary: YaST2 - Automated Installation License: GPL-2.0-only diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoyast2-4.3.51/src/autoyast-rnc/backup.rnc new/autoyast2-4.3.53/src/autoyast-rnc/backup.rnc --- old/autoyast2-4.3.51/src/autoyast-rnc/backup.rnc 1970-01-01 01:00:00.000000000 +0100 +++ new/autoyast2-4.3.53/src/autoyast-rnc/backup.rnc 2020-09-24 17:13:19.000000000 +0200 @@ -0,0 +1,10 @@ +default namespace = "http://www.suse.com/1.0/yast2ns" +namespace config = "http://www.suse.com/1.0/configns" +namespace a = "http://relaxng.org/ns/compatibility/annotations/1.0" + +backup = + element backup { + element modified { BOOLEAN }? & + element remove_old { BOOLEAN }? & + element sysconfig { BOOLEAN }? +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoyast2-4.3.51/src/autoyast-rnc/upgrade.rnc new/autoyast2-4.3.53/src/autoyast-rnc/upgrade.rnc --- old/autoyast2-4.3.51/src/autoyast-rnc/upgrade.rnc 1970-01-01 01:00:00.000000000 +0100 +++ new/autoyast2-4.3.53/src/autoyast-rnc/upgrade.rnc 2020-09-24 17:13:19.000000000 +0200 @@ -0,0 +1,8 @@ +default namespace = "http://www.suse.com/1.0/yast2ns" +namespace config = "http://www.suse.com/1.0/configns" +namespace a = "http://relaxng.org/ns/compatibility/annotations/1.0" + +upgrade = + element upgrade { + element stop_on_solver_conflict { BOOLEAN }? +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoyast2-4.3.51/src/lib/autoinstall/clients/autoyast.rb new/autoyast2-4.3.53/src/lib/autoinstall/clients/autoyast.rb --- old/autoyast2-4.3.51/src/lib/autoinstall/clients/autoyast.rb 2020-09-21 12:12:20.000000000 +0200 +++ new/autoyast2-4.3.53/src/lib/autoinstall/clients/autoyast.rb 2020-09-24 17:13:19.000000000 +0200 @@ -21,17 +21,18 @@ require "autoinstall/auto_sequence" require "autoinstall/entries/registry" require "autoinstall/importer" +require "autoinstall/profile_checker" -Yast.import "Pkg" -Yast.import "Wizard" -Yast.import "Mode" -Yast.import "Profile" -Yast.import "AutoinstConfig" -Yast.import "Popup" Yast.import "AddOnProduct" -Yast.import "CommandLine" Yast.import "AutoInstall" +Yast.import "AutoinstConfig" +Yast.import "CommandLine" +Yast.import "Mode" +Yast.import "Pkg" +Yast.import "Popup" +Yast.import "Profile" Yast.import "UI" +Yast.import "Wizard" module Y2Autoinstallation module Clients @@ -64,43 +65,64 @@ "help" => _("AutoYaST"), "guihandler" => fun_ref(method(:auto_sequence), "any ()"), "actions" => { - "ui" => { + "ui" => { "handler" => fun_ref( method(:run_ui), "boolean (map <string, string>)" ), "help" => ui_action_help }, - "file" => { + "file" => { "handler" => fun_ref( method(:run_ui), "boolean (map <string, string>)" ), "help" => file_action_help }, - "module" => { + "module" => { "handler" => fun_ref( method(:run_ui), "boolean (map <string, string>)" ), "help" => module_action_help }, - "list-modules" => { + "list-modules" => { "handler" => fun_ref( method(:list_modules), "void ()" ), "help" => list_modules_action_help + }, + "check-profile" => { + "handler" => fun_ref( + method(:check_profile), + "boolean (map <string, string>)" + ), + "help" => check_profile_action_help } }, "options" => { - "filename" => { "type" => "string", "help" => "filename=XML_PROFILE" }, - "modname" => { "type" => "string", "help" => "modname=AYAST_MODULE" } + "filename" => { "type" => "string", "help" => "Which profile to use. In " \ + "check-profile case it supports also remote location like " \ + "filename=ftp://test.com/example.xml" }, + "modname" => { "type" => "string", "help" => "modname=AYAST_MODULE" }, + "output" => { "type" => "string", "help" => "where evaluated profile will be " \ + "written. Default is '~/check_profile_result.xml'. Example 'filename=~/test.xml'." }, + "run-scripts" => { "type" => "enum", + "help" => "run also scripts that are defined in profile. " \ + "By default false. Example: run-scripts=true", + "typespec" => ["true", "false"] }, + "import-all" => { "type" => "enum", + "help" => "Do testing import of all sections in profile. " \ + "Note that scripts are imported when run-scripts is set to true. By default true. " \ + "Example: import-all=false", + "typespec" => ["true", "false"] } }, "mappings" => { - "ui" => ["filename", "modname"], - "file" => ["filename", "modname"], - "module" => ["filename", "modname"] + "check-profile" => ["filename", "run-scripts", "output", "import-all"], + "file" => ["filename", "modname"], + "module" => ["filename", "modname"], + "ui" => ["filename", "modname"] } } @@ -137,6 +159,25 @@ ) end + # Check if profile is valid + # + # @param options [Hash] Command line options + # @return [Boolean] true if profile is valid + def check_profile(options) + log.info "calling check profile with #{options.inspect}" + + if !options["filename"] + Yast::CommandLine.Error(_("Filename parameter is mandatory.")) + return false + end + + checker = ProfileChecker.new(options["filename"], + import_all: options["import_all"] != "false", + run_scripts: options["run-scripts"] == "true", + target_file: options["output"] || "~/check_profile_result.xml") + checker.check + end + private # Reads and imports a profile @@ -218,6 +259,13 @@ def list_modules_action_help _("List known modules.") end + + # @return [String] + def check_profile_action_help + _("Check if profile is valid. Also evaluate profile for dynamic profiles like " \ + "ERB or rules/classes. If run-scripts parameter is set to 'true' it can be used " \ + "also to validate dynamic profiles generated by pre-scripts.") + end end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoyast2-4.3.51/src/lib/autoinstall/clients/clone_system.rb new/autoyast2-4.3.53/src/lib/autoinstall/clients/clone_system.rb --- old/autoyast2-4.3.51/src/lib/autoinstall/clients/clone_system.rb 2020-09-21 12:12:20.000000000 +0200 +++ new/autoyast2-4.3.53/src/lib/autoinstall/clients/clone_system.rb 2020-09-24 17:13:19.000000000 +0200 @@ -18,6 +18,7 @@ # find current contact information at www.suse.com. require "yast" +require "fileutils" require "autoinstall/entries/registry" @@ -151,8 +152,12 @@ # always clone general Yast::ProductControl.clone_modules + ["general"] end + Yast::AutoinstClone.Process(target: target) begin + # The file might contain sensitive data, so let's set the permissions to 0o600. + ::FileUtils.touch(filename) + ::FileUtils.chmod(0o600, filename) Yast::XML.YCPToXMLFile(:profile, Yast::Profile.current, filename) rescue Yast::XMLSerializationError => e log.error "Creation of XML failed with #{e.inspect}" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoyast2-4.3.51/src/lib/autoinstall/profile_checker.rb new/autoyast2-4.3.53/src/lib/autoinstall/profile_checker.rb --- old/autoyast2-4.3.51/src/lib/autoinstall/profile_checker.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/autoyast2-4.3.53/src/lib/autoinstall/profile_checker.rb 2020-09-24 17:13:19.000000000 +0200 @@ -0,0 +1,170 @@ +# Copyright (c) [2020] SUSE LLC +# +# All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2 of the GNU General Public License as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, contact SUSE LLC. +# +# To contact SUSE LLC about this file by physical or electronic mail, you may +# find current contact information at www.suse.com. + +require "yast" +require "yast2/popup" + +require "autoinstall/importer" + +Yast.import "AutoInstall" +Yast.import "AutoinstConfig" +Yast.import "AutoinstScripts" +Yast.import "Mode" +Yast.import "Popup" +Yast.import "ProfileLocation" + +module Y2Autoinstallation + # Goal of this class is to do check of given profile file. It can evaluate + # dynamic profiles (erb, rules/classes, pre-script ). It contain also all UI + # interaction like showing feedback, or asking for confirmation. + class ProfileChecker + include Yast::I18n + include Yast::Logger + + # @param filename [String] can be relative path to pwd, absolute path or + # any URL that AY supports. + # @param import_all [Boolean] if importing all sections and checking for + # autoyast issues. Can be time consuming. + # @param run_scripts [Boolean] if also run all scripts defined in profile + # to check its correctness. It is also needed for dynamic profiles using + # pre-script generation. Can be dangeours if scripts contain destructive + # operations + # @param target_file [String] absolute path where to write resulting profile. + def initialize(filename, import_all:, run_scripts:, target_file:) + textdomain "autoinst" + + @filename = filename + @import_all = import_all + @run_scripts = run_scripts + @target_file = target_file + end + + # Runs the check according to flags specified in constructor. + def check + Yast::Mode.SetUI("dialog") # check profile use UI and not cmdline + + Yast::Popup.Feedback(_("Obtaining Profile"), + _("Fetching and generating final AutoYaST profile")) do + Yast::AutoinstConfig.ParseCmdLine(path) + res = Yast::ProfileLocation.Process + return res unless res + end + + # This is not problematic from security POV as it is own home, + # so another user cannot create malicious link + target_file = ::File.expand_path(@target_file) + ::FileUtils.cp(Yast::AutoinstConfig.xml_tmpfile, target_file) + return false unless import_profile(target_file) + + res = run_scripts(target_file) + Yast2::Popup.show("Resulting autoyast profile is at #{target_file}") + + res + end + + private + + # compute path that can be passed to parsing + def path + path = @filename + + if path !~ /^[a-zA-Z0-9]+:\// + path = File.join(Dir.pwd, path) unless path.start_with?("/") + path = "file://#{path}" + end + + path + end + + # Reads and imports a profile + # + # @param filename [String] Profile path + # @return [Boolean] if import does not find any issue + def import_profile(filename) + return true unless @import_all + + if !Yast::Profile.ReadXML(filename) + Yast2::Popup.show( + _( + "Error while parsing the control file.\n" \ + "Check the log files for more details or fix the\n" \ + "AutoYaST profile and try again.\n" + ), headline: :error + ) + end + Yast::Popup.Feedback( + _("Reading configuration data"), + _("This may take a while") + ) do + Y2Autoinstallation::Importer.new(Yast::Profile.current).import_sections + end + + Yast::AutoInstall.valid_imported_values + end + + SCRIPTS_PARAMS = [ + ["pre-scripts", true], + ["postpartitioning-scripts", true], + ["chroot-scripts", true], + ["chroot-scripts", false], + ["post-scripts", false], + ["init-scripts", false] + ].freeze + # run all scripts defined in profile + # @return [Boolean] true if all scripts works + def run_scripts(filename) + return true unless @run_scripts + + res = true + + Yast::Popup.Feedback(_("Executing Scripts"), + _("Trying to run all scripts in AutoYaST profile.")) do + log.info "Running scripts" + mode = Yast::Mode.mode + Yast::Mode.SetMode("autoinstallation") # to run scripts we need autoinst mode + # we need to import at least scripts if not all of them are imported + if !@import_all + Yast::Profile.ReadXML(filename) + Yast::AutoinstScripts.Import(Yast::Profile.current.fetch("scripts", {})) + log.info "importing scripts #{Yast::Profile.current.fetch("scripts", {})}" + end + SCRIPTS_PARAMS.each do |type, special| + # pre-scripts has some expectations where profile lives + if type == "pre-scripts" + # clean previous content + if File.exist?(Yast::AutoinstConfig.profile_dir) + ::FileUtils.rm_r(Yast::AutoinstConfig.profile_dir) + end + ::FileUtils.mkdir_p(Yast::AutoinstConfig.profile_dir) + ::FileUtils.cp(filename, Yast::AutoinstConfig.profile_path) + end + res = Yast::AutoinstScripts.Write(type, special) && res + # pre scripts can do modification of profile, so reload it + if type == "pre-scripts" && File.exist?(Yast::AutoinstConfig.modified_profile) + ::FileUtils.cp(Yast::AutoinstConfig.modified_profile, filename) + return false unless import_profile(filename) + end + end + Yast::Mode.SetMode(mode) # restore previous mode + end + + res + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoyast2-4.3.51/src/modules/AutoInstall.rb new/autoyast2-4.3.53/src/modules/AutoInstall.rb --- old/autoyast2-4.3.51/src/modules/AutoInstall.rb 2020-09-21 12:12:20.000000000 +0200 +++ new/autoyast2-4.3.53/src/modules/AutoInstall.rb 2020-09-24 17:13:19.000000000 +0200 @@ -6,6 +6,7 @@ # $Id$ require "yast" require "autoinstall/pkg_gpg_check_handler" +require "autoinstall/dialogs/question" require "installation/autoinst_issues" module Yast diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoyast2-4.3.51/test/lib/clients/clone_system_test.rb new/autoyast2-4.3.53/test/lib/clients/clone_system_test.rb --- old/autoyast2-4.3.51/test/lib/clients/clone_system_test.rb 2020-09-21 12:12:20.000000000 +0200 +++ new/autoyast2-4.3.53/test/lib/clients/clone_system_test.rb 2020-09-24 17:13:19.000000000 +0200 @@ -35,6 +35,7 @@ let(:normal?) { true } let(:package_installed?) { true } let(:tmp_dir) { Dir.mktmpdir("YaST-") } + let(:profile_path) { File.join(tmp_dir, "autoinst.xml") } let(:profile_exists?) { false } before do @@ -45,9 +46,12 @@ allow(Yast::Installation).to receive(:restart_file) .and_return(File.join(tmp_dir, "restart_yast")) allow(Yast::AutoinstClone).to receive(:Process) - allow(Yast::XML).to receive(:YCPToXMLFile) allow(Yast::FileUtils).to receive(:Exists).and_call_original allow(Yast::FileUtils).to receive(:Exists).with(/autoinst.xml/).and_return(profile_exists?) + stub_const( + "Y2Autoinstallation::Clients::CloneSystem::DEFAULT_FILENAME", + File.join(tmp_dir, "autoinst.xml") + ) end around(:each) do |example| @@ -81,7 +85,7 @@ describe "'modules' command" do let(:args) { ["modules"] } - let(:profile) { instance_double(Hash) } + let(:profile) { { "general" => { "mode" => { "confirm" => true } } } } before do allow(Yast::Profile).to receive(:current).and_return(profile) @@ -98,9 +102,9 @@ let(:continue?) { true } it "saves the profile to the given file" do - expect(Yast::XML).to receive(:YCPToXMLFile) - .with(:profile, profile, "/root/autoinst.xml") client.main + expect(File).to exist(profile_path) + expect(File.stat(profile_path).mode.to_s(8)).to eq("100600") end end @@ -117,8 +121,9 @@ it "clones and writes the profile to '/root/autoinst.xml'" do expect(Yast::AutoinstClone).to receive(:Process) - expect(Yast::XML).to receive(:YCPToXMLFile).with(:profile, profile, "/root/autoinst.xml") client.main + expect(File).to exist(profile_path) + expect(File.stat(profile_path).mode.to_s(8)).to eq("100600") end it "shows error popup if invalid object is found during serialization" do @@ -130,12 +135,14 @@ end context "when a filename is given" do - let(:args) { ["modules", "filename=/tmp/autoinst.xml"] } + let(:profile_path) { File.join(tmp_dir, "alternative.xml") } + let(:args) { ["modules", "filename=#{profile_path}"] } it "clones and writes the profile to the given file" do expect(Yast::AutoinstClone).to receive(:Process) - expect(Yast::XML).to receive(:YCPToXMLFile).with(:profile, profile, "/tmp/autoinst.xml") client.main + expect(File).to exist(profile_path) + expect(File.stat(profile_path).mode.to_s(8)).to eq("100600") end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoyast2-4.3.51/test/lib/profile_checker_test.rb new/autoyast2-4.3.53/test/lib/profile_checker_test.rb --- old/autoyast2-4.3.51/test/lib/profile_checker_test.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/autoyast2-4.3.53/test/lib/profile_checker_test.rb 2020-09-24 17:13:19.000000000 +0200 @@ -0,0 +1,111 @@ +# Copyright (c) [2020] SUSE LLC +# +# All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2 of the GNU General Public License as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, contact SUSE LLC. +# +# To contact SUSE LLC about this file by physical or electronic mail, you may +# find current contact information at www.suse.com. + +require_relative "../test_helper" +require "autoinstall/profile_checker" + +describe Y2Autoinstallation::ProfileChecker do + let(:import_all) { false } + let(:run_scripts) { false } + # here it is a bit tricky, but as we mock all fs operations, we need to use here source xml + let(:target_file) { fixture_xml("leap.xml") } + + subject do + described_class.new(fixture_xml("leap.xml"), import_all: import_all, + run_scripts: run_scripts, target_file: target_file) + end + + def fixture_xml(filename) + File.expand_path("#{__dir__}/../fixtures/profiles/#{filename}") + end + + before do + allow(::FileUtils).to receive(:cp) # no messing of fs + allow(Yast2::Popup).to receive(:show) # no popups + allow(Yast::ProfileLocation).to receive(:Process).and_return(true) + end + + describe "#check" do + it "sets mode to dialog mode to show UI" do + expect(Yast::Mode).to receive(:SetUI).with("dialog") + + subject.check + end + + it "fetches profile same as real autoinstallation" do + expect(Yast::AutoinstConfig).to receive(:ParseCmdLine) + expect(Yast::ProfileLocation).to receive(:Process).and_return(true) + + subject.check + end + + context "import_all flag is set" do + let(:import_all) { true } + + before do + allow(Y2Autoinstallation::Importer).to receive(:new) + .and_return(double(import_sections: true)) + allow(Yast::AutoInstall).to receive(:valid_imported_values) + end + + it "imports all sections in profile" do + expect(Y2Autoinstallation::Importer).to receive(:new) + .and_return(double(import_sections: true)) + + subject.check + end + + it "check if there are any autoinst issue" do + expect(Yast::AutoInstall).to receive(:valid_imported_values) + + subject.check + end + end + + context "run_scripts flag is set" do + let(:run_scripts) { true } + + before do + allow(Yast::AutoinstScripts).to receive(:Write) + allow(::FileUtils).to receive(:rm_r) + allow(::FileUtils).to receive(:mkdir_p) + allow(::FileUtils).to receive(:cp) + allow(Yast::Mode).to receive(:SetMode) + end + + it "sets autoinstallation mode" do + expect(Yast::Mode).to receive(:SetMode).with("autoinstallation") + + subject.check + end + + it "ensures that scripts are imported even when import_all is not set" do + expect(Yast::AutoinstScripts).to receive(:Import) + + subject.check + end + + it "runs all defined scripts" do + expect(Yast::AutoinstScripts).to receive(:Write) + + subject.check + end + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoyast2-4.3.51/test_xml/deprecated_bootloader.xml new/autoyast2-4.3.53/test_xml/deprecated_bootloader.xml --- old/autoyast2-4.3.51/test_xml/deprecated_bootloader.xml 1970-01-01 01:00:00.000000000 +0100 +++ new/autoyast2-4.3.53/test_xml/deprecated_bootloader.xml 2020-09-24 17:13:19.000000000 +0200 @@ -0,0 +1,8 @@ +<?xml version="1.0"?> +<!DOCTYPE profile> +<profile xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns"> + <bootloader> + <loader_type>grub</loader_type> + </bootloader> +</profile> + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoyast2-4.3.51/test_xml/dynamic.erb new/autoyast2-4.3.53/test_xml/dynamic.erb --- old/autoyast2-4.3.51/test_xml/dynamic.erb 1970-01-01 01:00:00.000000000 +0100 +++ new/autoyast2-4.3.53/test_xml/dynamic.erb 2020-09-24 17:13:19.000000000 +0200 @@ -0,0 +1,41 @@ +<profile xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns"> + <software> + <products config:type="list"> + <product>openSUSE</product> + </products> + </software> + <%# first lets create list of disk names according to its size %> + <% sorted_disks = disks.sort_by { |d| d[:size] }.map { |d| d[:device] }.reverse %> + <partitioning t="list"> + <% sorted_disks[0..1].each do |name| %> + <drive> + <device> + <%= name %> + </device> + <initialize t="boolean"> + true + </initialize> + </drive> + <% end %> + </partitioning> + <%# situation: machine has two network catds. One leads to intranet and other to internet, so here we create udev + rules to have internet one as eth0 and intranet as eth1. To distinguish in this example if use active flag for intranet %> + <networking> + <net-udev t="list"> + <rule> + <name>eth0</name> + <rule>ATTR{address}</rule> + <value> + <%= network_cards.find { |c| c[:link] }[:mac] %> + </value> + </rule> + <rule> + <name>eth1</name> + <rule>ATTR{address}</rule> + <value> + <%= network_cards.find { |c| !c[:link] }[:mac] %> + </value> + </rule> + </net-udev> + </networking> +</profile> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoyast2-4.3.51/test_xml/dynamic.xml new/autoyast2-4.3.53/test_xml/dynamic.xml --- old/autoyast2-4.3.51/test_xml/dynamic.xml 1970-01-01 01:00:00.000000000 +0100 +++ new/autoyast2-4.3.53/test_xml/dynamic.xml 2020-09-24 17:13:19.000000000 +0200 @@ -0,0 +1,30 @@ +<?xml version="1.0"?> +<!DOCTYPE profile> +<profile xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns"> + <scripts> + <pre-scripts config:type="list"> + <script> + <interpreter>shell</interpreter> + <source><![CDATA[ + # get list of disks. In this case it picks two biggest disks + # Some details, perl part makes disk info one liner, sed keep just device name and its capacity. Then it is sorted and removed size info + DISKS=`hwinfo --disk | perl -p0E 'while(s/^(.*)\n /$1 /gm){}' | sed '/^$/d; s/^.*Device File: \([^ ]\+\).*Capacity: [^(]*(\(.*\) bytes).*/\1 \2/' | sort --key 2 -nr | sed 's/ [0-9]*$//' | head -2` + # final static profile + TARGET_FILE=/tmp/profile/modified.xml + echo '<profile xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns"> + <software> + <products config:type="list"> + <product>openSUSE</product> + </products> + </software> + <partitioning t="list">' > $TARGET_FILE + for i in $DISKS; do + echo "<drive><device>$i</device><initialize t=\"boolean\">true</initialize></drive>" >> $TARGET_FILE + done + echo '</partitioning></profile>' >> $TARGET_FILE + ]]> + </source> + </script> + </pre-scripts> + </scripts> +</profile>