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

add flavors create, delete to api #14

Merged
merged 1 commit into from
Oct 19, 2017

Conversation

alexander-demicev
Copy link

Add flavors actions(create,delete) to api

Copy link

@jntullo jntullo left a comment

Choose a reason for hiding this comment

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

Hi @alexander-demichev, can you also add some specs to this? You will also need to update the config/api.yml. Thanks!

end

def validate_flavor_attrs(data)
data.dup
Copy link

Choose a reason for hiding this comment

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

not sure this method is necessary if no validation is being done. If you aren't manipulating the data, you shouldn't need to dup it either


def delete_resource(type, id, _data = {})
flavor = resource_search(id, type, collection_class(:flavors))
raise "Delete not supported for #{flavor_ident(flavor)}" unless flavor.respond_to?(:delete_flavor_queue)
Copy link

Choose a reason for hiding this comment

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

is this supposed to be delete_in_provider_queue? it's checking a different method than is used below

Copy link

Choose a reason for hiding this comment

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

@alexander-demichev I may be incorrect, but is this method delete_flavor_queue the correct method? I don't see any flavor descendants responding to it

Copy link
Author

Choose a reason for hiding this comment

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

@jntullo I made comment with link to flavors actions PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't all flavors respond to this? How does the user know which ones can be deleted? Is it possible that flavors could utilize the supports_feature? feature?

Copy link
Author

Choose a reason for hiding this comment

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

All flavors support delete. I should delete this line of code.

@alexander-demicev
Copy link
Author

alexander-demicev commented Aug 12, 2017

Thank you for review, @jntullo. I added some specs.

@alexander-demicev alexander-demicev force-pushed the flavors-api branch 5 times, most recently from 6b98a40 to f408fab Compare August 12, 2017 13:52
@alexander-demicev
Copy link
Author

Flavors actions are implemented here ManageIQ/manageiq#15552

@alexander-demicev
Copy link
Author

@jntullo Hi, can you review it again?

@imtayadeway
Copy link
Contributor

Hi! It looks like your PR has been affected by the recently merged #40, and as a result will need to be rebased. First, I apologize for any inconvenience caused. After rebasing, you'll need to update some specs in order for them to pass. In particular you'll need to change any path helpers, applying the following pattern:

vms_url => api_vms_url
vms_url(vm.id) => api_vm_url(nil, vm) 
vms_url(vm.compressed_id) => api_vm_url(nil, vm.compressed_id)
"#{vms_url(vm.id)}/tags" => api_vm_tags_url(nil, vm)
"#{vms_url(vm.compressed_id}/tags" => api_vm_tags_url(nil, vm.compressed_id)
"#{vms_url(vm.id)}/tags/#{tag.id}" => api_vm_tag_url(nil, vm, tag)
"#{vms_url(vm.compressed_id)}/tags/#{tag.compressed_id}" => api_vm_tag_url(nil, vm.compressed_id, tag.compressed_id)

If you run into any issues, please ping me and I will try to help you out.

Many thanks!
Tim

@alexander-demicev
Copy link
Author

@imtayadeway Hi, one of the tests is failing, can you take a look at it? Thanks. :-)


api_basic_authorize

run_delete api_flavors_url(nil, flavor)
Copy link

@jntullo jntullo Sep 11, 2017

Choose a reason for hiding this comment

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

I believe you want api_flavor_url(nil, flavor) here

Copy link
Author

Choose a reason for hiding this comment

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

