Skip to content

Commit

Permalink
Merge pull request #217 from jntullo/bz/provider_orchestrate_delete
Browse files Browse the repository at this point in the history
Use destroy_queue for provider delete
  • Loading branch information
Fryguy authored Nov 20, 2017
2 parents a488868 + e91c02a commit 4d00d26
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
20 changes: 5 additions & 15 deletions app/controllers/api/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ def refresh_resource(type, id = nil, _data = nil)
end

def delete_resource(type, id = nil, _data = nil)
raise BadRequestError, "Must specify an id for deleting a #{type} resource" unless id

api_action(type, id) do |klass|
provider = resource_search(id, type, klass)
api_log_info("Deleting #{provider_ident(provider)}")

destroy_provider(provider)
delete_action_handler do
raise BadRequestError, "Must specify an id for deleting a #{type} resource" unless id
provider = resource_search(id, type, collection_class(type))
task = provider.destroy_queue
action_result(true, "#{provider_ident(provider)} deleting", :task_id => task.id, :parent_id => id)
end
end

Expand Down Expand Up @@ -160,14 +158,6 @@ def refresh_provider(provider)
action_result(false, err.to_s)
end

def destroy_provider(provider)
desc = "#{provider_ident(provider)} deleting"
task_id = queue_object_action(provider, desc, :method_name => "destroy")
action_result(true, desc, :task_id => task_id)
rescue => err
action_result(false, err.to_s)
end

def import_vm_to_provider(provider, source_vm_id, target_params)
desc = "#{provider_ident(provider)} importing vm"
task_id = queue_object_action(provider, desc,
Expand Down
18 changes: 12 additions & 6 deletions spec/requests/providers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -803,10 +803,11 @@ def token(connection)

post(api_provider_url(nil, provider), :params => gen_request(:delete))

expect_single_action_result(:success => true,
:message => "deleting",
:href => api_provider_url(nil, provider),
:task => true)
expect_single_action_result(:success => true,
:message => "deleting",
:task_href => api_tasks_url,
:task => true,
:href => api_provider_url(nil, provider))
end

it "supports multiple provider deletes" do
Expand All @@ -818,9 +819,14 @@ def token(connection)
post(api_providers_url, :params => gen_request(:delete,
[{"href" => api_provider_url(nil, p1)},
{"href" => api_provider_url(nil, p2)}]))

expected = {
"results" => [
a_hash_including('task_href' => a_string_including(api_tasks_url)),
a_hash_including('task_href' => a_string_including(api_tasks_url))
]
}
expect_multiple_action_result(2, :task => true)
expect_result_resources_to_include_hrefs("results", [api_provider_url(nil, p1), api_provider_url(nil, p2)])
expect(response.parsed_body).to include(expected)
end
end

Expand Down

0 comments on commit 4d00d26

Please sign in to comment.