diff --git a/app/controllers/api/resource_pools_controller.rb b/app/controllers/api/resource_pool_clouds_controller.rb similarity index 71% rename from app/controllers/api/resource_pools_controller.rb rename to app/controllers/api/resource_pool_clouds_controller.rb index 6734bc4b5d..bf42fe2ce9 100644 --- a/app/controllers/api/resource_pools_controller.rb +++ b/app/controllers/api/resource_pool_clouds_controller.rb @@ -1,5 +1,5 @@ module Api - class ResourcePoolsController < BaseController + class ResourcePoolCloudsController < BaseController include Subcollections::Policies include Subcollections::PolicyProfiles include Subcollections::Tags diff --git a/app/controllers/api/resource_pool_infras_controller.rb b/app/controllers/api/resource_pool_infras_controller.rb new file mode 100644 index 0000000000..36a9a0a222 --- /dev/null +++ b/app/controllers/api/resource_pool_infras_controller.rb @@ -0,0 +1,7 @@ +module Api + class ResourcePoolInfrasController < BaseController + include Subcollections::Policies + include Subcollections::PolicyProfiles + include Subcollections::Tags + end +end diff --git a/config/api.yml b/config/api.yml index 4ff601c747..3db74f23ad 100644 --- a/config/api.yml +++ b/config/api.yml @@ -3325,13 +3325,58 @@ - :subcollection :verbs: *g :klass: ResourceAction - :resource_pools: - :description: Resource Pools - :identifier: resource_pool + + :resource_pool_clouds: + :description: Cloud Resource Pools + :identifier: resource_pool_cloud + :options: + - :collection + :verbs: *gp + :klass: ManageIQ::Providers::CloudManager::ResourcePool + :subcollections: + - :tags + - :policies + - :policy_profiles + :collection_actions: + :get: + - :name: read + :identifier: resource_pool_cloud_show_list + :post: + - :name: query + :identifier: resource_pool_cloud_show_list + :resource_actions: + :get: + - :name: read + :identifier: resource_pool_cloud_show + :post: + - :name: delete + :identifier: resource_pool_cloud_delete + :tags_subcollection_actions: + :post: + - :name: assign + :identifier: resource_pool_cloud_tag + - :name: unassign + :identifier: resource_pool_cloud_tag + :policies_subcollection_actions: + :post: + - :name: assign + :identifier: resource_pool_cloud_protect + - :name: unassign + :identifier: resource_pool_cloud_protect + :policy_profiles_subcollection_actions: + :post: + - :name: assign + :identifier: resource_pool_cloud_protect + - :name: unassign + :identifier: resource_pool_cloud_protect + + :resource_pool_infras: + :description: Infrastructure Resource Pools + :identifier: resource_pool_infra :options: - :collection :verbs: *gp - :klass: ResourcePool + :klass: ManageIQ::Providers::InfraManager::ResourcePool :subcollections: - :tags - :policies @@ -3339,35 +3384,35 @@ :collection_actions: :get: - :name: read - :identifier: resource_pool_show_list + :identifier: resource_pool_infra_show_list :post: - :name: query - :identifier: resource_pool_show_list + :identifier: resource_pool_infra_show_list :resource_actions: :get: - :name: read - :identifier: resource_pool_show + :identifier: resource_pool_infra_show :post: - :name: delete - :identifier: resource_pool_delete + :identifier: resource_pool_infra_delete :tags_subcollection_actions: :post: - :name: assign - :identifier: resource_pool_tag + :identifier: resource_pool_infra_tag - :name: unassign - :identifier: resource_pool_tag + :identifier: resource_pool_infra_tag :policies_subcollection_actions: :post: - :name: assign - :identifier: resource_pool_protect + :identifier: resource_pool_infra_protect - :name: unassign - :identifier: resource_pool_protect + :identifier: resource_pool_infra_protect :policy_profiles_subcollection_actions: :post: - :name: assign - :identifier: resource_pool_protect + :identifier: resource_pool_infra_protect - :name: unassign - :identifier: resource_pool_protect + :identifier: resource_pool_infra_protect :results: :description: Report Results :identifier: miq_report_reports diff --git a/spec/requests/collections_spec.rb b/spec/requests/collections_spec.rb index 5dcde85fcf..f5965e91ac 100644 --- a/spec/requests/collections_spec.rb +++ b/spec/requests/collections_spec.rb @@ -256,9 +256,14 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil) test_collection_query(:requests, api_requests_url, MiqRequest) end - it "query Resource Pools" do + it "query Cloud Resource Pool" do FactoryBot.create(:resource_pool) - test_collection_query(:resource_pools, api_resource_pools_url, ResourcePool) + test_collection_query(:resource_pool_clouds, api_resource_pool_clouds_url, ManageIQ::Providers::CloudManager::ResourcePool) + end + + it "query Infra Resource Pool" do + FactoryBot.create(:resource_pool) + test_collection_query(:resource_pool_infras, api_resource_pool_infras_url, ManageIQ::Providers::InfraManager::ResourcePool) end it "query Roles" do @@ -586,9 +591,14 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil) test_collection_bulk_query(:requests, api_requests_url, MiqRequest) end - it "bulk query Resource Pools" do - FactoryBot.create(:resource_pool) - test_collection_bulk_query(:resource_pools, api_resource_pools_url, ResourcePool) + it "bulk query Cloud Resource Pools" do + FactoryBot.create(:resource_pool, :type => 'ManageIQ::Providers::CloudManager::ResourcePool') + test_collection_bulk_query(:resource_pool_clouds, api_resource_pool_clouds_url, ManageIQ::Providers::CloudManager::ResourcePool) + end + + it "bulk query Infra Resource Pools" do + FactoryBot.create(:resource_pool, :type => 'ManageIQ::Providers::InfraManager::ResourcePool') + test_collection_bulk_query(:resource_pool_infras, api_resource_pool_infras_url, ManageIQ::Providers::InfraManager::ResourcePool) end it "bulk query Roles" do diff --git a/spec/requests/policies_assignment_spec.rb b/spec/requests/policies_assignment_spec.rb index 6bb7287d0d..b530000406 100644 --- a/spec/requests/policies_assignment_spec.rb +++ b/spec/requests/policies_assignment_spec.rb @@ -6,7 +6,8 @@ # /api/vms/:id # /api/providers/:id # /api/hosts/:id -# /api/resource_pools/:id +# /api/resource_pool_clouds/:id +# /api/resource_pool_infras/:id # /api/clusters/:id # /api/templates/:id # @@ -22,7 +23,8 @@ let(:cluster) do FactoryBot.create(:ems_cluster, :ext_management_system => provider, :hosts => [host], :vms => []) end - let(:rp) { FactoryBot.create(:resource_pool, :name => "Resource Pool 1") } + let(:rpc) { FactoryBot.create(:resource_pool, :name => "Resource Pool 1", :type => ManageIQ::Providers::CloudManager::ResourcePool) } + let(:rpi) { FactoryBot.create(:resource_pool, :name => "Resource Pool 1", :type => ManageIQ::Providers::InfraManager::ResourcePool) } let(:vm) { FactoryBot.create(:vm) } let(:template) do FactoryBot.create(:miq_template, :name => "Tmpl 1", :vendor => "vmware", :location => "tmpl_1.vmtx") @@ -322,87 +324,171 @@ def test_unassign_multiple_policy_profiles(api_object_policies_url, collection, end end - context "Resource Pool policies subcollection assignments" do - it "assign Resource Pool policy without appropriate role" do - test_policy_assign_no_role(api_resource_pool_policies_url(nil, rp)) + context "Resource Pool Cloud policies subcollection assignments" do + it "assign Resource Pool Cloud policy without appropriate role" do + test_policy_assign_no_role(api_resource_pool_cloud_policies_url(nil, rpc)) end - it "assign Resource Pool policy with invalid href" do - test_policy_assign_invalid_policy(api_resource_pool_policies_url(nil, rp), :resource_pools, :policies) + it "assign Resource Pool Cloud policy with invalid href" do + test_policy_assign_invalid_policy(api_resource_pool_cloud_policies_url(nil, rpc), :resource_pool_clouds, :policies) end - it "assign Resource Pool policy with invalid guid" do - test_policy_assign_invalid_policy_guid(api_resource_pool_url(nil, rp), api_resource_pool_policies_url(nil, rp), :resource_pools, :policies) + it "assign Resource Pool Cloud policy with invalid guid" do + test_policy_assign_invalid_policy_guid(api_resource_pool_cloud_url(nil, rpc), api_resource_pool_cloud_policies_url(nil, rpc), :resource_pool_clouds, :policies) end - it "assign Resource Pool multiple policies" do - test_assign_multiple_policies(api_resource_pool_url(nil, rp), - api_resource_pool_policies_url(nil, rp), - :resource_pools, + it "assign Resource Pool Cloud multiple policies" do + test_assign_multiple_policies(api_resource_pool_cloud_url(nil, rpc), + api_resource_pool_cloud_policies_url(nil, rpc), + :resource_pool_clouds, :policies, - :object => rp, + :object => rpc, :policies => [p1, p2]) end - it "unassign Resource Pool policy without approriate role" do - test_policy_unassign_no_role(api_resource_pool_policies_url(nil, rp)) + it "unassign Resource Pool Cloud policy without approriate role" do + test_policy_unassign_no_role(api_resource_pool_cloud_policies_url(nil, rpc)) end - it "unassign Resource Pool policy with invalid href" do - test_policy_unassign_invalid_policy(api_resource_pool_policies_url(nil, rp), :resource_pools, :policies) + it "unassign Resource Pool Cloud policy with invalid href" do + test_policy_unassign_invalid_policy(api_resource_pool_cloud_policies_url(nil, rpc), :resource_pool_clouds, :policies) end - it "unassign Resource Pool policy with invalid guid" do - test_policy_unassign_invalid_policy_guid(api_resource_pool_url(nil, rp), api_resource_pool_policies_url(nil, rp), :resource_pools, :policies) + it "unassign Resource Pool Cloud policy with invalid guid" do + test_policy_unassign_invalid_policy_guid(api_resource_pool_cloud_url(nil, rpc), api_resource_pool_cloud_policies_url(nil, rpc), :resource_pool_clouds, :policies) end - it "unassign Resource Pool multiple policies" do - test_unassign_multiple_policies(api_resource_pool_policies_url(nil, rp), :resource_pools, :policies, :object => rp) + it "unassign Resource Pool Cloud multiple policies" do + test_unassign_multiple_policies(api_resource_pool_cloud_policies_url(nil, rpc), :resource_pool_clouds, :policies, :object => rpc) end end - context "Resource Pool policy profiles subcollection assignments" do - it "assign Resource Pool policy profile without approriate role" do - test_policy_assign_no_role(api_resource_pool_policy_profiles_url(nil, rp)) + context "Resource Pool Cloud policy profiles subcollection assignments" do + it "assign Resource Pool Cloud policy profile without approriate role" do + test_policy_assign_no_role(api_resource_pool_cloud_policy_profiles_url(nil, rpc)) end - it "assign Resource Pool policy profile with invalid href" do - test_policy_assign_invalid_policy(api_resource_pool_policy_profiles_url(nil, rp), :resource_pools, :policy_profiles) + it "assign Resource Pool Cloud policy profile with invalid href" do + test_policy_assign_invalid_policy(api_resource_pool_cloud_policy_profiles_url(nil, rpc), :resource_pool_clouds, :policy_profiles) end - it "assign Resource Pool policy profile with invalid guid" do - test_policy_assign_invalid_policy_guid(api_resource_pool_url(nil, rp), api_resource_pool_policy_profiles_url(nil, rp), :resource_pools, :policy_profiles) + it "assign Resource Pool Cloud policy profile with invalid guid" do + test_policy_assign_invalid_policy_guid(api_resource_pool_cloud_url(nil, rpc), api_resource_pool_cloud_policy_profiles_url(nil, rpc), :resource_pool_clouds, :policy_profiles) end - it "assign Resource Pool multiple policy profiles" do - test_assign_multiple_policies(api_resource_pool_url(nil, rp), - api_resource_pool_policy_profiles_url(nil, rp), - :resource_pools, + it "assign Resource Pool Cloud multiple policy profiles" do + test_assign_multiple_policies(api_resource_pool_cloud_url(nil, rpc), + api_resource_pool_cloud_policy_profiles_url(nil, rpc), + :resource_pool_clouds, :policy_profiles, - :object => rp, + :object => rpc, :policies => [ps1, ps2]) end - it "unassign Resource Pool policy profile without approriate role" do - test_policy_unassign_no_role(api_resource_pool_policy_profiles_url(nil, rp)) + it "unassign Resource Pool Cloud policy profile without approriate role" do + test_policy_unassign_no_role(api_resource_pool_cloud_policy_profiles_url(nil, rpc)) end - it "unassign Resource Pool policy profile with invalid href" do - test_policy_unassign_invalid_policy(api_resource_pool_policy_profiles_url(nil, rp), :resource_pools, :policy_profiles) + it "unassign Resource Pool Cloud policy profile with invalid href" do + test_policy_unassign_invalid_policy(api_resource_pool_cloud_policy_profiles_url(nil, rpc), :resource_pool_clouds, :policy_profiles) end - it "unassign Resource Pool policy profile with invalid guid" do - test_policy_unassign_invalid_policy_guid(api_resource_pool_url(nil, rp), - api_resource_pool_policy_profiles_url(nil, rp), - :resource_pools, + it "unassign Resource Pool Cloud policy profile with invalid guid" do + test_policy_unassign_invalid_policy_guid(api_resource_pool_cloud_url(nil, rpc), + api_resource_pool_cloud_policy_profiles_url(nil, rpc), + :resource_pool_clouds, :policy_profiles) end - it "unassign Resource Pool multiple policy profiles" do - test_unassign_multiple_policy_profiles(api_resource_pool_policy_profiles_url(nil, rp), - :resource_pools, + it "unassign Resource Pool Cloud multiple policy profiles" do + test_unassign_multiple_policy_profiles(api_resource_pool_cloud_policy_profiles_url(nil, rpc), + :resource_pool_clouds, :policy_profiles, - :object => rp) + :object => rpc) + end + end + + context "Resource Pool Infra policies subcollection assignments" do + it "assign Resource Pool Infra policy without appropriate role" do + test_policy_assign_no_role(api_resource_pool_infra_policies_url(nil, rpi)) + end + + it "assign Resource Pool Infra policy with invalid href" do + test_policy_assign_invalid_policy(api_resource_pool_infra_policies_url(nil, rpi), :resource_pool_infras, :policies) + end + + it "assign Resource Pool Infra policy with invalid guid" do + test_policy_assign_invalid_policy_guid(api_resource_pool_infra_url(nil, rpi), api_resource_pool_infra_policies_url(nil, rpi), :resource_pool_infras, :policies) + end + + it "assign Resource Pool Infra multiple policies" do + test_assign_multiple_policies(api_resource_pool_infra_url(nil, rpi), + api_resource_pool_infra_policies_url(nil, rpi), + :resource_pool_infras, + :policies, + :object => rpi, + :policies => [p1, p2]) + end + + it "unassign Resource Pool Infra policy without approriate role" do + test_policy_unassign_no_role(api_resource_pool_infra_policies_url(nil, rpi)) + end + + it "unassign Resource Pool Infra policy with invalid href" do + test_policy_unassign_invalid_policy(api_resource_pool_infra_policies_url(nil, rpi), :resource_pool_infras, :policies) + end + + it "unassign Resource Pool Infra policy with invalid guid" do + test_policy_unassign_invalid_policy_guid(api_resource_pool_infra_url(nil, rpi), api_resource_pool_infra_policies_url(nil, rpi), :resource_pool_infras, :policies) + end + + it "unassign Resource Pool Infra multiple policies" do + test_unassign_multiple_policies(api_resource_pool_infra_policies_url(nil, rpi), :resource_pool_infras, :policies, :object => rpi) + end + end + + context "Resource Pool Infra policy profiles subcollection assignments" do + it "assign Resource Pool Infra policy profile without approriate role" do + test_policy_assign_no_role(api_resource_pool_infra_policy_profiles_url(nil, rpi)) + end + + it "assign Resource Pool Infra policy profile with invalid href" do + test_policy_assign_invalid_policy(api_resource_pool_infra_policy_profiles_url(nil, rpi), :resource_pool_infras, :policy_profiles) + end + + it "assign Resource Pool Infra policy profile with invalid guid" do + test_policy_assign_invalid_policy_guid(api_resource_pool_infra_url(nil, rpi), api_resource_pool_infra_policy_profiles_url(nil, rpi), :resource_pool_infras, :policy_profiles) + end + + it "assign Resource Pool Infra multiple policy profiles" do + test_assign_multiple_policies(api_resource_pool_infra_url(nil, rpi), + api_resource_pool_infra_policy_profiles_url(nil, rpi), + :resource_pool_infras, + :policy_profiles, + :object => rpi, + :policies => [ps1, ps2]) + end + + it "unassign Resource Pool Infra policy profile without approriate role" do + test_policy_unassign_no_role(api_resource_pool_infra_policy_profiles_url(nil, rpi)) + end + + it "unassign Resource Pool Infra policy profile with invalid href" do + test_policy_unassign_invalid_policy(api_resource_pool_infra_policy_profiles_url(nil, rpi), :resource_pool_infras, :policy_profiles) + end + + it "unassign Resource Pool Infra policy profile with invalid guid" do + test_policy_unassign_invalid_policy_guid(api_resource_pool_infra_url(nil, rpi), + api_resource_pool_infra_policy_profiles_url(nil, rpi), + :resource_pool_infras, + :policy_profiles) + end + + it "unassign Resource Pool Infra multiple policy profiles" do + test_unassign_multiple_policy_profiles(api_resource_pool_infra_policy_profiles_url(nil, rpi), + :resource_pool_infras, + :policy_profiles, + :object => rpi) end end diff --git a/spec/requests/policies_spec.rb b/spec/requests/policies_spec.rb index d80dfe046a..6f6e7b0d82 100644 --- a/spec/requests/policies_spec.rb +++ b/spec/requests/policies_spec.rb @@ -9,7 +9,8 @@ # /api/vms/:id/policies # /api/providers/:id/policies # /api/hosts/:id/policies -# /api/resource_pools/:id/policies +# /api/resource_pool_clouds/:id/policies +# /api/resource_pool_infras/:id/policies # /api/clusters/:id/policies # /api/templates/:id/policies # /api/policy_profiles/:id/policies @@ -18,7 +19,8 @@ # /api/vms/:id/policy_profiles # /api/providers/:id/policy_profiles # /api/hosts/:id/policy_profiles -# /api/resource_pools/:id/policy_profiles +# /api/resource_pool_clouds/:id/policy_profiles +# /api/resource_pool_infras/:id/policy_profiles # /api/clusters/:id/policy_profiles # /api/templates/:id/policy_profiles # @@ -334,27 +336,51 @@ def test_policy_profile_policies_query(object, api_object_policy_profiles_url) end end - context "Resource Pool policies subcollection" do - let(:rp) { FactoryBot.create(:resource_pool, :name => "Resource Pool 1") } + context "Resource Pool Cloud policies subcollection" do + let(:rp) { FactoryBot.create(:resource_pool, :name => "Resource Pool 1", :type => ManageIQ::Providers::CloudManager::ResourcePool) } - it "query Resource Pool policies with no policies defined" do - test_no_policy_query(api_resource_pool_policies_url(nil, rp)) + it "query Resource Pool Cloud policies with no policies defined" do + test_no_policy_query(api_resource_pool_cloud_policies_url(nil, rp)) end - it "query Resource Pool policy profiles with no policy profiles defined" do - test_no_policy_profile_query(api_resource_pool_policy_profiles_url(nil, rp)) + it "query Resource Pool Cloud policy profiles with no policy profiles defined" do + test_no_policy_profile_query(api_resource_pool_cloud_policy_profiles_url(nil, rp)) end - it "query Resource Pool policies with one policy defined" do - test_single_policy_query(rp, api_resource_pool_policies_url(nil, rp)) + it "query Resource Pool Cloud policies with one policy defined" do + test_single_policy_query(rp, api_resource_pool_cloud_policies_url(nil, rp)) end - it "query Resource Pool policies with multiple policies defined" do - test_multiple_policy_query(rp, api_resource_pool_policies_url(nil, rp)) + it "query Resource Pool Cloud policies with multiple policies defined" do + test_multiple_policy_query(rp, api_resource_pool_cloud_policies_url(nil, rp)) end - it "query Resource Pool policy profiles" do - test_policy_profile_query(rp, api_resource_pool_policy_profiles_url(nil, rp)) + it "query Resource Pool Cloud policy profiles" do + test_policy_profile_query(rp, api_resource_pool_cloud_policy_profiles_url(nil, rp)) + end + end + + context "Resource Pool Infra policies subcollection" do + let(:rp) { FactoryBot.create(:resource_pool, :name => "Resource Pool 1", :type => ManageIQ::Providers::InfraManager::ResourcePool) } + + it "query Resource Pool Infra policies with no policies defined" do + test_no_policy_query(api_resource_pool_infra_policies_url(nil, rp)) + end + + it "query Resource Pool Infra policy profiles with no policy profiles defined" do + test_no_policy_profile_query(api_resource_pool_infra_policy_profiles_url(nil, rp)) + end + + it "query Resource Pool Infra policies with one policy defined" do + test_single_policy_query(rp, api_resource_pool_infra_policies_url(nil, rp)) + end + + it "query Resource Pool Infra policies with multiple policies defined" do + test_multiple_policy_query(rp, api_resource_pool_infra_policies_url(nil, rp)) + end + + it "query Resource Pool Infra policy profiles" do + test_policy_profile_query(rp, api_resource_pool_infra_policy_profiles_url(nil, rp)) end end diff --git a/spec/requests/tag_collections_spec.rb b/spec/requests/tag_collections_spec.rb index 3dbd961c28..821a8f19e9 100644 --- a/spec/requests/tag_collections_spec.rb +++ b/spec/requests/tag_collections_spec.rb @@ -412,50 +412,98 @@ def expect_resource_has_tags(resource, tag_names) end end - context "Resource Pool Tag subcollection" do - let(:rp) { FactoryBot.create(:resource_pool, :name => "Resource Pool 1") } - - it "query all tags of a Resource Pool and verify tag category and names" do + context "Resource Pool Cloud Tag subcollection" do + let(:rp) { FactoryBot.create(:resource_pool, :name => "Resource Pool 1", :type => "ManageIQ::Providers::CloudManager::ResourcePool") } + + it "queries all tags of a Resource Pool Cloud and verifies tag category and names" do api_basic_authorize classify_resource(rp) - get api_resource_pool_tags_url(nil, rp), :params => { :expand => "resources" } + get api_resource_pool_cloud_tags_url(nil, rp), :params => { :expand => "resources" } expect_query_result(:tags, 2, Tag.count) expect_result_resources_to_include_data("resources", "name" => tag_paths) end - it "does not assign a tag to a Resource Pool without appropriate role" do + it "does not assign a tag to a Resource Pool Cloud without appropriate role" do api_basic_authorize - post(api_resource_pool_tags_url(nil, rp), :params => gen_request(:assign, :category => tag1[:category], :name => tag1[:name])) - + post(api_resource_pool_cloud_tags_url(nil, rp), :params => gen_request(:assign, :category => tag1[:category], :name => tag1[:name])) + expect(response).to have_http_status(:forbidden) end - - it "assigns a tag to a Resource Pool" do - api_basic_authorize subcollection_action_identifier(:resource_pools, :tags, :assign) - - post(api_resource_pool_tags_url(nil, rp), :params => gen_request(:assign, :category => tag1[:category], :name => tag1[:name])) - - expect_tagging_result(tag1_results(api_resource_pool_url(nil, rp))) + + it "assigns a tag to a Resource Pool Cloud" do + api_basic_authorize subcollection_action_identifier(:resource_pool_clouds, :tags, :assign) + + post(api_resource_pool_cloud_tags_url(nil, rp), :params => gen_request(:assign, :category => tag1[:category], :name => tag1[:name])) + + expect_tagging_result(tag1_results(api_resource_pool_cloud_url(nil, rp))) end - - it "does not unassign a tag from a Resource Pool without appropriate role" do + + it "does not unassign a tag from a Resource Pool Cloud without appropriate role" do + api_basic_authorize + + post(api_resource_pool_cloud_tags_url(nil, rp), :params => gen_request(:unassign, :category => tag1[:category], :name => tag1[:name])) + + expect(response).to have_http_status(:forbidden) + end + + it "unassigns a tag from a Resource Pool Cloud" do + api_basic_authorize subcollection_action_identifier(:resource_pool_clouds, :tags, :unassign) + classify_resource(rp) + + post(api_resource_pool_cloud_tags_url(nil, rp), :params => gen_request(:unassign, :category => tag1[:category], :name => tag1[:name])) + + expect_tagging_result(tag1_results(api_resource_pool_cloud_url(nil, rp))) + expect_resource_has_tags(rp, tag2[:path]) + end + end + + context "Resource Pool Infra Tag subcollection" do + let(:rp) { FactoryBot.create(:resource_pool, :name => "Resource Pool 1", :type => "ManageIQ::Providers::InfraManager::ResourcePool") } + + it "queries all tags of a Resource Pool Infra and verifies tag category and names" do api_basic_authorize + classify_resource(rp) + + get api_resource_pool_infra_tags_url(nil, rp), :params => { :expand => "resources" } + + expect_query_result(:tags, 2, Tag.count) + expect_result_resources_to_include_data("resources", "name" => tag_paths) + end - post(api_resource_pool_tags_url(nil, rp), :params => gen_request(:unassign, :category => tag1[:category], :name => tag1[:name])) + it "does not assign a tag to a Resource Pool Infra without appropriate role" do + api_basic_authorize + post(api_resource_pool_infra_tags_url(nil, rp), :params => gen_request(:assign, :category => tag1[:category], :name => tag1[:name])) + expect(response).to have_http_status(:forbidden) end + + it "assigns a tag to a Resource Pool Infra" do + api_basic_authorize subcollection_action_identifier(:resource_pool_infras, :tags, :assign) + + post(api_resource_pool_infra_tags_url(nil, rp), :params => gen_request(:assign, :category => tag1[:category], :name => tag1[:name])) + + expect_tagging_result(tag1_results(api_resource_pool_infra_url(nil, rp))) + end - it "unassigns a tag from a Resource Pool" do - api_basic_authorize subcollection_action_identifier(:resource_pools, :tags, :unassign) + it "does not unassign a tag from a Resource Pool Infra without appropriate role" do + api_basic_authorize + + post(api_resource_pool_infra_tags_url(nil, rp), :params => gen_request(:unassign, :category => tag1[:category], :name => tag1[:name])) + + expect(response).to have_http_status(:forbidden) + end + + it "unassigns a tag from a Resource Pool Infra" do + api_basic_authorize subcollection_action_identifier(:resource_pool_infras, :tags, :unassign) classify_resource(rp) - - post(api_resource_pool_tags_url(nil, rp), :params => gen_request(:unassign, :category => tag1[:category], :name => tag1[:name])) - - expect_tagging_result(tag1_results(api_resource_pool_url(nil, rp))) + + post(api_resource_pool_infra_tags_url(nil, rp), :params => gen_request(:unassign, :category => tag1[:category], :name => tag1[:name])) + + expect_tagging_result(tag1_results(api_resource_pool_infra_url(nil, rp))) expect_resource_has_tags(rp, tag2[:path]) end end