Skip to content

Commit

Permalink
Support for the offline installation medium (jsc#SLE-7101)
Browse files Browse the repository at this point in the history
- 4.2.16
  • Loading branch information
lslezak committed Oct 1, 2019
1 parent 71e4fec commit 0d8970c
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 4 deletions.
6 changes: 6 additions & 0 deletions package/yast2-installation.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Tue Oct 1 16:09:07 UTC 2019 - Ladislav Slezák <lslezak@suse.cz>

- Support for the offline installation medium (jsc#SLE-7101)
- 4.2.16

-------------------------------------------------------------------
Wed Sep 25 08:29:19 UTC 2019 - Steffen Winterfeldt <snwint@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-installation.spec
Expand Up @@ -16,7 +16,7 @@
#

Name: yast2-installation
Version: 4.2.15
Version: 4.2.16
Release: 0
Group: System/YaST
License: GPL-2.0-only
Expand Down
13 changes: 12 additions & 1 deletion src/lib/installation/clients/inst_complex_welcome.rb
Expand Up @@ -28,11 +28,14 @@
require "y2packager/medium_type"
require "y2packager/product"
require "y2packager/product_control_product"
require "y2packager/product_location"
require "y2packager/product_sorter"

Yast.import "Console"
Yast.import "FileUtils"
Yast.import "GetInstArgs"
Yast.import "InstShowInfo"
Yast.import "InstURL"
Yast.import "Keyboard"
Yast.import "Language"
Yast.import "Mode"
Expand Down Expand Up @@ -172,13 +175,21 @@ def products
def available_base_products
return @available_base_products if @available_base_products

if Y2Packager::MediumType.online?
case Y2Packager::MediumType.type
when :online
# read the products from the control.xml
@available_base_products = Y2Packager::ProductControlProduct.products
log.info "Found base products in the control.xml: #{@available_base_products.pretty_inspect}"

# we cannot continue, the control.xml in the installer is invalid
raise "control.xml does not define any base products!" if @available_base_products.empty?
when :offline
url = InstURL.installInf2Url("")
@available_base_products = Y2Packager::ProductLocation
.scan(url)
.select { |p| p.details && p.details.base }
.sort(&::Y2Packager::PRODUCT_SORTER)
log.info "Found base products on the offline medium: #{@available_base_products.pretty_inspect}"
else
@available_base_products = Y2Packager::Product.available_base_products
end
Expand Down
28 changes: 27 additions & 1 deletion src/lib/installation/widgets/product_selector.rb
@@ -1,10 +1,12 @@
require "yast"

require "y2packager/medium_type"
require "y2packager/product_control_product"

Yast.import "Pkg"
Yast.import "Popup"
Yast.import "AddOnProduct"
Yast.import "WorkflowManager"

require "cwm/common_widgets"

Expand Down Expand Up @@ -35,7 +37,9 @@ def label

def init
selected = products.find(&:selected?)
disable if registered?
# disable changing the base product after registering it, in the offline
# installation we cannot easily change the base product repository
disable if registered? || offline_product_selected?
return unless selected

self.value = item_id(selected)
Expand All @@ -48,8 +52,21 @@ def store

return unless @product

# online product from control.xml
if @product.is_a?(Y2Packager::ProductControlProduct)
Y2Packager::ProductControlProduct.selected = @product
# offline product from the medium repository
elsif @product.is_a?(Y2Packager::ProductLocation)
# in offline installation add the repository with the selected base product
show_popup = true
base_url = Yast::InstURL.installInf2Url("")
log_url = Yast::URL.HidePassword(base_url)
Yast::Packages.Initialize_StageInitial(show_popup, base_url, log_url, @product.dir)
# select the product to install
Yast::Pkg.ResolvableInstall(@product.details && @product.details.product, :product, "")
# initialize addons and the workflow manager
Yast::AddOnProduct.SetBaseProductURL(base_url)
Yast::WorkflowManager.SetBaseWorkflow(false)
else
# reset both YaST and user selection (when going back or any products
# selected by YaST in the previous steps)
Expand Down Expand Up @@ -87,7 +104,16 @@ def registered?
false
end

# has been an offline installation product selected?
# @return [Boolean] true if an offline installation product has been selected
def offline_product_selected?
Y2Packager::MediumType.offline? && products.any?(&:selected?)
end

# unique widget ID for the product
# @return [String] widget ID
def item_id(prod)
return prod.dir if prod.is_a?(Y2Packager::ProductLocation)
"#{prod.name}-#{prod.version}-#{prod.arch}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/lib/clients/inst_complex_welcome_test.rb
Expand Up @@ -69,7 +69,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)
allow(Y2Packager::MediumType).to receive(:online?).and_return(false)
allow(Y2Packager::MediumType).to receive(:type).and_return(:standard)
end

describe "#main" do
Expand Down
42 changes: 42 additions & 0 deletions test/widgets/product_selector_test.rb
Expand Up @@ -12,6 +12,10 @@

include_examples "CWM::RadioButtons"

before do
allow(Y2Packager::MediumType).to receive(:offline?).and_return(false)
end

describe "#init" do
let(:registration) { double("Registration::Registration", is_registered?: registered?) }

Expand Down Expand Up @@ -51,6 +55,20 @@
subject.init
end
end

context "when an offline base product has been selected" do
let(:registered?) { false }

before do
expect(Y2Packager::MediumType).to receive(:offline?).and_return(true)
expect(product1).to receive(:selected?).and_return(true).at_least(:once)
end

it "disables the widget" do
expect(subject).to receive(:disable)
subject.init
end
end
end

describe "#store" do
Expand Down Expand Up @@ -82,5 +100,29 @@
.with("add-on-product", :product, "")
subject.store
end

context "offline installation medium" do
let(:offline_product) { Y2Packager::ProductLocation.new("product", "dir") }
let(:url) { "http://example.com" }

before do
allow(offline_product).to receive(:selected?).and_return(true)
allow(Yast::InstURL).to receive(:installInf2Url).and_return(url)
allow(Yast::Packages).to receive(:Initialize_StageInitial)
allow(Yast::Pkg).to receive(:ResolvableInstall)
allow(Yast::AddOnProduct).to receive(:SetBaseProductURL)
allow(Yast::WorkflowManager).to receive(:SetBaseWorkflow)
end

it "adds the product repository" do
expect(Yast::Packages).to receive(:Initialize_StageInitial)
.with(true, url, url, "dir")

product_selector = described_class.new([offline_product])
allow(product_selector).to receive(:value).and_return("dir")
product_selector.init
product_selector.store
end
end
end
end

0 comments on commit 0d8970c

Please sign in to comment.