Skip to content

Commit

Permalink
Merge pull request #415 from yast/nil_check
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Jan 16, 2019
2 parents 86a025b + 47c3169 commit fd89e9f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
7 changes: 7 additions & 0 deletions package/yast2-registration.changes
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-registration.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-registration
Version: 4.1.12
Version: 4.1.13
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
8 changes: 8 additions & 0 deletions src/lib/registration/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,18 @@ def update_system(target_distro = nil)
ret
end

# Get the list of addons
#
# @return [Array<Addon>] 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 []
end

log.info "Reading available addons for product: #{base_product["name"]}"

remote_product = SwMgmt.remote_product(base_product)
Expand Down
50 changes: 30 additions & 20 deletions test/registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,31 +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
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({})
allow(Registration::SwMgmt).to receive(:base_product_to_register).and_return(base_product)
end

addons = Registration::Registration.new.get_addon_list
context "no base product found" do
let(:base_product) { nil }

# 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")
it "returns empty list if no base product is found" do
expect(Registration::Registration.new.get_addon_list).to eq([])
end
end

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")
end
end
end

Expand Down

0 comments on commit fd89e9f

Please sign in to comment.