diff --git a/app/controllers/api/providers_controller.rb b/app/controllers/api/providers_controller.rb index c9331ff2475..0d2c86f1071 100644 --- a/app/controllers/api/providers_controller.rb +++ b/app/controllers/api/providers_controller.rb @@ -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 diff --git a/app/models/ext_management_system.rb b/app/models/ext_management_system.rb index 6da193ac2d6..9d80595e81a 100644 --- a/app/models/ext_management_system.rb +++ b/app/models/ext_management_system.rb @@ -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 diff --git a/app/models/provider.rb b/app/models/provider.rb index 9af033a7ffa..bb08ac530f9 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -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 diff --git a/spec/requests/api/providers_spec.rb b/spec/requests/api/providers_spec.rb index a82d85ad804..3b4c246b177 100644 --- a/spec/requests/api/providers_spec.rb +++ b/spec/requests/api/providers_spec.rb @@ -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