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

[api] Add support for Cloud Volume Delete action #15097

Merged
merged 9 commits into from
May 22, 2017

Conversation

AparnaKarve
Copy link
Contributor

@AparnaKarve AparnaKarve commented May 15, 2017

Added support for deleting Cloud Volumes via POST.

POST /api/cloud_volumes

{
  "action" : "delete",
  "resources" : { 
    'id': 1,
    'id': 2
  }
}

/cc @abellotti

@AparnaKarve
Copy link
Contributor Author

This would have to be a queued Delete operation.
Setting WIP for now.

@miq-bot add_label wip

@miq-bot miq-bot changed the title [api] Add support for Cloud Volume Delete action [WIP] [api] Add support for Cloud Volume Delete action May 15, 2017
@miq-bot miq-bot added the wip label May 15, 2017
config/api.yml Outdated
:resource_actions:
:get:
- :name: read
:identifier: cloud_volume
:post:
- :name: query
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem like part of this PR - was this ne cessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you're right, not related to this PR.
I have removed it.

@@ -477,10 +477,17 @@
:post:
- :name: query
:identifier: cloud_volume_show_list
- :name: delete
Copy link
Contributor

Choose a reason for hiding this comment

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

I see there's a test below but I don't think it covers the bulk delete you've added here - can you add one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only reason I have the delete here is to avoid the below error.
That's the only purpose it serves.

Failures:

  1) Cloud Volumes API can delete cloud volumes through POST
     Failure/Error:
       Api::ApiConfig.collections[type][selection][method]
         .detect { |spec| spec[:name] == action.to_s }[:identifier]
     
     NoMethodError:
       undefined method `[]' for nil:NilClass
     # ./spec/support/api_helper.rb:113:in `action_identifier'
     # ./spec/support/api_helper.rb:117:in `collection_action_identifier'
     # ./spec/requests/api/cloud_volumes_spec.rb:51:in `block (2 levels) in <top (required)>'

I have also tried using

api_basic_authorize action_identifier(:cloud_volumes, :delete, :resource_actions, :post)

but that requires the delete in collection_actions as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@imtayadeway What do you think of the above?

Copy link
Contributor

Choose a reason for hiding this comment

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

@AparnaKarve I think I confused myself :) This is correct - it's the one below that's not covered by a test

Copy link
Contributor Author

@AparnaKarve AparnaKarve May 16, 2017

Choose a reason for hiding this comment

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

The resource_actions delete which is under post is covered by a test.
And that would be the test for it https://github.com/ManageIQ/manageiq/pull/15097/files#diff-3eaddeceef284aecbf30c2f57658d722R52

@imtayadeway
Copy link
Contributor

@AparnaKarve can you also add some tests to ensure that RBAC will kick you out if not authorized? Otherwise LGTM!

config/api.yml Outdated
@@ -468,7 +468,7 @@
:identifier: cloud_volume
:options:
- :collection
:verbs: *gp
:verbs: *gpppd
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you only need gpd here....

Since you're adding the 'd' - can you add tests for deleting via DELETE using the collection/member routes, and that RBAC is enforced for both of these too? I have a feeling this may require some more configuration (i.e. adding an explicit entry for delete with the appropriate identifier for each)

@AparnaKarve AparnaKarve force-pushed the api_cloud_volume_delete branch 2 times, most recently from 0ef853a to 44b99c0 Compare May 17, 2017 20:14
@AparnaKarve
Copy link
Contributor Author

@imtayadeway Thanks for all your input so far.
Do you think this is now good to go?


cloud_volume1 = FactoryGirl.create(:cloud_volume, :ext_management_system => aws, :name => "CloudVolume1")

api_basic_authorize action_identifier(:cloud_volumes, :delete)
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be action_identifier(:cloud_volumes, :delete, :resource_actions, :delete) - which I think does not exist (yet). Can you add that also confirm that we reject DELETES for users that don't have the appropriate role?


cloud_volume1 = FactoryGirl.create(:cloud_volume, :ext_management_system => aws, :name => "CloudVolume1")

api_basic_authorize action_identifier(:cloud_volumes, :delete)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly action_identifier(:cloud_volumes, :delete, :collection_actions, :delete) + test for rejection

@imtayadeway
Copy link
Contributor

@AparnaKarve this is looking great, I just have a couple of suggestions above

api_basic_authorize collection_action_identifier(:cloud_volumes, :delete, :post)

expected = {
'results' => [
Copy link
Contributor

Choose a reason for hiding this comment

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

We may not be able to guarantee the order here, so you may want to use a_collection_containing_exactly() over []

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 with just one more comment above. Thanks! 🎈

@AparnaKarve
Copy link
Contributor Author

AparnaKarve commented May 18, 2017

@imtayadeway I just happened to notice this Coverage increased (+6.5%) to 41.703%, which is great!

Thank you for requesting specs for all possible DELETE cases :)

@AparnaKarve AparnaKarve reopened this May 18, 2017
@AparnaKarve
Copy link
Contributor Author

@miq-bot remove_label wip

@AparnaKarve AparnaKarve changed the title [WIP] [api] Add support for Cloud Volume Delete action [api] Add support for Cloud Volume Delete action May 18, 2017
@miq-bot miq-bot removed the wip label May 18, 2017
@AparnaKarve
Copy link
Contributor Author

@abellotti Please review/merge. Thanks.

config/api.yml Outdated
@@ -477,10 +477,21 @@
:post:
- :name: query
:identifier: cloud_volume_show_list
- :name: delete
:identifier: cloud_volume_delete
:delete:
Copy link
Member

Choose a reason for hiding this comment

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

we don't expose DELETE method on the collection itself, so this is not consistent with the others. DELETE targets should be fully identified by the URL itself, even though the standard does not prohibit it, some other vendors just ignore the body. Let's stick to POST for bulk delete unless this is an issue. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@abellotti I have removed the DELETE method on the collection and the related specs (6ca849f). Please review. Thanks.

@miq-bot
Copy link
Member

miq-bot commented May 19, 2017

Checked commits AparnaKarve/manageiq@47a9e32~...6ca849f with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks fine. 🍪

@abellotti
Copy link
Member

Thanks @AparnaKarve for the enhancement. LGTM!! 👍

@abellotti abellotti merged commit d4e12c9 into ManageIQ:master May 22, 2017
@abellotti abellotti added this to the Sprint 61 Ending May 22, 2017 milestone May 22, 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.

5 participants