Skip to content

Commit

Permalink
AutoYaST: skip product license client when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Apr 17, 2018
1 parent 758200f commit 6a28585
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 21 deletions.
36 changes: 25 additions & 11 deletions src/lib/y2packager/clients/inst_product_license.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,32 @@
require "y2packager/product"
Yast.import "Language"
Yast.import "GetInstArgs"
Yast.import "Mode"

module Y2Packager
module Clients
# This client shows a license confirmation dialog for the base selected product
#
# The client will be skipped (returning `:auto`) in these situations:
# The client will be skipped (returning `:auto` or `:next`) in these
# situations:
#
# * There is no license available for the selected base product.
# * There is only 1 base product (not a multi-product media at all). In
# that case, the license is supposed to has been already accepted in the
# welcome screen.
# * Running AutoYaST but the license has been already confirmed.
# * Running a normal installation but there is only 1 base product
# (not a multi-product media at all). In that case, the license is
# supposed to has been already confirmed in the welcome screen.
class InstProductLicense
include Yast::I18n
include Yast::Logger

def main
textdomain "installation"
return :auto unless multi_product_media? && available_license?

if Yast::Mode.auto
return :next if !available_license? || license_confirmed?
else
return :auto unless available_license? && multi_product_media?
end

Yast::Wizard.EnableAbortButton
disable_buttons = !Yast::GetInstArgs.enable_back ? [:back] : []
Expand All @@ -47,7 +55,10 @@ def main
# @return [Y2Packager::Product]
# @see Y2Packager::Product.selected_base
def product
@product ||= Y2Packager::Product.selected_base
return @product if @product
@product = Y2Packager::Product.selected_base
log.warn "No base product is selected for installation" unless @product
@product
end

# Determines whether a multi-product media is being used
Expand All @@ -64,13 +75,16 @@ def multi_product_media?
# @return [Boolean] true if the license is available; false otherwise.
def available_license?
return true if product && product.license?
if product.nil?
log.warn "No base product is selected for installation"
else
log.warn "No license for product '#{product.label}' was found"
end
log.warn "No license for product '#{product.label}' was found" if product
false
end

# Determine whether the product's license has been already confirmed
#
# @return [Boolean] true if the license was confirmed; false otherwise.
def license_confirmed?
product && product.license_confirmed?
end
end
end
end
66 changes: 56 additions & 10 deletions test/lib/clients/inst_product_license_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
let(:confirmation_required?) { true }
let(:license_confirmed?) { false }
let(:language) { double("Yast::Language", language: "en_US") }
let(:auto) { false }

before do
allow(Y2Packager::Dialogs::InstProductLicense).to receive(:new)
.and_return(dialog)
allow(Y2Packager::Product).to receive(:selected_base).and_return(product)
allow(Y2Packager::Product).to receive(:available_base_products).and_return(products)
allow(Yast::Mode).to receive(:auto).and_return(auto)
stub_const("Yast::Language", language)
end

Expand Down Expand Up @@ -81,14 +83,6 @@
end
end

context "when only one base product is found" do
let(:products) { [product] }

it "returns :auto" do
expect(client.main).to eq(:auto)
end
end

context "when no license is found for the selected base product" do
let(:license?) { false }

Expand All @@ -98,8 +92,60 @@
client.main
end

it "returns :auto" do
expect(client.main).to eq(:auto)
context "and running during normal installation" do
let(:auto) { false }

it "returns :auto" do
expect(client.main).to eq(:auto)
end
end

context "and running during autoinstallation" do
let(:auto) { true }

it "returns :next" do
expect(client.main).to eq(:next)
end
end
end

context "during normal installation" do
let(:auto) { false }

context "when only one base product is found" do
let(:products) { [product] }

it "returns :auto" do
expect(client.main).to eq(:auto)
end
end

context "when more than one product is found" do
it "opens the license dialog" do
expect(Y2Packager::Dialogs::InstProductLicense).to receive(:new)
client.main
end
end
end

context "during autoinstallation" do
let(:auto) { true }

context "when the license has been accepted" do
let(:license_confirmed?) { true }

it "returns :next" do
expect(client.main).to eq(:next)
end
end

context "when the license has not been accepted" do
let(:license_confirmed?) { false }

it "opens the license dialog" do
expect(Y2Packager::Dialogs::InstProductLicense).to receive(:new)
client.main
end
end
end
end
Expand Down

0 comments on commit 6a28585

Please sign in to comment.