Skip to content

Commit

Permalink
Merge pull request #496 from yast/feature/fix-bsc-1125959
Browse files Browse the repository at this point in the history
Avoid to crash when profile has a not valid sofware section
  • Loading branch information
dgdavid committed Feb 25, 2019
2 parents 43c9175 + 82383b9 commit bad80a9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
7 changes: 7 additions & 0 deletions package/autoyast2.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Fri Feb 22 16:40:30 UTC 2019 - dgonzalez@suse.com

- Avoid to crash when the profile has a not valid sofware section
(bsc#1125959).
- 4.1.2

-------------------------------------------------------------------
Tue Feb 12 13:50:19 CET 2019 - schubi@suse.de

Expand Down
2 changes: 1 addition & 1 deletion package/autoyast2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
%endif

Name: autoyast2
Version: 4.1.1
Version: 4.1.2
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
13 changes: 10 additions & 3 deletions src/modules/AutoinstFunctions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def identify_product
# @return [Y2Packager::Product] a product if exactly one product matches
# the criteria, nil otherwise
def identify_product_by_patterns(profile)
software = profile.fetch("software", {})
software = profile["software"] || {}

identify_product do |product|
software.fetch("patterns", []).any? { |p| p =~ /#{product.name.downcase}-.*/ }
Expand All @@ -151,7 +151,7 @@ def identify_product_by_patterns(profile)
# @return [Y2Packager::Product] a product if exactly one product matches
# the criteria, nil otherwise
def identify_product_by_packages(profile)
software = profile.fetch("software", {})
software = profile["software"] || {}

identify_product do |product|
software.fetch("packages", []).any? { |p| p =~ /#{product.name.downcase}-release/ }
Expand Down Expand Up @@ -180,7 +180,14 @@ def identify_product_by_selection(profile)
# @param profile [Hash] AutoYaST profile
# @return [String] product name
def base_product_name(profile)
software = profile.fetch("software", {})
software = profile["software"]

if software.nil?
log.info("Error: given profile has not a valid software section")

return nil
end

software.fetch("products", []).first
end
end
Expand Down
18 changes: 18 additions & 0 deletions test/AutoinstFunctions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,23 @@ def base_product(name)

expect(subject.selected_product.name).to eql "SLED"
end

context "when there is not a valid software section" do
before do
allow(Yast::Profile)
.to receive(:current)
.and_return("software" => nil)
end

it "returns nil" do
expect(subject.selected_product).to be_nil
end

it "logs a message" do
expect(subject.log).to receive(:info).at_least(1).with(/not a valid software section/)

subject.selected_product
end
end
end
end

0 comments on commit bad80a9

Please sign in to comment.