Implement RbacUtilsMixin for base RBAC classes
This PS implements a RbacUtilsMixin mixin class in rbac_utils
module. This mixin is useful for doing basic Patrole setup in one
place. The mixin currently handles skipping tests if the flag
`[patrole] enable_rbac` is False and initializing rbac_utils
for each RBAC test.
Following changes have been made:
* Implementation of RbacUtilsMixin
* Associated unit tests
* Refactor base RBAC classes to use the mixin
* Trivial documentation changes
Change-Id: Ieaf19ccc8ce374b12af4c481a2bddcdbe86dedec
diff --git a/patrole_tempest_plugin/rbac_utils.py b/patrole_tempest_plugin/rbac_utils.py
index 4ef0f80..753c915 100644
--- a/patrole_tempest_plugin/rbac_utils.py
+++ b/patrole_tempest_plugin/rbac_utils.py
@@ -114,7 +114,7 @@
* admin if `toggle_rbac_role` is False
* `CONF.patrole.rbac_test_role` if `toggle_rbac_role` is True
- :param test_obj: test object of type tempest.lib.base.BaseTestCase
+ :param test_obj: instance of :py:class:`tempest.test.BaseTestCase`
:param toggle_rbac_role: role to switch `os_primary` Tempest creds to
"""
self._override_role(test_obj, toggle_rbac_role)
@@ -122,7 +122,7 @@
def _override_role(self, test_obj, toggle_rbac_role=False):
"""Private helper for overriding ``os_primary`` Tempest credentials.
- :param test_obj: test object of type tempest.lib.base.BaseTestCase
+ :param test_obj: instance of :py:class:`tempest.test.BaseTestCase`
:param toggle_rbac_role: Boolean value that controls the role that
overrides default role of ``os_primary`` credentials.
* If True: role is set to ``[patrole] rbac_test_role``
@@ -203,6 +203,39 @@
return False
+class RbacUtilsMixin(object):
+ """Mixin class to be used alongside an instance of
+ :py:class:`tempest.test.BaseTestCase`.
+
+ Should be used to perform Patrole class setup for a base RBAC class. Child
+ classes should not use this mixin.
+
+ Example::
+
+ class BaseRbacTest(rbac_utils.RbacUtilsMixin, base.BaseV2ComputeTest):
+
+ @classmethod
+ def skip_checks(cls):
+ super(BaseRbacTest, cls).skip_checks()
+ cls.skip_rbac_checks()
+
+ @classmethod
+ def setup_clients(cls):
+ super(BaseRbacTest, cls).setup_clients()
+ cls.setup_rbac_utils()
+ """
+
+ @classmethod
+ def skip_rbac_checks(cls):
+ if not CONF.patrole.enable_rbac:
+ raise cls.skipException(
+ '%s skipped as Patrole testing not enabled.' % cls.__name__)
+
+ @classmethod
+ def setup_rbac_utils(cls):
+ cls.rbac_utils = RbacUtils(cls)
+
+
def is_admin():
"""Verifies whether the current test role equals the admin role.