From 29235cd27c0acf8518f518ebce8f35f16cefcb41 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Thu, 6 May 2021 16:27:24 +0100 Subject: [PATCH 1/3] Do not register the system if disabled --- src/lib/autoinstall/autosetup_helpers.rb | 4 +- test/lib/autosetup_helpers_test.rb | 73 ++++++++++++++---------- 2 files changed, 46 insertions(+), 31 deletions(-) diff --git a/src/lib/autoinstall/autosetup_helpers.rb b/src/lib/autoinstall/autosetup_helpers.rb index e1ef5cb81..e0470ac72 100644 --- a/src/lib/autoinstall/autosetup_helpers.rb +++ b/src/lib/autoinstall/autosetup_helpers.rb @@ -82,8 +82,10 @@ def suse_register return true unless registration_module_available? # do nothing general_section = Yast::Profile.current["general"] || {} + register_section = Yast::Profile.current[REGISTER_SECTION] + disabled_registration = (register_section || {})["do_registration"] == false # autoupgrade detects itself if system is registered and if needed do migration via scc - if Yast::Profile.current[REGISTER_SECTION] || Yast::Mode.autoupgrade + if !disabled_registration && (register_section || Yast::Mode.autoupgrade) Yast::WFM.CallFunction( "scc_auto", ["Import", Yast::Profile.current[REGISTER_SECTION]] diff --git a/test/lib/autosetup_helpers_test.rb b/test/lib/autosetup_helpers_test.rb index 0c42ad2c4..ede0fc26b 100755 --- a/test/lib/autosetup_helpers_test.rb +++ b/test/lib/autosetup_helpers_test.rb @@ -81,45 +81,58 @@ class DummyClient < Yast::Client end context "suse_register tag is defined in AY file" do - let(:profile_content) { { "suse_register" => { "reg_code" => "12345" } } } + context "and the registration is disabled explicitly" do + let(:profile_content) { { "suse_register" => { "do_registration" => false } } } - before do - allow(Yast::WFM).to receive(:CallFunction).with("inst_download_release_notes") - .and_return(true) - allow(Yast::WFM).to receive(:CallFunction).with("scc_auto", anything).and_return(true) - Yast::Profile.Import(profile_content) + it "does not call any client and returns true." do + # no scc_auto call at all + expect(Yast::WFM).not_to receive(:CallFunction) + expect(client.suse_register).to eq(true) + end end - it "imports the registration settings from the profile" do - expect(Yast::WFM).to receive(:CallFunction).with("scc_auto", - ["Import", profile_content["suse_register"]]).and_return(true) - expect(Yast::WFM).to receive(:CallFunction).with("scc_auto", ["Write"]) - .and_return(true) - client.suse_register - end + context "and the registration is not disabled explicitly" do + let(:profile_content) { { "suse_register" => { "reg_code" => "12345" } } } - it "downloads release notes" do - expect(Yast::WFM).to receive(:CallFunction).with("inst_download_release_notes") - client.suse_register - end + before do + allow(Yast::WFM).to receive(:CallFunction).with("inst_download_release_notes") + .and_return(true) + allow(Yast::WFM).to receive(:CallFunction).with("scc_auto", anything).and_return(true) + Yast::Profile.Import(profile_content) + end - # bsc#1153293 - it "removes the registration section to not run it again in the 2nd stage" do - expect(Yast::Profile).to receive(:remove_sections).with("suse_register") - client.suse_register - end + it "imports the registration settings from the profile" do + expect(Yast::WFM).to receive(:CallFunction).with("scc_auto", + ["Import", profile_content["suse_register"]]).and_return(true) + expect(Yast::WFM).to receive(:CallFunction).with("scc_auto", ["Write"]) + .and_return(true) + client.suse_register + end - it "returns true" do - expect(client.suse_register).to eq(true) - end + it "downloads release notes" do + expect(Yast::WFM).to receive(:CallFunction).with("inst_download_release_notes") + client.suse_register + end - context "when something goes wrong" do - before do - allow(Yast::WFM).to receive(:CallFunction).with("scc_auto", ["Write"]).and_return(false) + # bsc#1153293 + it "removes the registration section to not run it again in the 2nd stage" do + expect(Yast::Profile).to receive(:remove_sections).with("suse_register") + client.suse_register end - it "returns false" do - expect(client.suse_register).to eq(false) + it "returns true" do + expect(client.suse_register).to eq(true) + end + + context "when something goes wrong" do + before do + allow(Yast::WFM).to receive(:CallFunction).with("scc_auto", ["Write"]) + .and_return(false) + end + + it "returns false" do + expect(client.suse_register).to eq(false) + end end end end From b258c55512e38ca3c55eac6ab3ac470b3a0c9e95 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Fri, 7 May 2021 11:39:54 +0100 Subject: [PATCH 2/3] Bump version & changelog --- package/autoyast2.changes | 7 +++++++ package/autoyast2.spec | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package/autoyast2.changes b/package/autoyast2.changes index 68f2b37f9..571264452 100644 --- a/package/autoyast2.changes +++ b/package/autoyast2.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Fri May 7 10:24:22 UTC 2021 - Knut Anderssen + +- During autoupgrade do not try to register the system if it is + explicitly disabled in the profile (bsc#1176965) +- 4.2.51 + ------------------------------------------------------------------- Thu Mar 4 14:15:24 UTC 2021 - Imobach Gonzalez Sosa diff --git a/package/autoyast2.spec b/package/autoyast2.spec index abed2b618..e207319a9 100644 --- a/package/autoyast2.spec +++ b/package/autoyast2.spec @@ -22,7 +22,7 @@ %endif Name: autoyast2 -Version: 4.2.50 +Version: 4.2.51 Release: 0 Summary: YaST2 - Automated Installation License: GPL-2.0-only From e4e2f37022fcde274005691910d683879b8a9614 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Mon, 10 May 2021 12:31:19 +0100 Subject: [PATCH 3/3] Remove the section during the first stage in case of disable --- src/lib/autoinstall/autosetup_helpers.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib/autoinstall/autosetup_helpers.rb b/src/lib/autoinstall/autosetup_helpers.rb index e0470ac72..86538d5c9 100644 --- a/src/lib/autoinstall/autosetup_helpers.rb +++ b/src/lib/autoinstall/autosetup_helpers.rb @@ -84,6 +84,11 @@ def suse_register general_section = Yast::Profile.current["general"] || {} register_section = Yast::Profile.current[REGISTER_SECTION] disabled_registration = (register_section || {})["do_registration"] == false + + # remove the registration section to not run it again in the 2nd when it is explicitly + # disabled (no autoupgrade detection is needed in this case) + Yast::Profile.remove_sections(REGISTER_SECTION) if disabled_registration + # autoupgrade detects itself if system is registered and if needed do migration via scc if !disabled_registration && (register_section || Yast::Mode.autoupgrade) Yast::WFM.CallFunction(