Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dashboard role handler #543

Merged
merged 8 commits into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions package/yast2-installation.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Mar 23 11:34:47 UTC 2017 - igonzalezsosa@suse.com

- Run the activation script for the Dashboard role
(bsc#1030107)
- 3.1.128.29

-------------------------------------------------------------------
Thu Mar 16 13:07:44 UTC 2017 - mvidner@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-installation.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-installation
Version: 3.1.217.28
Version: 3.1.217.29
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
8 changes: 5 additions & 3 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ ylib_DATA = \
lib/installation/ssh_config_file.rb \
lib/installation/ssh_importer_presenter.rb \
lib/installation/ssh_importer.rb \
lib/installation/system_role.rb
lib/installation/system_role.rb \
lib/installation/system_role_handlers_runner.rb

ylibtransferdir = "${yast2dir}/lib/transfer"
ylibtransfer_DATA = \
Expand Down Expand Up @@ -222,9 +223,10 @@ ylibcfadir = "${yast2dir}/lib/installation/cfa"
ylibcfa_DATA = \
lib/installation/cfa/salt.rb

ylibrolehandlerdir = "${yast2dir}/lib/installation/system_roles"
ylibrolehandlerdir = "${yast2dir}/lib/installation/system_role_handlers"
ylibrolehandler_DATA = \
lib/installation/system_roles/handlers.rb
lib/installation/system_role_handlers/dashboard_role_finish.rb \
lib/installation/system_role_handlers/worker_role_finish.rb

EXTRA_DIST = $(module_DATA) $(client_DATA) $(ynclude_DATA) $(scrconf_DATA) $(schemafiles_DATA) $(desktop_DATA) $(fillup_DATA) $(ylibdialog_DATA) $(ylib_DATA) $(ylibtransfer_DATA) $(ylibcfa_DATA) $(ylibrolehandler_DATA)

Expand Down
12 changes: 2 additions & 10 deletions src/lib/installation/system_role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

require "yast"
require "installation/services"
require "installation/system_roles/handlers"
require "installation/system_role_handlers_runner"

Yast.import "ProductControl"
Yast.import "ProductFeatures"
Expand Down Expand Up @@ -165,15 +165,7 @@ def finish
log.info("There is no role selected so nothing to do")
return
end

class_name_role = current.split("_").map(&:capitalize).join
handler = "::Installation::SystemRoleHandlers::#{class_name_role}Finish"

if Object.const_defined?(handler)
Object.const_get(handler).run
else
log.info("There is no special finisher for #{current}")
end
SystemRoleHandlersRunner.new.finish(current)
end
end

Expand Down
38 changes: 38 additions & 0 deletions src/lib/installation/system_role_handlers/dashboard_role_finish.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# encoding: utf-8

# ------------------------------------------------------------------------------
# Copyright (c) 2017 SUSE LLC
#
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 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.
#
# To contact SUSE about this file by physical or electronic mail, you may find
# current contact information at www.suse.com.
# ------------------------------------------------------------------------------

require "yast"
require "yast2/execute"

module Installation
module SystemRoleHandlers
# Implement finish handler for the "dashboard" role
class DashboardRoleFinish
# Path to the activation script
ACTIVATION_SCRIPT_PATH = "/usr/share/caasp-container-manifests/activate.sh".freeze

# Run the activation script
def run
Yast::Execute.on_target(ACTIVATION_SCRIPT_PATH)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
# ------------------------------------------------------------------------------

require "yast"
require "installation/cfa/salt"

module Installation
module SystemRoleHandlers
# Implement finish handler for the "worker" role
class WorkerRoleFinish
include Yast::Logger

def self.run
# Configure Salt minion
def run
role = SystemRole.find("worker_role")
master_conf = CFA::MinionMasterConf.new
master = role["controller_node"]
Expand Down
61 changes: 61 additions & 0 deletions src/lib/installation/system_role_handlers_runner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# encoding: utf-8

# ------------------------------------------------------------------------------
# Copyright (c) 2017 SUSE LLC
#
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 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.
#
# To contact SUSE about this file by physical or electronic mail, you may find
# current contact information at www.suse.com.
# ------------------------------------------------------------------------------

require "yast"
require "installation/cfa/salt"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it is needed here??? It is for worker role only, so it should be in that file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I'll fix it (without version bumping) and anyway I'll remove it when merging into master.


module Installation
# Run system roles handlers
#
# System role handlers are a mechanism to execute code depending on the
# selected role. Currently those handlers are only used in the inst_finish
# client, but they could be extended in the future.
class SystemRoleHandlersRunner
include Yast::Logger

# Run the finish handler for a given role
def finish(role_id)
return unless require_handler(role_id)

class_name_role = role_id.split("_").map(&:capitalize).join
handler = "::Installation::SystemRoleHandlers::#{class_name_role}Finish"

if Object.const_defined?(handler)
Object.const_get(handler).new.run
else
log.info("There is no special finisher for #{role_id} ('#{class_name_role}' not defined)")
end
end

private

# Try to require the file where a handler is supposed to be defined
#
# @return [Boolean] True if the file was loaded; false otherwise.
def require_handler(role_id)
filename = "installation/system_role_handlers/#{role_id}_finish"
require filename
true
rescue LoadError
log.info("There is no special finisher for #{role_id} ('#{filename}' not found)")
end
end
end
6 changes: 4 additions & 2 deletions test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ TESTS = \
ssh_import_auto_test.rb \
ssh_importer_presenter_test.rb \
ssh_importer_test.rb \
system_role_handlers_test.rb \
system_role_test.rb \
update_repository_test.rb \
updates_manager_test.rb \
widgets_overview_test.rb \
widgets_system_role_test.rb
widgets_system_role_test.rb \
lib/system_role_handlers_runner_test.rb \
lib/system_role_handlers/dashboard_role_finish_test.rb \
lib/system_role_handlers/worker_role_finish_test.rb

TEST_EXTENSIONS = .rb
RB_LOG_COMPILER = rspec
Expand Down
15 changes: 15 additions & 0 deletions test/lib/system_role_handlers/dashboard_role_finish_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#! /usr/bin/env rspec

require_relative "../../test_helper"
require "installation/system_role_handlers/dashboard_role_finish"

describe Installation::SystemRoleHandlers::DashboardRoleFinish do
subject(:handler) { Installation::SystemRoleHandlers::DashboardRoleFinish.new }

describe "#run" do
it "runs the activation script" do
expect(Yast::Execute).to receive(:on_target).with(/activate.sh/)
handler.run
end
end
end
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#! /usr/bin/env rspec

require_relative "./test_helper"
require_relative "../../test_helper"
require "installation/system_role"
require "installation/system_roles/handlers"
require "installation/system_role_handlers/worker_role_finish"

describe Installation::SystemRoleHandlers::WorkerRoleFinish do
subject(:handler) { described_class.new }
let(:role) { instance_double("::Installation::SystemRole") }
let(:conf) do
instance_double("::Installation::CFA::MinionMasterConf", load: true, save: true)
Expand All @@ -21,16 +22,15 @@
it "surrounds the url with single quotes before save" do
expect(role).to receive(:[]).with("controller_node").and_return("controller-url")
expect(conf).to receive(:master=).with("'controller-url'")
described_class.run
handler.run
end

end

context "if the worker role controller node location does not contain dashes" do
it "saves the url as defined" do
expect(role).to receive(:[]).with("controller_node").and_return("controller")
expect(conf).to receive(:master=).with("controller")
described_class.run
handler.run
end
end

Expand All @@ -39,7 +39,7 @@
expect(conf).to receive(:master=).with("controller")
expect(conf).to receive(:save)

described_class.run
handler.run
end
end
end
46 changes: 46 additions & 0 deletions test/lib/system_role_handlers_runner_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env rspec

require_relative "../test_helper"
require "installation/system_role_handlers_runner"

describe Installation::SystemRoleHandlersRunner do
subject(:runner) { Installation::SystemRoleHandlersRunner.new }

describe "#finish" do
let(:handler_class) { double("HandlerClass") }
let(:handler) { double("HandlerInstance") }

before do
stub_const("::Installation::SystemRoleHandlers::TestRoleFinish", handler_class)
allow(handler_class).to receive(:new).and_return(handler)
allow(runner).to receive(:require).with("installation/system_role_handlers/test_role_finish")
end

it "runs the handler's 'run' method" do
expect(handler).to receive(:run)
runner.finish("test_role")
end

context "when handler file is not found" do
before do
allow(runner).to receive(:require).and_call_original
end

it "logs the error" do
expect(runner.log).to receive(:info).with(/not found/)
runner.finish("unknown_role")
end
end

context "when handler class is not defined" do
before do
allow(runner).to receive(:require).with("installation/system_role_handlers/undefined_role_finish")
end

it "logs the error" do
expect(runner.log).to receive(:info).with(/not defined/)
runner.finish("undefined_role")
end
end
end
end