Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #543 from imobachgs/add-dashboard-role-handler
Add dashboard role handler
- Loading branch information
Showing
11 changed files
with
188 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/lib/installation/system_role_handlers/dashboard_role_finish.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
test/lib/system_role_handlers/dashboard_role_finish_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |