diff --git a/package/yast2-network.changes b/package/yast2-network.changes index f3a10088d..d08ec9803 100644 --- a/package/yast2-network.changes +++ b/package/yast2-network.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Mon Apr 22 16:41:51 UTC 2019 - Imobach Gonzalez Sosa + +- Fix mode/second_stage value initialization (bsc#1132057) +- 4.1.45 + ------------------------------------------------------------------- Thu Mar 21 10:09:32 UTC 2019 - knut.anderssen@suse.com diff --git a/package/yast2-network.spec b/package/yast2-network.spec index cc65d154f..1e03789f2 100644 --- a/package/yast2-network.spec +++ b/package/yast2-network.spec @@ -17,7 +17,7 @@ Name: yast2-network -Version: 4.1.44 +Version: 4.1.45 Release: 0 BuildArch: noarch diff --git a/src/lib/network/network_autoyast.rb b/src/lib/network/network_autoyast.rb index 21a4066d4..c59983acc 100644 --- a/src/lib/network/network_autoyast.rb +++ b/src/lib/network/network_autoyast.rb @@ -368,7 +368,8 @@ def configure_submodule(yast_module, ay_config, write: false) # Return true in order to not call the NetworkAutoconfiguration.configure_hosts return true unless AutoInstall.valid_imported_values - write ||= !ay_general_section.fetch("mode", "second_stage" => true)["second_stage"] + mode_section = ay_general_section.fetch("mode", {}) + write ||= !mode_section.fetch("second_stage", true) log.info("Write configuration instantly: #{write}") yast_module.Write(gui: false) if write diff --git a/test/network_autoyast_test.rb b/test/network_autoyast_test.rb index b3d9f1037..ce21a8ff2 100755 --- a/test/network_autoyast_test.rb +++ b/test/network_autoyast_test.rb @@ -3,6 +3,8 @@ require_relative "test_helper" require "network/network_autoyast" +Yast.import "Profile" +Yast.import "Lan" describe "NetworkAutoYast" do subject(:network_autoyast) { Yast::NetworkAutoYast.instance } @@ -510,4 +512,76 @@ def mock_lan_item(renamed_to: nil) end end end + + describe "#configure_lan" do + before do + allow(Yast::Profile).to receive(:current) + .and_return("general" => general_section, "networking" => networking_section) + allow(Yast::AutoInstall).to receive(:valid_imported_values).and_return(true) + end + + let(:networking_section) { nil } + let(:general_section) { nil } + + context "when second stage is disabled" do + let(:general_section) do + { "mode" => { "second_stage" => false } } + end + + it "writes the Lan module configuration" do + expect(Yast::Lan).to receive(:Write) + subject.configure_lan + end + end + + context "when writing the configuration is disabled" do + it "writes the Lan module configuration" do + expect(Yast::Lan).to_not receive(:Write) + subject.configure_lan(write: false) + end + end + + context "when second stage is enabled" do + let(:general_section) do + { "mode" => { "second_stage" => true } } + end + + it "does not write the Lan module configuration" do + expect(Yast::Lan).to_not receive(:Write) + subject.configure_lan + end + end + + context "when second stage is not explicitly enabled" do + let(:general_section) { nil } + + it "does not write the Lan module configuration" do + expect(Yast::Lan).to_not receive(:write) + subject.configure_lan + end + end + + it "merges the installation configuration" do + expect(Yast::NetworkAutoYast.instance).to receive(:merge_configs) + subject.configure_lan + end + + context "when the user wants to keep the installation network" do + let(:networking_section) { { "keep_install_network" => true } } + + it "merges the installation configuration" do + expect(Yast::NetworkAutoYast.instance).to receive(:merge_configs) + subject.configure_lan + end + end + + context "when the user does not want to keep the installation network" do + let(:networking_section) { { "keep_install_network" => false } } + + it "does not merge the installation configuration" do + expect(Yast::NetworkAutoYast.instance).to_not receive(:merge_configs) + subject.configure_lan + end + end + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 4c125abfe..addc78765 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -26,6 +26,7 @@ def stub_module(name) # stub classes from other modules to speed up a build stub_module("AutoInstall") +stub_module("Profile") # A two level section/key => value store # to remember values of /etc/sysconfig/network/ifcfg-*