Skip to content

Commit

Permalink
Add a System Role step in the installation (FATE#317481)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidner committed Mar 4, 2016
1 parent b083c8f commit 82228ba
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Makefile.am
Expand Up @@ -50,6 +50,7 @@ client_DATA = \
clients/inst_save_hardware_status.rb \
clients/inst_scenarios.rb \
clients/inst_system_analysis.rb \
clients/inst_system_role.rb \
clients/inst_upgrade_urls.rb \
clients/inst_welcome.rb \
clients/inst_worker_continue.rb \
Expand Down Expand Up @@ -111,6 +112,7 @@ ylib_DATA = \
lib/installation/proposal_runner.rb \
lib/installation/proposal_store.rb \
lib/installation/remote_finish_client.rb \
lib/installation/select_system_role.rb \
lib/installation/snapshots_finish.rb

ylibclientdir = "${yast2dir}/lib/installation/clients"
Expand Down
2 changes: 2 additions & 0 deletions src/clients/inst_system_role.rb
@@ -0,0 +1,2 @@
require "installation/select_system_role"
Installation::SelectSystemRole.new.run
14 changes: 14 additions & 0 deletions src/clients/testme.rb
@@ -0,0 +1,14 @@
# a quick test of dialog layout without running the whole installation business
require "yast"
require "installation/select_system_role"

Yast.import "ProductControl"
Yast.import "Wizard"

Yast::ProductControl.custom_control_file =
ENV["HOME"] + "/binaries/y2update/control.xml"
Yast::ProductControl.Init

Yast::Wizard.OpenLeftTitleNextBackDialog()

::Installation::SelectSystemRole.new.run
121 changes: 121 additions & 0 deletions src/lib/installation/select_system_role.rb
@@ -0,0 +1,121 @@
# Copyright (c) 2016 SUSE LLC.
# All Rights Reserved.

# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 or 3 of the GNU General
# Public License as published by the Free Software Foundation.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, contact SUSE LLC.

# To contact SUSE about this file by physical or electronic mail,
# you may find current contact information at www.suse.com

require "yast"
require "ui/installation_dialog"

module Installation
class SelectSystemRole < ::UI::InstallationDialog
include Yast

def initialize
super

textdomain "installation"
Yast.import "ProductControl"
Yast.import "ProductFeatures"
end

def run
if raw_roles.empty?
log.info "No roles defined, skipping their dialog"
return :auto # skip forward or backward
end

super
end

public # called by parent class

def dialog_title
_("System Role")
end

def help_text
"" # no Help, besides the descriptions in dialog body
end

def dialog_content
RadioButtonGroup(
Id(:roles),
VBox(
* ui_roles.map do |r|
VBox(
Left(RadioButton(Id(r[:id]), r[:label])),
HBox(
HSpacing(4),
Left(Label(r[:description]))
),
VSpacing(2)
)
end
)
)
end

def create_dialog
clear_role
ok = super
UI.ChangeWidget(Id(:roles), :CurrentButton, ui_roles.first[:id])
ok
end

def next_handler
role_id = UI.QueryWidget(Id(:roles), :CurrentButton)
apply_role(role_id)

super
end

private

def clear_role
ProductFeatures.ClearOverlay
end

def apply_role(role_id)
log.info "Applying system role '#{role_id}'"
features = raw_roles.find { |r| r["id"] == role_id }
features = features.dup
features.delete("id")
ProductFeatures.SetOverlay(features)
end

# the contents is an overlay for ProductFeatures sections
# [
# { "id" => "foo", "partitioning" => ... },
# { "id" => "bar", "partitioning" => ... , "software" => ...},
# ]
# @return [Array<Hash{String => Object}>]
def raw_roles
ProductControl.productControl.fetch("system_roles", [])
end

def ui_roles
raw_roles.map do |r|
id = r["id"]

{
id: id,
label: ProductControl.GetTranslatedText(id),
description: ProductControl.GetTranslatedText(id + "_description")
}
end
end
end
end
1 change: 1 addition & 0 deletions test/Makefile.am
Expand Up @@ -8,6 +8,7 @@ TESTS = \
proposal_store_test.rb \
proposal_runner_test.rb \
remote_finish_test.rb \
select_system_role_test.rb \
snapshots_finish_test.rb

TEST_EXTENSIONS = .rb
Expand Down
2 changes: 0 additions & 2 deletions test/cio_ignore_test.rb
Expand Up @@ -6,7 +6,6 @@

describe ::Installation::CIOIgnore do
describe "enable/disable" do

it "take AutoYaST cio_ignore setting" do
allow(Yast::Mode).to receive(:autoinst).and_return(true)
allow(Yast::AutoinstConfig).to receive(:cio_ignore).and_return(false)
Expand All @@ -21,7 +20,6 @@
::Installation::CIOIgnore.instance.reset
expect(::Installation::CIOIgnore.instance.enabled).to eq(true)
end

end
end

Expand Down
71 changes: 71 additions & 0 deletions test/select_system_role_test.rb
@@ -0,0 +1,71 @@
#! /usr/bin/env rspec

require_relative "./test_helper"

require "installation/select_system_role"
Yast.import "ProductControl"

describe ::Installation::SelectSystemRole do
subject { Installation::SelectSystemRole.new }

before do
allow(Yast::ProductControl).to receive(:GetTranslatedText) do |s|
"Lorem Ipsum #{s}"
end

allow(Yast::UI).to receive(:ChangeWidget)
end

describe "#run" do
context "when no roles are defined" do
before do
allow(Yast::ProductControl).to receive(:productControl)
.and_return("system_roles" => [])
end

it "does not display dialog" do
expect(Yast::Wizard).to_not receive(:SetContents)
subject.run
end
end

context "when some roles are defined" do
include Yast::UIShortcuts

let(:control_file_roles) do
[
{ "id" => "foo", "partitioning" => { "format" => true } },
{ "id" => "bar", "software" => { "desktop" => "knome" } }
]
end

before do
allow(Yast::ProductControl).to receive(:productControl)
.and_return("system_roles" => control_file_roles)
end

it "displays dialog, and sets ProductFeatures on Next" do
allow(Yast::Wizard).to receive(:SetContents)
allow(Yast::UI).to receive(:UserInput)
.and_return(:next)
allow(Yast::UI).to receive(:QueryWidget)
.with(Id(:roles), :CurrentButton).and_return("foo")

expect(Yast::ProductFeatures).to receive(:ClearOverlay)
expect(Yast::ProductFeatures).to receive(:SetOverlay) # .with

expect(subject.run).to eq(:next)
end

it "displays dialog, and leaves ProductFeatures on Back" do
allow(Yast::Wizard).to receive(:SetContents)
allow(Yast::UI).to receive(:UserInput)
.and_return(:back)
expect(Yast::ProductFeatures).to receive(:ClearOverlay)
expect(Yast::ProductFeatures).to_not receive(:SetOverlay)

expect(subject.run).to eq(:back)
end
end
end
end

0 comments on commit 82228ba

Please sign in to comment.