From 49b642da9a493e9e75b4b79d187c0d63d381d8a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Mon, 22 Apr 2019 17:33:08 +0100 Subject: [PATCH 1/3] Add AutoYaST mode/second-stage initialization --- src/lib/network/network_autoyast.rb | 3 ++- test/network_autoyast_test.rb | 40 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) 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..195c81236 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,42 @@ 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) + allow(Yast::AutoInstall).to receive(:valid_imported_values).and_return(true) + end + + 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 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 + end end From 3afdb9484d1f6c58a69ee263aceb15b6ec10e6b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Mon, 22 Apr 2019 17:46:11 +0100 Subject: [PATCH 2/3] Bump version and update changes file --- package/yast2-network.changes | 6 ++++++ package/yast2-network.spec | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) 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 From 3bba3854f77fb80a195790ad876e34d177fcecc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Tue, 23 Apr 2019 08:54:36 +0100 Subject: [PATCH 3/3] Improve NetworkAutoYast#configure_lan test --- test/network_autoyast_test.rb | 36 ++++++++++++++++++++++++++++++++++- test/test_helper.rb | 1 + 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/test/network_autoyast_test.rb b/test/network_autoyast_test.rb index 195c81236..ce21a8ff2 100755 --- a/test/network_autoyast_test.rb +++ b/test/network_autoyast_test.rb @@ -515,10 +515,14 @@ def mock_lan_item(renamed_to: nil) describe "#configure_lan" do before do - allow(Yast::Profile).to receive(:current).and_return("general" => general_section) + 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 } } @@ -530,6 +534,13 @@ def mock_lan_item(renamed_to: nil) 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 } } @@ -549,5 +560,28 @@ def mock_lan_item(renamed_to: nil) 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-*