Merge "Migrate to override_role for volume module (part 4)"
diff --git a/patrole_tempest_plugin/tests/api/network/test_metering_label_rules_rbac.py b/patrole_tempest_plugin/tests/api/network/test_metering_label_rules_rbac.py
index 5ffc966..7a9d814 100644
--- a/patrole_tempest_plugin/tests/api/network/test_metering_label_rules_rbac.py
+++ b/patrole_tempest_plugin/tests/api/network/test_metering_label_rules_rbac.py
@@ -70,8 +70,8 @@
RBAC test for the neutron create_metering_label_rule policy
"""
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self._create_metering_label_rule(self.label)
+ with self.rbac_utils.override_role(self):
+ self._create_metering_label_rule(self.label)
@rbac_rule_validation.action(service="neutron",
rule="get_metering_label_rule",
@@ -83,9 +83,9 @@
RBAC test for the neutron get_metering_label_rule policy
"""
label_rule = self._create_metering_label_rule(self.label)
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.metering_label_rules_client.show_metering_label_rule(
- label_rule['id'])
+ with self.rbac_utils.override_role(self):
+ self.metering_label_rules_client.show_metering_label_rule(
+ label_rule['id'])
@rbac_rule_validation.action(service="neutron",
rule="delete_metering_label_rule",
@@ -97,6 +97,6 @@
RBAC test for the neutron delete_metering_label_rule policy
"""
label_rule = self._create_metering_label_rule(self.label)
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.metering_label_rules_client.delete_metering_label_rule(
- label_rule['id'])
+ with self.rbac_utils.override_role(self):
+ self.metering_label_rules_client.delete_metering_label_rule(
+ label_rule['id'])
diff --git a/patrole_tempest_plugin/tests/api/volume/test_limits_rbac.py b/patrole_tempest_plugin/tests/api/volume/test_limits_rbac.py
index fa92cad..976d756 100644
--- a/patrole_tempest_plugin/tests/api/volume/test_limits_rbac.py
+++ b/patrole_tempest_plugin/tests/api/volume/test_limits_rbac.py
@@ -26,5 +26,5 @@
@rbac_rule_validation.action(service="cinder",
rule="limits_extension:used_limits")
def test_show_limits(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.volume_limits_client.show_limits()
+ with self.rbac_utils.override_role(self):
+ self.volume_limits_client.show_limits()
diff --git a/patrole_tempest_plugin/tests/api/volume/test_qos_rbac.py b/patrole_tempest_plugin/tests/api/volume/test_qos_rbac.py
index adfd397..a62bbda 100644
--- a/patrole_tempest_plugin/tests/api/volume/test_qos_rbac.py
+++ b/patrole_tempest_plugin/tests/api/volume/test_qos_rbac.py
@@ -23,13 +23,11 @@
class VolumeQOSV3RbacTest(rbac_base.BaseVolumeRbacTest):
- credentials = ['primary', 'admin']
@classmethod
def setup_clients(cls):
super(VolumeQOSV3RbacTest, cls).setup_clients()
cls.qos_client = cls.os_primary.volume_qos_v2_client
- cls.admin_qos_client = cls.os_admin.volume_qos_v2_client
def _create_test_qos_specs(self, name=None, consumer=None, **kwargs):
name = name or data_utils.rand_name(self.__class__.__name__ + '-QoS')
@@ -44,24 +42,24 @@
service="cinder", rule="volume_extension:qos_specs_manage:create")
@decorators.idempotent_id('4f9f45f0-b379-4577-a279-cec3e917cbec')
def test_create_qos_with_consumer(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self._create_test_qos_specs()
+ with self.rbac_utils.override_role(self):
+ self._create_test_qos_specs()
@rbac_rule_validation.action(
service="cinder", rule="volume_extension:qos_specs_manage:delete")
@decorators.idempotent_id('fbc8a77e-6b6d-45ae-bebe-c496eb8f06f7')
def test_delete_qos_with_consumer(self):
qos = self._create_test_qos_specs()
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.qos_client.delete_qos(qos['id'])
+ with self.rbac_utils.override_role(self):
+ self.qos_client.delete_qos(qos['id'])
@rbac_rule_validation.action(service="cinder",
rule="volume_extension:qos_specs_manage:get")
@decorators.idempotent_id('22aff0dd-0343-408d-ae80-e77551956e14')
def test_show_qos(self):
qos = self._create_test_qos_specs()
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.qos_client.show_qos(qos['id'])['qos_specs']
+ with self.rbac_utils.override_role(self):
+ self.qos_client.show_qos(qos['id'])['qos_specs']
@rbac_rule_validation.action(service="cinder",
rule="volume_extension:"
@@ -73,24 +71,25 @@
self.qos_client.associate_qos(qos['id'], vol_type)
self.addCleanup(self.qos_client.disassociate_qos, qos['id'], vol_type)
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.qos_client.show_association_qos(qos['id'])
+ with self.rbac_utils.override_role(self):
+ self.qos_client.show_association_qos(qos['id'])
@rbac_rule_validation.action(
service="cinder",
rule="volume_extension:qos_specs_manage:get_all")
@decorators.idempotent_id('546b8bb1-04a4-4387-9506-a538a7f3cd6a')
def test_list_qos(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.qos_client.list_qos()['qos_specs']
+ with self.rbac_utils.override_role(self):
+ self.qos_client.list_qos()['qos_specs']
@rbac_rule_validation.action(
service="cinder", rule="volume_extension:qos_specs_manage:update")
@decorators.idempotent_id('89b630b7-c170-47c3-ac80-50ed425c2d98')
def test_set_qos_key(self):
qos = self._create_test_qos_specs()
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.qos_client.set_qos_key(qos['id'], iops_bytes='500')['qos_specs']
+ with self.rbac_utils.override_role(self):
+ self.qos_client.set_qos_key(
+ qos['id'], iops_bytes='500')['qos_specs']
@rbac_rule_validation.action(
service="cinder", rule="volume_extension:qos_specs_manage:update")
@@ -99,9 +98,9 @@
qos = self._create_test_qos_specs()
self.qos_client.set_qos_key(qos['id'], iops_bytes='500')['qos_specs']
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.qos_client.unset_qos_key(qos['id'], ['iops_bytes'])
- waiters.wait_for_qos_operations(self.admin_qos_client, qos['id'],
+ with self.rbac_utils.override_role(self):
+ self.qos_client.unset_qos_key(qos['id'], ['iops_bytes'])
+ waiters.wait_for_qos_operations(self.qos_client, qos['id'],
'qos-key-unset', args=['iops_bytes'])
@rbac_rule_validation.action(
@@ -111,8 +110,8 @@
qos = self._create_test_qos_specs()
vol_type = self.create_volume_type()['id']
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.qos_client.associate_qos(qos['id'], vol_type)
+ with self.rbac_utils.override_role(self):
+ self.qos_client.associate_qos(qos['id'], vol_type)
self.addCleanup(
test_utils.call_and_ignore_notfound_exc,
self.qos_client.disassociate_qos, qos['id'], vol_type)
@@ -127,9 +126,9 @@
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
self.qos_client.disassociate_qos, qos['id'], vol_type)
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.qos_client.disassociate_qos(qos['id'], vol_type)
- waiters.wait_for_qos_operations(self.admin_qos_client, qos['id'],
+ with self.rbac_utils.override_role(self):
+ self.qos_client.disassociate_qos(qos['id'], vol_type)
+ waiters.wait_for_qos_operations(self.qos_client, qos['id'],
'disassociate', args=vol_type)
@rbac_rule_validation.action(
@@ -142,7 +141,7 @@
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
self.qos_client.disassociate_qos, qos['id'], vol_type)
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.qos_client.disassociate_all_qos(qos['id'])
- waiters.wait_for_qos_operations(self.admin_qos_client, qos['id'],
+ with self.rbac_utils.override_role(self):
+ self.qos_client.disassociate_all_qos(qos['id'])
+ waiters.wait_for_qos_operations(self.qos_client, qos['id'],
'disassociate-all')
diff --git a/patrole_tempest_plugin/tests/api/volume/test_quota_classes_rbac.py b/patrole_tempest_plugin/tests/api/volume/test_quota_classes_rbac.py
index a81f1b9..dace257 100644
--- a/patrole_tempest_plugin/tests/api/volume/test_quota_classes_rbac.py
+++ b/patrole_tempest_plugin/tests/api/volume/test_quota_classes_rbac.py
@@ -41,9 +41,9 @@
@rbac_rule_validation.action(service="cinder",
rule="volume_extension:quota_classes")
def test_show_quota_class_set(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.quota_classes_client.show_quota_class_set(
- self.quota_name)['quota_class_set']
+ with self.rbac_utils.override_role(self):
+ self.quota_classes_client.show_quota_class_set(
+ self.quota_name)['quota_class_set']
@decorators.idempotent_id('72159478-23a7-4c75-989f-6bac609eca62')
@rbac_rule_validation.action(service="cinder",
@@ -53,6 +53,6 @@
self.quota_name)['quota_class_set']
quota_class_set.pop('id')
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.quota_classes_client.update_quota_class_set(self.quota_name,
- **quota_class_set)
+ with self.rbac_utils.override_role(self):
+ self.quota_classes_client.update_quota_class_set(self.quota_name,
+ **quota_class_set)
diff --git a/patrole_tempest_plugin/tests/api/volume/test_scheduler_stats_rbac.py b/patrole_tempest_plugin/tests/api/volume/test_scheduler_stats_rbac.py
index 8fded0a..a243587 100644
--- a/patrole_tempest_plugin/tests/api/volume/test_scheduler_stats_rbac.py
+++ b/patrole_tempest_plugin/tests/api/volume/test_scheduler_stats_rbac.py
@@ -40,5 +40,5 @@
rule="scheduler_extension:scheduler_stats:get_pools")
@decorators.idempotent_id('5f800441-4d30-48ec-9e5b-0d55bc86acbb')
def test_list_back_end_storage_pools(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.scheduler_stats_client.list_pools()
+ with self.rbac_utils.override_role(self):
+ self.scheduler_stats_client.list_pools()
diff --git a/patrole_tempest_plugin/tests/api/volume/test_snapshots_actions_rbac.py b/patrole_tempest_plugin/tests/api/volume/test_snapshots_actions_rbac.py
index f7a4151..65b7526 100644
--- a/patrole_tempest_plugin/tests/api/volume/test_snapshots_actions_rbac.py
+++ b/patrole_tempest_plugin/tests/api/volume/test_snapshots_actions_rbac.py
@@ -66,8 +66,8 @@
def test_snapshot_force_delete(self):
temp_snapshot = self.create_snapshot(self.volume['id'])
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.snapshots_client.force_delete_snapshot(temp_snapshot['id'])
+ with self.rbac_utils.override_role(self):
+ self.snapshots_client.force_delete_snapshot(temp_snapshot['id'])
self.snapshots_client.wait_for_resource_deletion(temp_snapshot['id'])
@decorators.idempotent_id('a95eab2a-c441-4609-9235-f7478627da88')
diff --git a/patrole_tempest_plugin/tests/api/volume/test_snapshots_metadata_rbac.py b/patrole_tempest_plugin/tests/api/volume/test_snapshots_metadata_rbac.py
index 1f82671..226411f 100644
--- a/patrole_tempest_plugin/tests/api/volume/test_snapshots_metadata_rbac.py
+++ b/patrole_tempest_plugin/tests/api/volume/test_snapshots_metadata_rbac.py
@@ -53,8 +53,8 @@
@decorators.idempotent_id('c9cbec1c-edfe-46b8-825b-7b6ac0a58c25')
def test_create_snapshot_metadata(self):
# Create metadata for the snapshot
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self._create_test_snapshot_metadata()
+ with self.rbac_utils.override_role(self):
+ self._create_test_snapshot_metadata()
@rbac_rule_validation.action(service="cinder",
rule="volume:get_snapshot_metadata")
@@ -63,9 +63,9 @@
# Create volume and snapshot metadata
self._create_test_snapshot_metadata()
# Get metadata for the snapshot
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.snapshots_client.show_snapshot_metadata(
- self.snapshot_id)
+ with self.rbac_utils.override_role(self):
+ self.snapshots_client.show_snapshot_metadata(
+ self.snapshot_id)
@rbac_rule_validation.action(
service="cinder",
@@ -74,31 +74,30 @@
def test_get_snapshot_metadata_for_volume_tenant(self):
# Create volume and snapshot metadata
self._create_test_snapshot_metadata()
- # Get metadata for the snapshot
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
# Get the metadata of the snapshot
- self.snapshots_client.show_snapshot_metadata(
- self.snapshot_id)['metadata']
+ with self.rbac_utils.override_role(self):
+ self.snapshots_client.show_snapshot_metadata(
+ self.snapshot_id)['metadata']
@decorators.idempotent_id('7ea597f6-c544-4b10-aab0-ff68f595fb06')
@rbac_rule_validation.action(service="cinder",
rule="volume:update_snapshot_metadata")
def test_update_snapshot_metadata(self):
self._create_test_snapshot_metadata()
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- update = {"key3": "value3_update",
- "key4": "value4"}
- self.snapshots_client.update_snapshot_metadata(
- self.snapshot['id'], metadata=update)
+ with self.rbac_utils.override_role(self):
+ update = {"key3": "value3_update",
+ "key4": "value4"}
+ self.snapshots_client.update_snapshot_metadata(
+ self.snapshot['id'], metadata=update)
@decorators.idempotent_id('93068d02-0131-4dd3-af16-fc40d7128d93')
@rbac_rule_validation.action(service="cinder",
rule="volume:get_snapshot_metadata")
def test_show_snapshot_metadata_item(self):
self._create_test_snapshot_metadata()
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.snapshots_client.show_snapshot_metadata_item(
- self.snapshot['id'], "key3")['meta']
+ with self.rbac_utils.override_role(self):
+ self.snapshots_client.show_snapshot_metadata_item(
+ self.snapshot['id'], "key3")['meta']
@decorators.idempotent_id('1f8f43e7-da31-4128-bb3c-73fc548650e3')
@rbac_rule_validation.action(service="cinder",
@@ -106,15 +105,15 @@
def test_update_snapshot_metadata_item(self):
update_item = {"key3": "value3_update"}
self._create_test_snapshot_metadata()
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.snapshots_client.update_snapshot_metadata_item(
- self.snapshot['id'], "key3", meta=update_item)['meta']
+ with self.rbac_utils.override_role(self):
+ self.snapshots_client.update_snapshot_metadata_item(
+ self.snapshot['id'], "key3", meta=update_item)['meta']
@decorators.idempotent_id('3ec32516-f7cd-4f88-b78a-ddee67492071')
@rbac_rule_validation.action(service="cinder",
rule="volume:delete_snapshot_metadata")
def test_delete_snapshot_metadata_item(self):
self._create_test_snapshot_metadata()
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.snapshots_client.delete_snapshot_metadata_item(
- self.snapshot['id'], "key1")
+ with self.rbac_utils.override_role(self):
+ self.snapshots_client.delete_snapshot_metadata_item(
+ self.snapshot['id'], "key1")
diff --git a/patrole_tempest_plugin/tests/api/volume/test_user_messages_rbac.py b/patrole_tempest_plugin/tests/api/volume/test_user_messages_rbac.py
index bac9189..56ee1e0 100644
--- a/patrole_tempest_plugin/tests/api/volume/test_user_messages_rbac.py
+++ b/patrole_tempest_plugin/tests/api/volume/test_user_messages_rbac.py
@@ -28,13 +28,10 @@
min_microversion = '3.3'
max_microversion = 'latest'
- credentials = ['primary', 'admin']
-
@classmethod
def setup_clients(cls):
super(MessagesV3RbacTest, cls).setup_clients()
cls.messages_client = cls.os_primary.volume_v3_messages_client
- cls.admin_messages_client = cls.os_admin.volume_v3_messages_client
def _create_user_message(self):
"""Trigger a 'no valid host' situation to generate a message."""
@@ -70,8 +67,8 @@
service="cinder",
rule="message:get_all")
def test_list_messages(self):
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.messages_client.list_messages()['messages']
+ with self.rbac_utils.override_role(self):
+ self.messages_client.list_messages()['messages']
@decorators.idempotent_id('9cc1ad1e-68a2-4407-8b60-ea77909bce08')
@rbac_rule_validation.action(
@@ -80,8 +77,8 @@
def test_show_message(self):
message_id = self._create_user_message()
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.messages_client.show_message(message_id)['message']
+ with self.rbac_utils.override_role(self):
+ self.messages_client.show_message(message_id)['message']
@decorators.idempotent_id('65ca7fb7-7f2c-443e-b144-ac86973a97be')
@rbac_rule_validation.action(
@@ -90,6 +87,6 @@
def test_delete_message(self):
message_id = self._create_user_message()
- self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- self.messages_client.delete_message(message_id)
- self.admin_messages_client.wait_for_resource_deletion(message_id)
+ with self.rbac_utils.override_role(self):
+ self.messages_client.delete_message(message_id)
+ self.messages_client.wait_for_resource_deletion(message_id)