Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced API to have a task created for provider refreshes #14387

Merged
merged 3 commits into from
Mar 27, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
allow_any_instance_of(provider.class).to receive_messages(:authentication_status_ok? => true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although still problematic, WDYT about doing something like:

provider.authentication_type(:default).update(:status => "Valid")

to avoid the use of any_instance_of?


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)
allow_any_instance_of(provider.class).to receive_messages(:authentication_status_ok? => true)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it whatever caused us to have to write queries like this is still an issue? 😁

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we'll need to enhance the run_post method to support options like we do with run_get.


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