Skip to content

Commit

Permalink
Add a Dashboard role handler which runs the activation script
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Mar 23, 2017
1 parent e70000e commit ac448e6
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/lib/installation/system_role_handlers/dashboard_role_finish.rb
@@ -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 test/lib/system_role_handlers/dashboard_role_finish_test.rb
@@ -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

0 comments on commit ac448e6

Please sign in to comment.