Add functools.wraps decorator to rbac_rule_validation
This adds functools.wraps [0] to rbac_rule_validation decorator.
"This takes a function used in a decorator and adds the functionality
of copying over the function name, docstring, arguments list, etc." which
is quite convenient [1].
Also stops adding the role as a testcase attribute which can cause
filtering issues via regular expressions when the role doesn't match
the role in tempest.conf under ``[patrole].rbac_test_role``.
[0] https://docs.python.org/2/library/functools.html#functools.wraps
[1] https://stackoverflow.com/questions/308999/what-does-functools-wraps-do
Change-Id: I8fde00e4f9332ba9b9ea94edc714d87ab9e1b851
diff --git a/patrole_tempest_plugin/rbac_rule_validation.py b/patrole_tempest_plugin/rbac_rule_validation.py
index 01a9981..d3213cf 100644
--- a/patrole_tempest_plugin/rbac_rule_validation.py
+++ b/patrole_tempest_plugin/rbac_rule_validation.py
@@ -13,9 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
+import functools
import logging
import sys
-import testtools
from oslo_utils import excutils
import six
@@ -116,6 +116,7 @@
def decorator(test_func):
role = CONF.patrole.rbac_test_role
+ @functools.wraps(test_func)
def wrapper(*args, **kwargs):
if args and isinstance(args[0], test.BaseTestCase):
test_obj = args[0]
@@ -176,8 +177,7 @@
"Allowed" if allowed else "Denied",
test_status)
- _wrapper = testtools.testcase.attr(role)(wrapper)
- return _wrapper
+ return wrapper
return decorator