-
Notifications
You must be signed in to change notification settings - Fork 143
add flavors create, delete to api #14
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Api | ||
module Subcollections | ||
module Flavors | ||
def flavors_query_resource(object) | ||
object.flavors | ||
end | ||
|
||
def flavors_create_resource(parent, _type, _id, data) | ||
task_id = Flavor.create_flavor_queue(User.current_user.id, parent, data) | ||
action_result(true, 'Creating Flavor', :task_id => task_id) | ||
rescue => err | ||
action_result(false, err.to_s) | ||
end | ||
|
||
def delete_resource_flavors(_parent, type, id, _data) | ||
flavor = resource_search(id, type, collection_class(type)) | ||
task_id = flavor.delete_flavor_queue(User.current_user.id) | ||
action_result(true, "Deleting #{flavor_ident(flavor)}", :task_id => task_id) | ||
rescue => err | ||
action_result(false, err.to_s) | ||
end | ||
alias flavors_delete_resource delete_resource_flavors | ||
|
||
private | ||
|
||
def flavor_ident(flavor) | ||
"Flavor id:#{flavor.id} name: '#{flavor.name}'" | ||
end | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
RSpec.describe "Flavors API" do | ||
describe "as a subcollection of providers" do | ||
describe "GET /api/providers/:c_id/flavors" do | ||
it "can list the flavors of a provider" do | ||
api_basic_authorize(action_identifier(:flavors, :read, :subcollection_actions, :get)) | ||
ems = FactoryGirl.create(:ems_cloud) | ||
flavor = FactoryGirl.create(:flavor, :ext_management_system => ems) | ||
|
||
get(api_provider_flavors_url(nil, ems)) | ||
|
||
expected = { | ||
"count" => 1, | ||
"name" => "flavors", | ||
"resources" => [ | ||
{"href" => api_provider_flavor_url(nil, ems, flavor)} | ||
] | ||
} | ||
expect(response.parsed_body).to include(expected) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it "will not list flavors unless authorized" do | ||
api_basic_authorize | ||
ems = FactoryGirl.create(:ems_cloud) | ||
FactoryGirl.create(:flavor, :ext_management_system => ems) | ||
|
||
get(api_provider_flavors_url(nil, ems)) | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
describe "GET /api/providers/:c_id/flavors/:id" do | ||
it "can show a provider's flavor" do | ||
api_basic_authorize(action_identifier(:flavors, :read, :subresource_actions, :get)) | ||
ems = FactoryGirl.create(:ems_cloud) | ||
flavor = FactoryGirl.create(:flavor, :ext_management_system => ems) | ||
|
||
get(api_provider_flavor_url(nil, ems, flavor)) | ||
|
||
expected = { | ||
"href" => api_provider_flavor_url(nil, ems, flavor), | ||
"id" => flavor.id.to_s | ||
} | ||
expect(response.parsed_body).to include(expected) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it "will not show a flavor unless authorized" do | ||
api_basic_authorize | ||
ems = FactoryGirl.create(:ems_cloud) | ||
flavor = FactoryGirl.create(:flavor, :ext_management_system => ems) | ||
|
||
get(api_provider_flavor_url(nil, ems, flavor)) | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
describe "POST /api/providers/:c_id/flavors" do | ||
it "can queue the creation of a flavors" do | ||
api_basic_authorize(action_identifier(:flavors, :create, :subcollection_actions)) | ||
ems = FactoryGirl.create(:ems_cloud) | ||
|
||
post(api_provider_flavors_url(nil, ems), :params => { :name => "test-flavor" }) | ||
|
||
expected = { | ||
"results" => [ | ||
a_hash_including( | ||
"success" => true, | ||
"message" => "Creating Flavor", | ||
"task_id" => anything, | ||
"task_href" => a_string_matching(api_tasks_url) | ||
) | ||
] | ||
} | ||
expect(response.parsed_body).to include(expected) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it "will not create a flavor unless authorized" do | ||
api_basic_authorize | ||
ems = FactoryGirl.create(:ems_cloud) | ||
|
||
post(api_provider_flavors_url(nil, ems), :params => { :name => "test-flavor" }) | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
describe "POST /api/providers/:c_id/flavors/:s_id with delete action" do | ||
it "can queue a flavor for deletion" do | ||
api_basic_authorize(action_identifier(:flavors, :delete, :subresource_actions)) | ||
|
||
ems = FactoryGirl.create(:ems_cloud) | ||
flavor = FactoryGirl.create(:flavor, :ext_management_system => ems) | ||
|
||
post(api_provider_flavor_url(nil, ems, flavor), :params => { :action => "delete" }) | ||
|
||
expected = { | ||
"message" => "Deleting Flavor id:#{flavor.id} name: '#{flavor.name}'", | ||
"success" => true, | ||
"task_href" => a_string_matching(api_tasks_url), | ||
"task_id" => anything | ||
} | ||
expect(response.parsed_body).to include(expected) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it "will not delete a flavor unless authorized" do | ||
api_basic_authorize | ||
ems = FactoryGirl.create(:ems_cloud) | ||
flavor = FactoryGirl.create(:flavor, :ext_management_system => ems) | ||
|
||
post(api_provider_flavor_url(nil, ems, flavor), :params => { :action => "delete" }) | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
describe "POST /api/providers/:c_id/flavors/ with delete action" do | ||
it "can delete multiple flavors" do | ||
ems = FactoryGirl.create(:ems_cloud) | ||
flavor1, flavor2 = FactoryGirl.create_list(:flavor, 2) | ||
|
||
api_basic_authorize(action_identifier(:flavors, :delete, :subresource_actions)) | ||
|
||
post(api_provider_flavors_url(nil, ems), :params => { :action => "delete", :resources => [{:id => flavor1.id}, | ||
{:id => flavor2.id}] }) | ||
|
||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it "forbids multiple flavor deletion without an appropriate role" do | ||
ems = FactoryGirl.create(:ems_cloud) | ||
flavor1, flavor2 = FactoryGirl.create_list(:flavor, 2) | ||
|
||
api_basic_authorize | ||
|
||
post(api_provider_flavors_url(nil, ems), :params => { :action => "delete", :resources => [{:id => flavor1.id}, | ||
{:id => flavor2.id}] }) | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
describe "DELETE /api/providers/:c_id/flavors/:s_id" do | ||
it "can delete a flavor" do | ||
ems = FactoryGirl.create(:ems_cloud) | ||
flavor = FactoryGirl.create(:flavor, :ext_management_system => ems) | ||
|
||
api_basic_authorize(action_identifier(:flavors, :delete, :subresource_actions, :delete)) | ||
|
||
delete(api_provider_flavor_url(nil, ems, flavor)) | ||
|
||
expect(response).to have_http_status(:no_content) | ||
end | ||
|
||
it "will not delete a flavor unless authorized" do | ||
ems = FactoryGirl.create(:ems_cloud) | ||
flavor = FactoryGirl.create(:flavor, :ext_management_system => ems) | ||
|
||
api_basic_authorize | ||
|
||
delete(api_provider_flavor_url(nil, ems, flavor)) | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@imtayadeway @jntullo Should I check 'data' for all needed attributes here? Openstack has it's own check and there will be a check on frontend level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexander-demichev no, best to keep that logic out of the controller, and it seems it's already being well handled by Openstack 👍