Skip to content

Commit

Permalink
Merge pull request #14387 from abellotti/api_provider_refresh_task
Browse files Browse the repository at this point in the history
Enhanced API to have a task created for provider refreshes
  • Loading branch information
gtanzillo authored Mar 27, 2017
2 parents f1e1e7d + 8d45246 commit 646c668
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/controllers/api/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def edit_provider(provider, data)

def refresh_provider(provider)
desc = "#{provider_ident(provider)} refreshing"
provider.refresh_ems
action_result(true, desc)
task_id = provider.refresh_ems(:create_task => true).first
action_result(true, desc, :task_id => task_id)
rescue => err
action_result(false, err.to_s)
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -400,14 +400,14 @@ def last_refresh_status
end
end

def refresh_ems
def refresh_ems(opts = {})
if missing_credentials?
raise _("no %{table} credentials defined") % {:table => ui_lookup(:table => "ext_management_systems")}
end
unless authentication_status_ok?
raise _("%{table} failed last authentication check") % {:table => ui_lookup(:table => "ext_management_systems")}
end
EmsRefresh.queue_refresh(self)
EmsRefresh.queue_refresh(self, nil, opts)
end

def self.ems_infra_discovery_types
Expand Down
4 changes: 2 additions & 2 deletions app/models/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def my_zone
end
alias_method :zone_name, :my_zone

def refresh_ems
def refresh_ems(opts = {})
if missing_credentials?
raise _("no %{table} credentials defined") % {:table => ui_lookup(:table => "provider")}
end
unless authentication_status_ok?
raise _("%{table} failed last authentication check") % {:table => ui_lookup(:table => "provider")}
end
managers.each { |manager| EmsRefresh.queue_refresh(manager) }
managers.flat_map { |manager| EmsRefresh.queue_refresh(manager, nil, opts) }
end
end
30 changes: 30 additions & 0 deletions spec/requests/api/providers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,36 @@ def failed_auth_action(id)
expect(response).to have_http_status(:ok)
expect_results_to_match_hash("results", [failed_auth_action(p1.id), failed_auth_action(p2.id)])
end

it "provider refresh are created with a task" do
api_basic_authorize collection_action_identifier(:providers, :refresh)

provider = FactoryGirl.create(:ext_management_system, sample_vmware.symbolize_keys.except(:type))
provider.update_authentication(:default => default_credentials.symbolize_keys)
provider.authentication_type(:default).update(:status => "Valid")

run_post(providers_url(provider.id), gen_request(:refresh))

expect_single_action_result(:success => true,
:message => a_string_matching("Provider .* refreshing"),
:href => providers_url(provider.id),
:task => true)
end

it "provider refresh for provider_class=provider are created with a task" do
api_basic_authorize collection_action_identifier(:providers, :refresh)

provider = FactoryGirl.create(:provider_foreman, :zone => @zone, :url => "example.com", :verify_ssl => false)
provider.update_authentication(:default => default_credentials.symbolize_keys)
provider.authentication_type(:default).update(:status => "Valid")

run_post(providers_url(provider.id) + '?provider_class=provider', gen_request(:refresh))

expect_single_action_result(:success => true,
:message => a_string_matching("Provider .* refreshing"),
:href => providers_url(provider.id),
:task => true)
end
end

describe 'Providers import VM' do
Expand Down

0 comments on commit 646c668

Please sign in to comment.