From a269c9d38b925b170553c0616abc8a636a13a8c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ladislav=20Slez=C3=A1k?= Date: Wed, 16 Jan 2019 09:56:45 +0100 Subject: [PATCH 1/3] Do not crash when no base product to register is found (bsc#1122011) - 4.1.13 --- package/yast2-registration.changes | 7 +++++++ package/yast2-registration.spec | 2 +- src/lib/registration/registration.rb | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/package/yast2-registration.changes b/package/yast2-registration.changes index bc6d182a6..5c535b4a6 100644 --- a/package/yast2-registration.changes +++ b/package/yast2-registration.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Wed Jan 16 08:53:13 UTC 2019 - lslezak@suse.cz + +- Do not crash when no base product to register is found + (bsc#1122011) +- 4.1.13 + ------------------------------------------------------------------- Thu Jan 10 09:58:10 UTC 2019 - lslezak@suse.cz diff --git a/package/yast2-registration.spec b/package/yast2-registration.spec index c33108def..8a7b8e3a7 100644 --- a/package/yast2-registration.spec +++ b/package/yast2-registration.spec @@ -17,7 +17,7 @@ Name: yast2-registration -Version: 4.1.12 +Version: 4.1.13 Release: 0 BuildRoot: %{_tmppath}/%{name}-%{version}-build diff --git a/src/lib/registration/registration.rb b/src/lib/registration/registration.rb index 8d71ae70b..b0c648e39 100644 --- a/src/lib/registration/registration.rb +++ b/src/lib/registration/registration.rb @@ -134,6 +134,11 @@ def get_addon_list # extensions for base product base_product = ::Registration::SwMgmt.base_product_to_register + if !base_product + log.warn "No base product, skipping addons" + return + end + log.info "Reading available addons for product: #{base_product["name"]}" remote_product = SwMgmt.remote_product(base_product) From 3042bc972e2aa963fd19824b38accdec8c104a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ladislav=20Slez=C3=A1k?= Date: Wed, 16 Jan 2019 11:08:49 +0100 Subject: [PATCH 2/3] Added test --- src/lib/registration/registration.rb | 4 +++- test/registration_spec.rb | 16 ++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/lib/registration/registration.rb b/src/lib/registration/registration.rb index b0c648e39..733574425 100644 --- a/src/lib/registration/registration.rb +++ b/src/lib/registration/registration.rb @@ -130,13 +130,15 @@ def update_system(target_distro = nil) ret end + # Get the list of addons + # @return [Array] List of addons, empty if no base product is found def get_addon_list # extensions for base product base_product = ::Registration::SwMgmt.base_product_to_register if !base_product log.warn "No base product, skipping addons" - return + return [] end log.info "Reading available addons for product: #{base_product["name"]}" diff --git a/test/registration_spec.rb b/test/registration_spec.rb index 53840fb50..10139b9d6 100644 --- a/test/registration_spec.rb +++ b/test/registration_spec.rb @@ -127,15 +127,19 @@ } end before do - expect(Registration::SwMgmt).to receive(:base_product_to_register).and_return(base_product) - end - - it "downloads available extensions" do remote_product = load_yaml_fixture("remote_product.yml") - expect(SUSE::Connect::YaST).to receive(:show_product).and_return(remote_product) + allow(SUSE::Connect::YaST).to receive(:show_product).and_return(remote_product) # no product renames defined - expect(Registration::SwMgmt).to receive(:update_product_renames).with({}) + allow(Registration::SwMgmt).to receive(:update_product_renames).with({}) + end + it "returns empty list if no base product is found" do + expect(Registration::SwMgmt).to receive(:base_product_to_register).and_return(nil) + expect(Registration::Registration.new.get_addon_list).to eq([]) + end + + it "downloads available extensions" do + expect(Registration::SwMgmt).to receive(:base_product_to_register).and_return(base_product) addons = Registration::Registration.new.get_addon_list # HA-GEO is extension for HA so it's not included in the list From 47c316986f6ca0254215a0aa6ae8bade671c0ade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ladislav=20Slez=C3=A1k?= Date: Wed, 16 Jan 2019 13:40:09 +0100 Subject: [PATCH 3/3] Improve the test --- src/lib/registration/registration.rb | 1 + test/registration_spec.rb | 44 ++++++++++++++++------------ 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/lib/registration/registration.rb b/src/lib/registration/registration.rb index 733574425..d2637171e 100644 --- a/src/lib/registration/registration.rb +++ b/src/lib/registration/registration.rb @@ -131,6 +131,7 @@ def update_system(target_distro = nil) end # Get the list of addons + # # @return [Array] List of addons, empty if no base product is found def get_addon_list # extensions for base product diff --git a/test/registration_spec.rb b/test/registration_spec.rb index 10139b9d6..742cb4900 100644 --- a/test/registration_spec.rb +++ b/test/registration_spec.rb @@ -118,35 +118,41 @@ end describe "#get_addon_list" do - let(:base_product) do - { - "name" => "SLES", - "version" => "12", - "arch" => "x86_64", - "release_type" => "DVD" - } - end before do remote_product = load_yaml_fixture("remote_product.yml") allow(SUSE::Connect::YaST).to receive(:show_product).and_return(remote_product) # no product renames defined allow(Registration::SwMgmt).to receive(:update_product_renames).with({}) + allow(Registration::SwMgmt).to receive(:base_product_to_register).and_return(base_product) end - it "returns empty list if no base product is found" do - expect(Registration::SwMgmt).to receive(:base_product_to_register).and_return(nil) - expect(Registration::Registration.new.get_addon_list).to eq([]) + context "no base product found" do + let(:base_product) { nil } + + it "returns empty list if no base product is found" do + expect(Registration::Registration.new.get_addon_list).to eq([]) + end end - it "downloads available extensions" do - expect(Registration::SwMgmt).to receive(:base_product_to_register).and_return(base_product) - addons = Registration::Registration.new.get_addon_list + context "a base product is found" do + let(:base_product) do + { + "name" => "SLES", + "version" => "12", + "arch" => "x86_64", + "release_type" => "DVD" + } + end + + it "downloads available extensions" do + addons = Registration::Registration.new.get_addon_list - # HA-GEO is extension for HA so it's not included in the list - # also the base product must not be included in the list - expect(addons.map(&:identifier)).to include("sle-we", "sle-sdk", - "sle-module-legacy", "sle-module-web-scripting", "sle-module-public-cloud", - "sle-module-adv-systems-management", "sle-hae") + # HA-GEO is extension for HA so it's not included in the list + # also the base product must not be included in the list + expect(addons.map(&:identifier)).to include("sle-we", "sle-sdk", + "sle-module-legacy", "sle-module-web-scripting", "sle-module-public-cloud", + "sle-module-adv-systems-management", "sle-hae") + end end end