Merge "Migrate to override_role for compute module (part 1)"
diff --git a/patrole_tempest_plugin/tests/api/compute/test_agents_rbac.py b/patrole_tempest_plugin/tests/api/compute/test_agents_rbac.py
index cbe8d01..a046f96 100644
--- a/patrole_tempest_plugin/tests/api/compute/test_agents_rbac.py
+++ b/patrole_tempest_plugin/tests/api/compute/test_agents_rbac.py
@@ -45,8 +45,8 @@
service="nova", rule="os_compute_api:os-agents")
@decorators.idempotent_id('d1bc6d97-07f5-4f45-ac29-1c619a6a7e27')
def test_list_agents_rbac(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.agents_client.list_agents()
+ with self.rbac_utils.override_role(self):
+ self.agents_client.list_agents()
@rbac_rule_validation.action(
service="nova",
@@ -56,8 +56,8 @@
params = {'hypervisor': 'kvm', 'os': 'win', 'architecture': 'x86',
'version': '7.0', 'url': 'xxx://xxxx/xxx/xxx',
'md5hash': 'add6bb58e139be103324d04d82d8f545'}
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- body = self.agents_client.create_agent(**params)['agent']
+ with self.rbac_utils.override_role(self):
+ body = self.agents_client.create_agent(**params)['agent']
self.addCleanup(self.agents_client.delete_agent,
body['agent_id'])
@@ -74,13 +74,13 @@
body = self.agents_client.create_agent(**params)['agent']
self.addCleanup(self.agents_client.delete_agent,
body['agent_id'])
-
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
update_params = self._param_helper(
version='8.0',
url='xxx://xxxx/xxx/xxx2',
md5hash='add6bb58e139be103324d04d82d8f547')
- self.agents_client.update_agent(body['agent_id'], **update_params)
+
+ with self.rbac_utils.override_role(self):
+ self.agents_client.update_agent(body['agent_id'], **update_params)
@rbac_rule_validation.action(
service="nova",
@@ -96,5 +96,5 @@
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
self.agents_client.delete_agent,
body['agent_id'])
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.agents_client.delete_agent(body['agent_id'])
+ with self.rbac_utils.override_role(self):
+ self.agents_client.delete_agent(body['agent_id'])
diff --git a/patrole_tempest_plugin/tests/api/compute/test_aggregates_rbac.py b/patrole_tempest_plugin/tests/api/compute/test_aggregates_rbac.py
index 261fded..12ac058 100644
--- a/patrole_tempest_plugin/tests/api/compute/test_aggregates_rbac.py
+++ b/patrole_tempest_plugin/tests/api/compute/test_aggregates_rbac.py
@@ -58,48 +58,49 @@
service="nova", rule="os_compute_api:os-aggregates:create")
@decorators.idempotent_id('ba754393-896e-434a-9704-452ff4a84f3f')
def test_create_aggregate_rbac(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self._create_aggregate()
+ with self.rbac_utils.override_role(self):
+ self._create_aggregate()
@rbac_rule_validation.action(
service="nova", rule="os_compute_api:os-aggregates:show")
@decorators.idempotent_id('8fb0b749-b120-4727-b3fb-bcfa3fa6f55b')
def test_show_aggregate_rbac(self):
aggregate_id = self._create_aggregate()
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.aggregates_client.show_aggregate(aggregate_id)
+ with self.rbac_utils.override_role(self):
+ self.aggregates_client.show_aggregate(aggregate_id)
@rbac_rule_validation.action(
service="nova", rule="os_compute_api:os-aggregates:index")
@decorators.idempotent_id('146284da-5dd6-4c97-b598-42b480f014c6')
def test_list_aggregate_rbac(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.aggregates_client.list_aggregates()['aggregates']
+ with self.rbac_utils.override_role(self):
+ self.aggregates_client.list_aggregates()
@rbac_rule_validation.action(
service="nova", rule="os_compute_api:os-aggregates:update")
@decorators.idempotent_id('c94e0d69-99b6-477e-b301-2cd0e9d0ad81')
def test_update_aggregate_rbac(self):
aggregate_id = self._create_aggregate()
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
new_name = data_utils.rand_name(self.__class__.__name__ + '-aggregate')
- self.aggregates_client.update_aggregate(aggregate_id, name=new_name)
+ with self.rbac_utils.override_role(self):
+ self.aggregates_client.update_aggregate(aggregate_id,
+ name=new_name)
@rbac_rule_validation.action(
service="nova", rule="os_compute_api:os-aggregates:delete")
@decorators.idempotent_id('5a50c5a6-0f12-4405-a1ce-2288ae895ea6')
def test_delete_aggregate_rbac(self):
aggregate_id = self._create_aggregate()
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.aggregates_client.delete_aggregate(aggregate_id)
+ with self.rbac_utils.override_role(self):
+ self.aggregates_client.delete_aggregate(aggregate_id)
@rbac_rule_validation.action(
service="nova", rule="os_compute_api:os-aggregates:add_host")
@decorators.idempotent_id('97e6e9df-5291-4faa-8147-755b2d1f1ce2')
def test_add_host_to_aggregate_rbac(self):
aggregate_id = self._create_aggregate()
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self._add_host_to_aggregate(aggregate_id)
+ with self.rbac_utils.override_role(self):
+ self._add_host_to_aggregate(aggregate_id)
@rbac_rule_validation.action(
service="nova", rule="os_compute_api:os-aggregates:remove_host")
@@ -107,8 +108,8 @@
def test_remove_host_from_aggregate_rbac(self):
aggregate_id = self._create_aggregate()
host_name = self._add_host_to_aggregate(aggregate_id)
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.aggregates_client.remove_host(aggregate_id, host=host_name)
+ with self.rbac_utils.override_role(self):
+ self.aggregates_client.remove_host(aggregate_id, host=host_name)
@rbac_rule_validation.action(
service="nova", rule="os_compute_api:os-aggregates:set_metadata")
@@ -117,7 +118,7 @@
aggregate_id = self._create_aggregate()
rand_key = data_utils.rand_name(self.__class__.__name__ + '-key')
rand_val = data_utils.rand_name(self.__class__.__name__ + '-val')
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.aggregates_client.set_metadata(
- aggregate_id,
- metadata={rand_key: rand_val})
+ with self.rbac_utils.override_role(self):
+ self.aggregates_client.set_metadata(
+ aggregate_id,
+ metadata={rand_key: rand_val})
diff --git a/patrole_tempest_plugin/tests/api/compute/test_availability_zone_rbac.py b/patrole_tempest_plugin/tests/api/compute/test_availability_zone_rbac.py
index 2a8a6ae..66dce5c 100644
--- a/patrole_tempest_plugin/tests/api/compute/test_availability_zone_rbac.py
+++ b/patrole_tempest_plugin/tests/api/compute/test_availability_zone_rbac.py
@@ -32,12 +32,12 @@
"os-availability-zone:list")
@decorators.idempotent_id('cd34e7ea-d26e-4fa3-a8d0-f8883726ce3d')
def test_get_availability_zone_list_rbac(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.availability_zone_client.list_availability_zones()
+ with self.rbac_utils.override_role(self):
+ self.availability_zone_client.list_availability_zones()
@rbac_rule_validation.action(service="nova", rule="os_compute_api:"
"os-availability-zone:detail")
@decorators.idempotent_id('2f61c191-6ece-4f21-b487-39d749e3d38e')
def test_get_availability_zone_list_detail_rbac(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.availability_zone_client.list_availability_zones(detail=True)
+ with self.rbac_utils.override_role(self):
+ self.availability_zone_client.list_availability_zones(detail=True)
diff --git a/patrole_tempest_plugin/tests/api/compute/test_fixed_ips_rbac.py b/patrole_tempest_plugin/tests/api/compute/test_fixed_ips_rbac.py
index dd32187..f426cf3 100644
--- a/patrole_tempest_plugin/tests/api/compute/test_fixed_ips_rbac.py
+++ b/patrole_tempest_plugin/tests/api/compute/test_fixed_ips_rbac.py
@@ -58,21 +58,21 @@
service="nova",
rule="os_compute_api:os-fixed-ips")
def test_show_fixed_ip_details(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.fixed_ips_client.show_fixed_ip(self.ip)
+ with self.rbac_utils.override_role(self):
+ self.fixed_ips_client.show_fixed_ip(self.ip)
@decorators.idempotent_id('f0314501-735d-4315-9856-959e01e82f0d')
@rbac_rule_validation.action(
service="nova",
rule="os_compute_api:os-fixed-ips")
def test_set_reserve(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.fixed_ips_client.reserve_fixed_ip(self.ip, reserve="None")
+ with self.rbac_utils.override_role(self):
+ self.fixed_ips_client.reserve_fixed_ip(self.ip, reserve="None")
@decorators.idempotent_id('866a6fdc-a237-4502-9bf2-52fe82aba356')
@rbac_rule_validation.action(
service="nova",
rule="os_compute_api:os-fixed-ips")
def test_set_unreserve(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.fixed_ips_client.reserve_fixed_ip(self.ip, unreserve="None")
+ with self.rbac_utils.override_role(self):
+ self.fixed_ips_client.reserve_fixed_ip(self.ip, unreserve="None")
diff --git a/patrole_tempest_plugin/tests/api/compute/test_flavor_access_rbac.py b/patrole_tempest_plugin/tests/api/compute/test_flavor_access_rbac.py
index 7503962..976f18c 100644
--- a/patrole_tempest_plugin/tests/api/compute/test_flavor_access_rbac.py
+++ b/patrole_tempest_plugin/tests/api/compute/test_flavor_access_rbac.py
@@ -41,9 +41,9 @@
def test_show_flavor_contains_is_public_key(self):
public_flavor_id = CONF.compute.flavor_ref
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- body = self.flavors_client.show_flavor(public_flavor_id)[
- 'flavor']
+ with self.rbac_utils.override_role(self):
+ body = self.flavors_client.show_flavor(public_flavor_id)[
+ 'flavor']
expected_attr = 'os-flavor-access:is_public'
if expected_attr not in body:
@@ -57,8 +57,8 @@
def test_list_flavors_details_contains_is_public_key(self):
expected_attr = 'os-flavor-access:is_public'
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- flavors = self.flavors_client.list_flavors(detail=True)['flavors']
+ with self.rbac_utils.override_role(self):
+ flavors = self.flavors_client.list_flavors(detail=True)['flavors']
# There should already be a public flavor available, namely
# `CONF.compute.flavor_ref`.
public_flavors = [f for f in flavors if expected_attr in f]
@@ -74,10 +74,9 @@
service="nova",
rule="os_compute_api:os-flavor-access:add_tenant_access")
def test_add_flavor_access(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.flavors_client.add_flavor_access(
- flavor_id=self.flavor_id, tenant_id=self.tenant_id)[
- 'flavor_access']
+ with self.rbac_utils.override_role(self):
+ self.flavors_client.add_flavor_access(
+ flavor_id=self.flavor_id, tenant_id=self.tenant_id)
self.addCleanup(self.flavors_client.remove_flavor_access,
flavor_id=self.flavor_id, tenant_id=self.tenant_id)
@@ -92,9 +91,9 @@
self.flavors_client.remove_flavor_access,
flavor_id=self.flavor_id, tenant_id=self.tenant_id)
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.flavors_client.remove_flavor_access(
- flavor_id=self.flavor_id, tenant_id=self.tenant_id)
+ with self.rbac_utils.override_role(self):
+ self.flavors_client.remove_flavor_access(
+ flavor_id=self.flavor_id, tenant_id=self.tenant_id)
@decorators.idempotent_id('e1cf59fb-7f32-40a1-96b9-248ab23dd581')
@rbac_rule_validation.action(
@@ -104,10 +103,9 @@
# Add flavor access for os_primary so that it can access the flavor or
# else a NotFound is raised.
self.flavors_client.add_flavor_access(
- flavor_id=self.flavor_id, tenant_id=self.tenant_id)[
- 'flavor_access']
+ flavor_id=self.flavor_id, tenant_id=self.tenant_id)
self.addCleanup(self.flavors_client.remove_flavor_access,
flavor_id=self.flavor_id, tenant_id=self.tenant_id)
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.flavors_client.list_flavor_access(self.flavor_id)
+ with self.rbac_utils.override_role(self):
+ self.flavors_client.list_flavor_access(self.flavor_id)
diff --git a/patrole_tempest_plugin/tests/api/compute/test_flavor_extra_specs_rbac.py b/patrole_tempest_plugin/tests/api/compute/test_flavor_extra_specs_rbac.py
index 2d60e09..816492c 100644
--- a/patrole_tempest_plugin/tests/api/compute/test_flavor_extra_specs_rbac.py
+++ b/patrole_tempest_plugin/tests/api/compute/test_flavor_extra_specs_rbac.py
@@ -53,16 +53,16 @@
rule="os_compute_api:os-flavor-extra-specs:show")
def test_show_flavor_extra_spec(self):
key = self._set_flavor_extra_spec()
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.flavors_client.show_flavor_extra_spec(self.flavor['id'], key)[key]
+ with self.rbac_utils.override_role(self):
+ self.flavors_client.show_flavor_extra_spec(self.flavor['id'], key)
@decorators.idempotent_id('fcffeca2-ed04-4e85-bf93-02fb5643f22b')
@rbac_rule_validation.action(
service="nova",
rule="os_compute_api:os-flavor-extra-specs:create")
def test_set_flavor_extra_spec(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self._set_flavor_extra_spec()
+ with self.rbac_utils.override_role(self):
+ self._set_flavor_extra_spec()
@decorators.idempotent_id('42b85279-6bfa-4f58-b7a2-258c284f03c5')
@rbac_rule_validation.action(
@@ -70,10 +70,10 @@
rule="os_compute_api:os-flavor-extra-specs:update")
def test_update_flavor_extra_spec(self):
key = self._set_flavor_extra_spec()
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
update_val = data_utils.rand_name(self.__class__.__name__ + '-val')
- self.flavors_client.update_flavor_extra_spec(
- self.flavor['id'], key, **{key: update_val})[key]
+ with self.rbac_utils.override_role(self):
+ self.flavors_client.update_flavor_extra_spec(
+ self.flavor['id'], key, **{key: update_val})
@decorators.idempotent_id('4b0e5471-e010-4c09-8965-80898e6760a3')
@rbac_rule_validation.action(
@@ -81,8 +81,8 @@
rule="os_compute_api:os-flavor-extra-specs:delete")
def test_unset_flavor_extra_spec(self):
key = self._set_flavor_extra_spec()
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.flavors_client.unset_flavor_extra_spec(self.flavor['id'], key)
+ with self.rbac_utils.override_role(self):
+ self.flavors_client.unset_flavor_extra_spec(self.flavor['id'], key)
@decorators.idempotent_id('02c3831a-3ce9-476e-a722-d805ac2da621')
@rbac_rule_validation.action(
@@ -90,6 +90,5 @@
rule="os_compute_api:os-flavor-extra-specs:index")
def test_list_flavor_extra_specs(self):
self._set_flavor_extra_spec()
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.flavors_client.list_flavor_extra_specs(
- self.flavor['id'])['extra_specs']
+ with self.rbac_utils.override_role(self):
+ self.flavors_client.list_flavor_extra_specs(self.flavor['id'])
diff --git a/patrole_tempest_plugin/tests/api/compute/test_flavor_manage_rbac.py b/patrole_tempest_plugin/tests/api/compute/test_flavor_manage_rbac.py
index afe5013..f0f267c 100644
--- a/patrole_tempest_plugin/tests/api/compute/test_flavor_manage_rbac.py
+++ b/patrole_tempest_plugin/tests/api/compute/test_flavor_manage_rbac.py
@@ -22,10 +22,6 @@
class FlavorManageRbacTest(rbac_base.BaseV2ComputeRbacTest):
- # Need admin to wait for resource deletion below to avoid test role
- # having to pass extra policies.
- credentials = ['primary', 'admin']
-
@classmethod
def skip_checks(cls):
super(FlavorManageRbacTest, cls).skip_checks()
@@ -38,8 +34,8 @@
service="nova",
rule="os_compute_api:os-flavor-manage:create")
def test_create_flavor_manage(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.create_flavor()
+ with self.rbac_utils.override_role(self):
+ self.create_flavor()
@decorators.idempotent_id('782e988e-061b-4c40-896f-a77c70c2b057')
@rbac_rule_validation.action(
@@ -48,6 +44,6 @@
def test_delete_flavor_manage(self):
flavor_id = self.create_flavor()['id']
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.flavors_client.delete_flavor(flavor_id)
- self.os_admin.flavors_client.wait_for_resource_deletion(flavor_id)
+ with self.rbac_utils.override_role(self):
+ self.flavors_client.delete_flavor(flavor_id)
+ self.flavors_client.wait_for_resource_deletion(flavor_id)
diff --git a/patrole_tempest_plugin/tests/api/compute/test_flavor_rxtx_rbac.py b/patrole_tempest_plugin/tests/api/compute/test_flavor_rxtx_rbac.py
index b530cbf..fbc03cf 100644
--- a/patrole_tempest_plugin/tests/api/compute/test_flavor_rxtx_rbac.py
+++ b/patrole_tempest_plugin/tests/api/compute/test_flavor_rxtx_rbac.py
@@ -38,8 +38,8 @@
service="nova",
rule="os_compute_api:os-flavor-rxtx")
def test_list_flavors_details_rxtx(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- result = self.flavors_client.list_flavors(detail=True)['flavors']
+ with self.rbac_utils.override_role(self):
+ result = self.flavors_client.list_flavors(detail=True)['flavors']
if 'rxtx_factor' not in result[0]:
raise rbac_exceptions.RbacMalformedResponse(
attribute='rxtx_factor')
@@ -49,9 +49,9 @@
service="nova",
rule="os_compute_api:os-flavor-rxtx")
def test_get_flavor_rxtx(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- result = self.flavors_client.show_flavor(
- CONF.compute.flavor_ref)['flavor']
+ with self.rbac_utils.override_role(self):
+ result = self.flavors_client.show_flavor(
+ CONF.compute.flavor_ref)['flavor']
if 'rxtx_factor' not in result:
raise rbac_exceptions.RbacMalformedResponse(
attribute='rxtx_factor')
diff --git a/patrole_tempest_plugin/tests/api/compute/test_floating_ip_pools_rbac.py b/patrole_tempest_plugin/tests/api/compute/test_floating_ip_pools_rbac.py
index 15891d7..7467130 100644
--- a/patrole_tempest_plugin/tests/api/compute/test_floating_ip_pools_rbac.py
+++ b/patrole_tempest_plugin/tests/api/compute/test_floating_ip_pools_rbac.py
@@ -50,5 +50,5 @@
service="nova",
rule="os_compute_api:os-floating-ip-pools")
def test_list_floating_ip_pools(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.fip_pools_client.list_floating_ip_pools()['floating_ip_pools']
+ with self.rbac_utils.override_role(self):
+ self.fip_pools_client.list_floating_ip_pools()
diff --git a/patrole_tempest_plugin/tests/api/compute/test_floating_ips_bulk_rbac.py b/patrole_tempest_plugin/tests/api/compute/test_floating_ips_bulk_rbac.py
index e149bf2..18a2196 100644
--- a/patrole_tempest_plugin/tests/api/compute/test_floating_ips_bulk_rbac.py
+++ b/patrole_tempest_plugin/tests/api/compute/test_floating_ips_bulk_rbac.py
@@ -50,5 +50,5 @@
service="nova",
rule="os_compute_api:os-floating-ips-bulk")
def test_list_floating_ips_bulk(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.fip_bulk_client.list_floating_ips_bulk()['floating_ip_info']
+ with self.rbac_utils.override_role(self):
+ self.fip_bulk_client.list_floating_ips_bulk()
diff --git a/patrole_tempest_plugin/tests/api/compute/test_floating_ips_rbac.py b/patrole_tempest_plugin/tests/api/compute/test_floating_ips_rbac.py
index 8ab5a51..1045512 100644
--- a/patrole_tempest_plugin/tests/api/compute/test_floating_ips_rbac.py
+++ b/patrole_tempest_plugin/tests/api/compute/test_floating_ips_rbac.py
@@ -46,8 +46,8 @@
service="nova",
rule="os_compute_api:os-floating-ips")
def test_list_floating_ips(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.floating_ips_client.list_floating_ips()['floating_ips']
+ with self.rbac_utils.override_role(self):
+ self.floating_ips_client.list_floating_ips()
@decorators.idempotent_id('bebe52b3-5269-4e72-80c8-5a4a39c3bfa6')
@rbac_rule_validation.action(
@@ -58,17 +58,17 @@
pool=CONF.network.floating_network_name)['floating_ip']
self.addCleanup(
self.floating_ips_client.delete_floating_ip, body['id'])
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.floating_ips_client.show_floating_ip(body['id'])['floating_ip']
+ with self.rbac_utils.override_role(self):
+ self.floating_ips_client.show_floating_ip(body['id'])
@decorators.idempotent_id('2bfb8745-c329-4ee9-95f6-c165a1989dbf')
@rbac_rule_validation.action(
service="nova",
rule="os_compute_api:os-floating-ips")
def test_create_floating_ips(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- body = self.floating_ips_client.create_floating_ip(
- pool=CONF.network.floating_network_name)['floating_ip']
+ with self.rbac_utils.override_role(self):
+ body = self.floating_ips_client.create_floating_ip(
+ pool=CONF.network.floating_network_name)['floating_ip']
self.addCleanup(
self.floating_ips_client.delete_floating_ip, body['id'])
@@ -82,5 +82,5 @@
self.addCleanup(
test_utils.call_and_ignore_notfound_exc,
self.floating_ips_client.delete_floating_ip, body['id'])
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.floating_ips_client.delete_floating_ip(body['id'])
+ with self.rbac_utils.override_role(self):
+ self.floating_ips_client.delete_floating_ip(body['id'])