Custom action for arbitrary commands

Support Nailgun hooks action as separate action.
This help us for tasks necessary for Fuel preparation
instead of cluster preparation

Implements blueprint downloadable-ubuntu-release

Change-Id: I4354842e5ff1ba940de1dae0f4bd639cdb70b0f3
This commit is contained in:
Vladimir Sharshov (warpc) 2015-02-02 16:57:03 +03:00
parent ed5270bf9c
commit cf25925680
5 changed files with 65 additions and 6 deletions

View File

@ -16,9 +16,10 @@
module Astute
class NailgunHooks
def initialize(nailgun_hooks, context)
def initialize(nailgun_hooks, context, type='deploy')
@nailgun_hooks = nailgun_hooks
@ctx = context
@type = type
end
def process
@ -34,19 +35,19 @@ module Astute
end
is_raise_on_error = hook.fetch('fail_on_error', true)
hook_name = hook['id'] || hook['diagnostic_name']
if !success && is_raise_on_error
nodes = hook['uids'].map do |uid|
{ 'uid' => uid,
'status' => 'error',
'error_type' => 'deploy',
'error_type' => @type,
'role' => 'hook',
'hook' => hook['diagnostic_name']
'hook' => hook_name
}
end
@ctx.report_and_update_status('nodes' => nodes)
raise Astute::DeploymentEngineError,
"Failed to deploy plugin #{hook['diagnostic_name']}"
raise Astute::DeploymentEngineError, "Failed to deploy plugin #{hook_name}"
end
end
end

View File

@ -31,6 +31,12 @@ module Astute
end
end
def execute_tasks(up_reporter, task_id, tasks)
ctx = Context.new(task_id, up_reporter)
Astute::NailgunHooks.new(tasks, ctx, 'execute_tasks').process
report_result({}, up_reporter)
end
def deploy(up_reporter, task_id, deployment_info, pre_deployment=[], post_deployment=[])
deploy_cluster(
up_reporter,

View File

@ -162,6 +162,21 @@ module Astute
remove_nodes(data)
end
def execute_tasks(data)
task_uuid = data['args']['task_uuid']
reporter = Astute::Server::Reporter.new(
@producer,
data['respond_to'],
task_uuid
)
@orchestrator.execute_tasks(
reporter,
task_uuid,
data['args']['tasks']
)
end
#
# Service worker actions
#

View File

@ -61,7 +61,7 @@ describe Astute::NailgunHooks do
"priority" => 100,
"type" => "shell",
"fail_on_error" => false,
"diagnostic_name" => "shell-example-1.0",
"id" => "shell-example-1.0",
"uids" => ['1','2','3'],
"parameters" => {
"cmd" => "./deploy.sh",
@ -96,6 +96,18 @@ describe Astute::NailgunHooks do
]
end
context '#new' do
it 'should use default run type if no type setting' do
hooks = Astute::NailgunHooks.new(hooks_data, ctx)
expect(hooks.instance_variable_get("@type")).to eql('deploy')
end
it 'should use type if it set' do
hooks = Astute::NailgunHooks.new(hooks_data, ctx, 'execute_tasks')
expect(hooks.instance_variable_get("@type")).to eql('execute_tasks')
end
end
context "#process" do
it 'should process known hook type' do
hooks = Astute::NailgunHooks.new(hooks_data, ctx)

View File

@ -709,4 +709,29 @@ describe Astute::Orchestrator do
end
end # stop_provision
describe '#execute_tasks' do
it 'should execute tasks using nailgun hooks' do
@orchestrator.stubs(:report_result)
Astute::NailgunHooks.any_instance.expects(:process)
@orchestrator.execute_tasks(@reporter, task_id="", tasks=[])
end
it 'should report succeed if all done without critical error' do
Astute::NailgunHooks.any_instance.stubs(:process)
@orchestrator.expects(:report_result).with({}, @reporter)
@orchestrator.execute_tasks(@reporter, task_id="", tasks=[])
end
it 'it should rescue exception if task failed' do
Astute::NailgunHooks.any_instance.stubs(:process)
.raises(Astute::DeploymentEngineError)
expect {@orchestrator.execute_tasks(@reporter, task_id="", tasks=[])}
.to raise_error(Astute::DeploymentEngineError)
end
end #execute_tasks
end