Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Dashboard role handler which runs the activation script
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
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,28 @@ | ||
require "yast" | ||
Yast.import "Popup" | ||
Yast.import "FileUtils" | ||
|
||
module Installation | ||
module SystemRoleHandlers | ||
class DashboardRoleFinish | ||
include Yast::I18n | ||
include Yast::Logger | ||
|
||
# Path to the activation script | ||
ACTIVATION_SCRIPT_PATH = "/usr/share/caasp-container-manifests/activate.sh".freeze | ||
|
||
# Run the activation script | ||
def run | ||
if !Yast::FileUtils.Exists(ACTIVATION_SCRIPT_PATH) | ||
Yast::Popup.Error(_("Activation script not found:\n#{ACTIVATION_SCRIPT_PATH}")) | ||
return | ||
end | ||
|
||
out = Yast::SCR.Execute(Yast::Term.new(".target.bash_output"), ACTIVATION_SCRIPT_PATH) | ||
return if out["exit"].zero? | ||
|
||
Yast::Popup.LongError(out["stdout"]) | ||
end | ||
end | ||
end | ||
end |
45 changes: 45 additions & 0 deletions
45
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,45 @@ | ||
#! /usr/bin/env rspec | ||
|
||
require_relative "../../test_helper" | ||
require "installation/system_role" | ||
require "installation/system_role_handlers/dashboard_role_finish" | ||
|
||
describe Installation::SystemRoleHandlers::DashboardRoleFinish do | ||
subject(:handler) { Installation::SystemRoleHandlers::DashboardRoleFinish.new } | ||
|
||
describe "#run" do | ||
let(:script_exists) { true } | ||
|
||
before do | ||
allow(Yast::FileUtils).to receive(:Exists).with(/activate.sh/) | ||
.and_return(script_exists) | ||
end | ||
|
||
it "runs the activation script" do | ||
expect(Yast::SCR).to receive(:Execute) | ||
.with(Yast::Term.new(".target.bash_output"), /activate.sh/) | ||
.and_return("exit" => 0) | ||
handler.run | ||
end | ||
|
||
context "when the script is not found" do | ||
let(:script_exists) { false } | ||
|
||
it "informs the user" do | ||
expect(Yast::Popup).to receive(:Error) | ||
handler.run | ||
end | ||
end | ||
|
||
context "when the script fails" do | ||
it "shows the error to the user" do | ||
allow(Yast::SCR).to receive(:Execute) | ||
.with(Yast::Term.new(".target.bash_output"), /activate.sh/) | ||
.and_return("exit" => 1, "stderr" => "Some error") | ||
expect(Yast::Popup).to receive(:LongError) | ||
.with(/Some error/) | ||
handler.run | ||
end | ||
end | ||
end | ||
end |