-
Notifications
You must be signed in to change notification settings - Fork 44
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
imobachgs
merged 8 commits into
yast:SLE-12-SP2-CASP
from
imobachgs:add-dashboard-role-handler
Mar 23, 2017
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
08cb32c
Extract execution system role handlers to its own class
imobachgs e70000e
Adapt system role handlers to be just plain objects
imobachgs ac448e6
Add a Dashboard role handler which runs the activation script
imobachgs e881523
Use Yast::Execute instead of Yast::SCR in Dashboard handler
imobachgs f6c3e36
Add some documentation to system role handlers
imobachgs fb31fc2
Update Makefiles to include new code
imobachgs cce1090
Fix tests permissions
imobachgs 661c867
Bump version and update changes file
imobachgs File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.