Skip to content

Commit

Permalink
Use the base product hardcoded in the control file
Browse files Browse the repository at this point in the history
Related to bsc#1124590.
  • Loading branch information
dgdavid committed Mar 19, 2019
1 parent c9ddb9c commit a3e27f7
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
27 changes: 26 additions & 1 deletion src/lib/installation/clients/inst_complex_welcome.rb
Expand Up @@ -35,6 +35,7 @@
Yast.import "Pkg"
Yast.import "Popup"
Yast.import "ProductControl"
Yast.import "ProductFeatures"
Yast.import "Stage"
Yast.import "Timezone"
Yast.import "Wizard"
Expand Down Expand Up @@ -145,16 +146,40 @@ def setup_final_choice
# not know which product we are upgrading yet) nor the product selector
# (as you cannot change the product during upgrade).
#
# It could return a list with pre-selected product(s), @see #preselected_base_product.
#
# @return [Array<Y2Packager::Product>] List of available base products;
# empty list in update mode.
def products
return @products if @products

@products = Y2Packager::Product.available_base_products
@products = preselected_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 global `product_name` 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
product_name = ProductFeatures.GetStringFeature("globals", "product_name")

return if product_name.empty?

available_base_products.select { |product| product.name == product_name }
end

# Returns all available base products
#
# @return [Array<Y2Packager::Product>] List of available base products
def available_base_products
@available_base_products ||= Y2Packager::Product.available_base_products
end

# Determine whether some product is available or not
#
# @return [Boolean] false if no product available; true otherwise
Expand Down
41 changes: 39 additions & 2 deletions test/lib/clients/inst_complex_welcome_test.rb
Expand Up @@ -9,16 +9,23 @@
let(:product) do
instance_double(
Y2Packager::Product,
name: "Product",
license_confirmation_required?: license_needed?,
license?: license?,
license: "license content",
license_confirmed?: license_confirmed?
)
end
let(:other_product) do
instance_double(
Y2Packager::Product,
name: "Other Product"
)
end

let(:license_needed?) { true }
let(:license_confirmed?) { false }
let(:license?) { true }
let(:other_product) { instance_double(Y2Packager::Product) }
let(:products) { [product, other_product] }
let(:auto) { false }
let(:config_mode) { false }
Expand Down Expand Up @@ -238,7 +245,7 @@
context "when running on install mode" do
let(:update_mode) { false }

context "and more than 1 product is availble" do
context "and more than 1 product is available" do
let(:products) { [product, other_product] }

it "runs the complex welcome dialog with the list of available products" do
Expand All @@ -257,6 +264,36 @@
subject.main
end
end

# 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
let(:products) { [product, other_product] }
let(:preselected_product) { "Other Product" }

before do
allow(Yast::ProductFeatures).to receive(:GetStringFeature)
.with("globals", "product_name")
.and_return(preselected_product)
end

it "runs the complex welcome dialog with the preselected 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

context "when running on update mode" do
Expand Down

0 comments on commit a3e27f7

Please sign in to comment.