Skip to content

Commit

Permalink
Preselect the default modules in the offline installation (jsc#SLE-80…
Browse files Browse the repository at this point in the history
…40, jsc#SLE-11455)
  • Loading branch information
lslezak committed Feb 25, 2020
1 parent 41a114a commit b26f4e6
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 6 deletions.
38 changes: 35 additions & 3 deletions src/lib/y2packager/dialogs/addon_selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

Yast.import "AddOnProduct"
Yast.import "Mode"
Yast.import "ProductFeatures"
Yast.import "Report"
Yast.import "Stage"
Yast.import "UI"
Expand Down Expand Up @@ -234,18 +235,49 @@ def product_description(product)
erb.result(binding)
end

# return a list of the preselected products
# during upgrade we want to preselect the installed products
# return a list of the preselected products depending on the installation mode
# @return [Array<Y2Packager::ProductLocation>] the products
def preselected_products
return [] unless Yast::Mode.update
# at upgrade preselect the installed addons
return preselected_upgrade_products if Yast::Mode.update
# in installation preselect the defaults defined in the control.xml/installation.xml
return preselected_installation_products if Yast::Mode.installation

# in other modes (e.g. installed system) do not preselect anything
[]
end

# return a list of the preselected products at upgrade,
# preselect the installed products
# @return [Array<Y2Packager::ProductLocation>] the products
def preselected_upgrade_products
missing_products = Yast::AddOnProduct.missing_upgrades
# installed but not selected yet products (to avoid duplicates)
products.select do |p|
missing_products.include?(p.details&.product)
end
end

# return a list of the preselected products at installation,
# preselect the default products specified in the control.xml/installation.xml,
# the already selected products are ignored
# @return [Array<Y2Packager::ProductLocation>] the products
def preselected_installation_products
default_modules = Yast::ProductFeatures.GetFeature("software", "default_modules")
return [] unless default_modules

log.info("Defined default modules: #{default_modules.inspect}")
# skip the already selected products (to avoid duplicates)
selected_products = Y2Packager::Resolvable.find(kind: :product, status: :selected)
.map(&:name)
default_modules -= selected_products
log.info("Using default modules: #{default_modules.inspect}")

# select the default products
products.select do |p|
default_modules.include?(p.details&.product)
end
end
end
end
end
52 changes: 49 additions & 3 deletions test/addon_selector_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@
require_relative "./test_helper"

require "y2packager/product_location"
require "y2packager/product_location_details"
require "y2packager/dialogs/addon_selector"

describe Y2Packager::Dialogs::AddonSelector do
let(:media_products) do
prods = [["SLE-15-Module-Basesystem 15.0-0", "/Basesystem"],
["SLE-15-Module-Legacy 15.0-0", "/Legacy"]]
prods.map { |r| Y2Packager::ProductLocation.new(r[0], r[1]) }
prods = [
[
"SLE-15-Module-Basesystem 15.0-0",
"/Basesystem",
Y2Packager::ProductLocationDetails.new(product: "sle-module-basesystem")
],
[
"SLE-15-Module-Legacy 15.0-0",
"/Legacy",
Y2Packager::ProductLocationDetails.new(product: "sle-module-legacy")
]
]
prods.map { |r| Y2Packager::ProductLocation.new(r[0], r[1], product: r[2]) }
end

subject { described_class.new(media_products) }
Expand Down Expand Up @@ -87,4 +98,39 @@
end
end
end

describe "#create_dialog" do
context "in installation" do
before do
allow(Yast::Stage).to receive(:initial).and_return(true)
allow(Yast::Mode).to receive(:installation).and_return(true)
end

it "preselects the default products from control.xml" do
# mock the control.xml default
expect(Yast::ProductFeatures).to receive(:GetFeature)
.with("software", "default_modules").and_return(["sle-module-basesystem"])

allow(Y2Packager::Resolvable).to receive(:find)
.with(kind: :product, status: :selected).and_return([])

expect(Yast::Wizard).to receive(:SetContents) do |_title, content, _help, _back, _next|
# find the MultiSelectionBox term in the UI definition
term = content.nested_find do |t|
t.respond_to?(:value) && t.value == :MultiSelectionBox
end

# verify that the Basesystem module is preselected
expect(term.params[3][0].params[1]).to eq("SLE-15-Module-Basesystem 15.0-0")
expect(term.params[3][0].params[2]).to eq(true)

# verify that the Legacy module is NOT preselected
expect(term.params[3][1].params[1]).to eq("SLE-15-Module-Legacy 15.0-0")
expect(term.params[3][1].params[2]).to eq(false)
end

subject.create_dialog
end
end
end
end

0 comments on commit b26f4e6

Please sign in to comment.