@jntullo Silly mistake :) Thank you, now it`s ok!

@abellotti abellotti self-assigned this Sep 15, 2017
@aufi
Copy link
Member

aufi commented Sep 20, 2017

Looks good to me, looking forward to see this merged :-)

@abellotti
Copy link
Member

Maybe add 2 tests for delete single flavor (POST /api/flavors/:id - action edit) and do a bulk delete (POST /api/flavors - action edit).

Otherwise looks good,

@imtayadeway and @jntullo your 👀 when you get a chance. Thanks!!

Copy link

@jntullo jntullo left a comment

Choose a reason for hiding this comment

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

LGTM! ✨ Minor comment about removing compressed_id and just passing in the flavor object

'count' => 1,
'subcount' => 1,
'name' => 'flavors',
'resources' => [hash_including('href' => a_string_matching(api_flavors_url(nil, flavor.compressed_id)))]
Copy link

Choose a reason for hiding this comment

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

I wouldn't use compressed_id here, and instead just pass in flavor

@alexander-demicev
Copy link
Author

@jntullo @imtayadeway Hi, can you take a look, I edited tests and during CI it's throwing 'NoMethodError', but it works if I run test on my machine.

@jntullo
Copy link

jntullo commented Sep 21, 2017

hi @alexander-demichev, if you rebase and update to use get instead of run_get, etc, you should be good to go 👍

@alexander-demicev
Copy link
Author

Added some tests :) @imtayadeway @jntullo

@@ -1,4 +1,24 @@
module Api
class FlavorsController < BaseController
def create_resource(_type, _id, data)
task_id = Flavor.create_flavor_queue(User.current_user.id, EmsCloud.find(data['ems']['id']), data)
Copy link

Choose a reason for hiding this comment

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

Rather than EmsCloud.find here, I think you may want to use resource_search(:id, :providers, collection_class(:providers). Also, what do you think about supporting both id and href? Something along the lines of
{ "provider": { "href" : "/api/providers/:id" } or { "provider": { "id": ":id" } }. This example may help

action_result(false, err.to_s)
end

def delete_resource_snapshots(_parent, type, id, _data)
Copy link

Choose a reason for hiding this comment

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

I believe this should be flavors_delete_resource

@alexander-demicev alexander-demicev force-pushed the flavors-api branch 6 times, most recently from 020b5a3 to 8425e11 Compare October 9, 2017 08:16
@alexander-demicev
Copy link
Author

@jntullo @imtayadeway Can I ask you for another round of review? 😄

config/api.yml Outdated
@@ -861,20 +861,30 @@
:description: Flavors
:identifier: flavor
:options:
- :collection
:verbs: *gp
- :subcollection
Copy link

Choose a reason for hiding this comment

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

I didn't realize the collection already exists, I am assuming we'll still want to keep the collection actions? And just add in the subcollection actions?

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Yeah I think if it already exists we can preserve the ability to retrieve flavors using only their id

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, but as @jntullo suggested I think it would be better to leave the existing routes for flavor retrieval intact.

@alexander-demicev
Copy link
Author

@imtayadeway @jntullo Is it ok now?

config/api.yml Outdated
:klass: Flavor
:collection_actions:
:subcollection_actions:
Copy link

Choose a reason for hiding this comment

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

if you just add the collection actions back in, should be good to go 👍

@@ -114,11 +114,6 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
test_collection_query(:features, api_features_url, MiqProductFeature)
end

it "query Flavors" do
Copy link

Choose a reason for hiding this comment

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

and we'll want these once you add the collections actions back into the api.yml

Copy link

@jntullo jntullo left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @alexander-demichev! ✨

@abellotti
Copy link
Member

@alexander-demichev can you add the test for bulk deletes ? i.e. POST /api/providers/:id/flavors action "delete" with 2 flavors ?

Thanks.

@miq-bot
Copy link
Member

miq-bot commented Oct 19, 2017

Checked commit alexander-demicev@eb40c9e with ruby 2.3.3, rubocop 0.47.1, and haml-lint 0.20.0
3 files checked, 0 offenses detected
Everything looks fine. 🍪

@alexander-demicev
Copy link
Author

@abellotti Added tests for bulk delete.

@abellotti
Copy link
Member

Thanks @alexander-demichev for the added test and the API enhancement. 👍

@abellotti abellotti merged commit c5cc04a into ManageIQ:master Oct 19, 2017
@abellotti abellotti added this to the Sprint 72 Ending Oct 30, 2017 milestone Oct 19, 2017
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.

6 participants