Skip to content

Commit

Permalink
Merge pull request #807 from yast/fix_forced_base_product_selection
Browse files Browse the repository at this point in the history
 Fix the forced base product selection (3/3)
  • Loading branch information
dgdavid committed Aug 5, 2019
2 parents b7e93db + fdb545e commit f2b97be
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 56 deletions.
7 changes: 7 additions & 0 deletions package/yast2-installation.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Mon Aug 5 08:43:21 UTC 2019 - David Diaz <dgonzalez@suse.com>

- Improve the detection of a forced base product
(bsc#1124590, bsc#1143943).
- 4.2.8

-------------------------------------------------------------------
Thu Jul 25 11:52:07 UTC 2019 - David Diaz <dgonzalez@suse.com>

Expand Down
5 changes: 3 additions & 2 deletions package/yast2-installation.spec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#

Name: yast2-installation
Version: 4.2.7
Version: 4.2.8
Release: 0
Group: System/YaST
License: GPL-2.0-only
Expand Down Expand Up @@ -75,7 +75,8 @@ Requires: yast2-proxy
# Systemd default target and services. This version supports
# writing settings in the first installation stage.
Requires: yast2-services-manager >= 3.2.1
Requires: yast2 >= 4.1.42
# Y2Packager::Product.forced_base_product
Requires: yast2 >= 4.2.17
Requires: yast2-network >= 4.0.13
# for AbortException and handle direct abort
Requires: yast2-ruby-bindings >= 4.0.6
Expand Down
42 changes: 7 additions & 35 deletions src/lib/installation/clients/inst_complex_welcome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,50 +141,22 @@ def setup_final_choice

# Return the list of base products available
#
# In update mode, when there are more than 1 product, this method will
# return an empty list because the dialog will not show the license (we do
# not know which product we are upgrading yet) nor the product selector
# (as you cannot change the product during upgrade).
# When a base product is being forced, the list will contains only it.
#
# It could return a list with pre-selected product(s), @see #preselected_base_product.
# In update mode, when there are more than 1 product, this method will return an empty
# list because the dialog will not show the license (we do not know which product we are
# upgrading yet) nor the product selector (as you cannot change the product during upgrade).
#
# @return [Array<Y2Packager::Product>] List of available base products;
# empty list in update mode.
# @return [Array<Y2Packager::Product>] List of available base products; if any, a list
# containing only the forced base product; empty list in update mode.
def products
return @products if @products

@products = preselected_base_product || available_base_products
@products = Array(Y2Packager::Product.forced_base_product || available_base_products)
@products = [] if Mode.update && @products.size > 1
@products
end

# Returns, if any, the preselected base product (bsc#1124590)
#
# A product can be pre-selected using the `select_product` element in the software section
# in the control file.
#
# @return [nil, Array<Y2Packager::Product>] nil when no preselected product in control file,
# a list containing the preselected base product, or
# empty list if preselected product is not available
def preselected_base_product
selected_product_name = ProductFeatures.GetStringFeature("software", "select_product")

return if selected_product_name.empty?

log.info("control.xml wants to preselect the #{selected_product_name} product")

filtered_base_products = available_base_products.select do |product|
product.name == selected_product_name
end
discarded_base_products = available_base_products - filtered_base_products

if !discarded_base_products.empty?
log.info("Ignoring the other available products: #{discarded_base_products.map(&:name)}")
end

filtered_base_products
end

# Returns all available base products
#
# @return [Array<Y2Packager::Product>] List of available base products
Expand Down
25 changes: 6 additions & 19 deletions test/lib/clients/inst_complex_welcome_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
)
end

let(:forced_base_product) { nil }

before do
# fake yast2-country, to avoid additional build dependencies
stub_const("Yast::Console", double.as_null_object)
Expand All @@ -66,6 +68,7 @@

allow(Y2Packager::Product).to receive(:selected_base).and_return(product)
allow(Y2Packager::Product).to receive(:available_base_products).and_return(products)
allow(Y2Packager::Product).to receive(:forced_base_product).and_return(forced_base_product)
end

describe "#main" do
Expand Down Expand Up @@ -268,31 +271,15 @@
# Test the behavior when the product name is hardcoded in the control file, which solves the
# issue with the wrong selected product during a network installation having multiples
# products in a single repository, bsc#1124590
context "and the control file contains a preselected product name" do
context "and there is a forced base product" do
let(:products) { [product, other_product] }
let(:preselected_product) { "Other Product" }

before do
allow(Yast::ProductFeatures).to receive(:GetStringFeature)
.with("software", "select_product")
.and_return(preselected_product)
end
let(:forced_base_product) { other_product }

it "runs the complex welcome dialog with the preselected product" do
it "runs the complex welcome dialog with the selected product" do
expect(Installation::Dialogs::ComplexWelcome).to receive(:run)
.with([other_product], anything)
subject.main
end

context "but it does not match with available products" do
let(:preselected_product) { "Unknown product" }

it "runs the complex welcome dialog with no products" do
expect(Installation::Dialogs::ComplexWelcome).to receive(:run)
.with([], anything)
subject.main
end
end
end
end

Expand Down

0 comments on commit f2b97be

Please sign in to comment.