Skip to content

Commit

Permalink
Merge pull request #340 from yast/system-role
Browse files Browse the repository at this point in the history
System Role (FATE#317481)
  • Loading branch information
mvidner committed Mar 7, 2016
2 parents 30ddeb8 + 5b4fea5 commit d49a246
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 8 deletions.
53 changes: 53 additions & 0 deletions doc/control-file.md
Expand Up @@ -842,6 +842,59 @@ Section *supported\_desktops* contains list of one or more

Text ID used for desktop selection label.

### System Roles

System Roles, if defined in the control file, are presented during
the first stage of the installation. The user will select one of them
and they will affect the proposed configuration of Partitioning and Software.

They were requested in FATE#317481 and they are an evolution of the earlier
concept of Server Scenarios used in SLE 11.

Example:

```xml
<productDefines xmlns="http://www.suse.com/1.0/yast2ns"
xmlns:config="http://www.suse.com/1.0/configns">
<!-- ... -->
<system_roles config:type="list">
<system_role>
<id>plain</id>
<!-- nothing else here, no overrides -->
</system_role>

<system_role>
<id>virtualization_host_kvm</id>
<partitioning>
<proposal_lvm config:type="boolean">true</proposal_lvm>
</partitioning>
<software>
<default_patterns>base Minimal kvm_server</default_patterns>
</software>
</system_role>
</system_roles>

<texts>
<plain><label>General Server</label></plain>
<plain_description>
<label>Suitable for physical machines.</label>
</plain_description>
<virtualization_host_kvm>
<label>KVM Virtualization Host</label>
</virtualization_host_kvm>
<virtualization_host_kvm_description>
<label>Will install the appropriate packages.
Will use LVM disk layout.</label>
</virtualization_host_kvm_description>
</texts>
</productDefines>
```

Each role has a short label and a few lines of description in the *texts*
section, identified by a matching *id* element. The contents of *partitioning*
and *software* are merged with the corresponding top-level definitions. See
[Partitioning](#partitioning) and [Software](#software).

### System Scenarios

System scenarios contain definition of dialog *inst\_scenarios* in the
Expand Down
6 changes: 6 additions & 0 deletions package/yast2-installation.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Fri Mar 4 14:24:49 UTC 2016 - mvidner@suse.com

- Added a System Role step in the installation (FATE#317481).
- 3.1.172

-------------------------------------------------------------------
Mon Feb 29 09:05:16 UTC 2016 - mfilka@suse.com

Expand Down
11 changes: 5 additions & 6 deletions package/yast2-installation.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-installation
Version: 3.1.171
Version: 3.1.172
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand All @@ -37,18 +37,17 @@ BuildRequires: docbook-xsl-stylesheets libxslt update-desktop-files yast2-core-
BuildRequires: yast2-devtools >= 3.1.10
BuildRequires: rubygem(rspec)

# Base clients for inst clients
# Arch::is_zkvm
BuildRequires: yast2 >= 3.1.162
# ProductFeatures.SetOverlay
BuildRequires: yast2 >= 3.1.177

# Yast::Remote
BuildRequires: yast2-network

# AutoinstSoftware.SavePackageSelection()
Requires: autoyast2-installation >= 3.1.105

# Wizard.OpenLeftTitleNextBackDialog
Requires: yast2 >= 3.1.126
# ProductFeatures.SetOverlay
Requires: yast2 >= 3.1.177

# Language::GetLanguageItems and other API
# Language::Set (handles downloading the translation extensions)
Expand Down
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
112 changes: 112 additions & 0 deletions src/lib/installation/select_system_role.rb
@@ -0,0 +1,112 @@
# 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"
Yast.import "ProductControl"
Yast.import "ProductFeatures"

module Installation
class SelectSystemRole < ::UI::InstallationDialog
def initialize
super

textdomain "installation"
end

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

super
end

def dialog_title
_("System Role")
end

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

def dialog_content
ui_roles = role_attributes.each_with_object(VBox()) do |r, vbox|
vbox << Left(RadioButton(Id(r[:id]), r[:label]))
vbox << HBox(
HSpacing(4),
Left(Label(r[:description]))
)
vbox << VSpacing(2)
end

RadioButtonGroup(Id(:roles), ui_roles)
end

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

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

super
end

private

def clear_role
Yast::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")
Yast::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
Yast::ProductControl.productControl.fetch("system_roles", [])
end

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

{
id: id,
label: Yast::ProductControl.GetTranslatedText(id),
description: Yast::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
69 changes: 69 additions & 0 deletions test/select_system_role_test.rb
@@ -0,0 +1,69 @@
#! /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, and returns :auto" do
expect(Yast::Wizard).to_not receive(:SetContents)
expect(subject.run).to eq(:auto)
end
end

context "when some roles are defined" do
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
1 change: 1 addition & 0 deletions test/test_helper.rb
Expand Up @@ -3,6 +3,7 @@
ENV["Y2DIR"] = y2dirs.unshift(srcdir).join(":")

require "yast"
require "yast/rspec"

# fake AutoinstConfigClass class which is not supported by Ubuntu
module Yast
Expand Down

0 comments on commit d49a246

Please sign in to comment.