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

Conversation

abellotti
Copy link
Member

Enhanced API to have a task created for provider refreshes and returns the appropriate task_id and task_href in the action result.

so a successful refresh action now return something like:

  {
    "success": true,
    "message": "Provider id:2 name:'rhev36' refreshing",
    "task_id": 55,
    "task_href": "http://localhost:3000/api/tasks/55",
    "href": "http://localhost:3000/api/providers/2"
  }

Added spec

@abellotti abellotti added the wip label Mar 17, 2017
@miq-bot miq-bot removed the wip label Mar 17, 2017
@abellotti abellotti added the wip label Mar 17, 2017
@abellotti abellotti changed the title Enhanced API to have a task created for provider refreshes [WIP] Enhanced API to have a task created for provider refreshes Mar 17, 2017
@abellotti
Copy link
Member Author

abellotti commented Mar 17, 2017

marked as WIP.

Needs an enhancement for actions creating multiple tasks (i.e. provider_class=provider) where refresh targets multiple managers, we only return the task_id and task_href for the first. Could be done in a separate PR, will need to see how the client handles that.

@abellotti
Copy link
Member Author

Looks like this is needed as per @mkanoor

Un-wipping with caveat that for multi-manager providers, only the task for the first manager is returned as per Issue #14404.

/cc @Fryguy @imtayadeway please review, Thanks!!

@abellotti abellotti removed the wip label Mar 22, 2017
@abellotti abellotti changed the title [WIP] Enhanced API to have a task created for provider refreshes Enhanced API to have a task created for provider refreshes Mar 22, 2017
@@ -400,14 +400,15 @@ def last_refresh_status
end
end

def refresh_ems
def refresh_ems(opts = nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a concern that you might explicitly send the argument nil to this method? If not, opts = {} should suffice (without the following line)

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.collect { |manager| EmsRefresh.queue_refresh(manager, nil, opts) }.flatten
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps flat_map here for a single operation?

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.

  and returns the appropriate task_id and task_href in
  the action result.

  so a successful "refresh" action now return something like:

  {
    "success": true,
    "message": "Provider id:2 name:'rhev36' refreshing",
    "task_id": 55,
    "task_href": "http://localhost:3000/api/tasks/55",
    "href": "http://localhost:3000/api/providers/2"
  }

- Supports both ext_management_system and provider (i.e. provider_class=provider)
- Added spec

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?

@miq-bot
Copy link
Member

miq-bot commented Mar 23, 2017

Checked commits abellotti/manageiq@f7715b5~...8d45246 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
4 files checked, 0 offenses detected
Everything looks good. ⭐

@abellotti
Copy link
Member Author

Anything else needed for this PR ?

@mkanoor
Copy link
Contributor

mkanoor commented Mar 24, 2017

@gtanzillo @imtayadeway @gmcculloug @Fryguy

This feature is critical for calling a refresh from Ansible Playbooks, without this feature the playbook would have to sleep for an arbitrary amount of time hoping that the refresh has completed.

Copy link
Contributor

@imtayadeway imtayadeway left a comment

Choose a reason for hiding this comment

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

👍 LGTM 🎹

Copy link
Member

@gtanzillo gtanzillo left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@gtanzillo gtanzillo added this to the Sprint 57 Ending Mar 27, 2017 milestone Mar 27, 2017
@gtanzillo gtanzillo merged commit 646c668 into ManageIQ:master Mar 27, 2017
@abellotti abellotti deleted the api_provider_refresh_task branch April 11, 2017 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants