From 4bf66a22855c2d96399cf20ed96b1cbed2f65266 Mon Sep 17 00:00:00 2001 From: Felipe Monteiro Date: Sun, 7 May 2017 14:44:21 +0100 Subject: [PATCH] Hacking: enable extensions H106, H203 and H904 [H106] Don't put vim configuration in source files. [H203] Use assertIs(Not)None to check for None. [H904] Delay string interpolations at logging calls. This change makes Patrole's hacking consistent with Tempest's [0][1]. [0] https://review.openstack.org/#/c/408211/ [1] https://review.openstack.org/#/c/408066/ Change-Id: Ia56f66b4ab7e1eea6a8bfea05bf52865be13430c --- patrole_tempest_plugin/rbac_policy_parser.py | 2 +- patrole_tempest_plugin/rbac_rule_validation.py | 4 ++-- .../tests/unit/test_rbac_rule_validation.py | 3 ++- tox.ini | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/patrole_tempest_plugin/rbac_policy_parser.py b/patrole_tempest_plugin/rbac_policy_parser.py index d4e989bd..1047d37e 100644 --- a/patrole_tempest_plugin/rbac_policy_parser.py +++ b/patrole_tempest_plugin/rbac_policy_parser.py @@ -81,7 +81,7 @@ class RbacPolicyParser(object): path = getattr(CONF.rbac, '%s_policy_file' % str(service), None) if not path: LOG.info("No config option found for %s," - " using default path" % str(service)) + " using default path", str(service)) path = os.path.join('/etc', service, 'policy.json') self.path = path self.rules = policy.Rules.load(self._get_policy_data(service), diff --git a/patrole_tempest_plugin/rbac_rule_validation.py b/patrole_tempest_plugin/rbac_rule_validation.py index d77b2d65..60a0f101 100644 --- a/patrole_tempest_plugin/rbac_rule_validation.py +++ b/patrole_tempest_plugin/rbac_rule_validation.py @@ -104,7 +104,7 @@ def action(service, rule='', admin_only=False, expected_error_code=403, (role, rule)) LOG.error(msg) raise exceptions.Forbidden( - "%s exception was: %s" % (msg, e)) + "%s Exception was: %s" % (msg, e)) except Exception as e: exc_info = sys.exc_info() error_details = exc_info[1].__str__() @@ -115,7 +115,7 @@ def action(service, rule='', admin_only=False, expected_error_code=403, six.reraise(exc_info[0], exc_info[0](msg), exc_info[2]) else: if not allowed: - LOG.error("Role %s was allowed to perform %s" % + LOG.error("Role %s was allowed to perform %s", (role, rule)) raise rbac_exceptions.RbacOverPermission( "OverPermission: Role %s was allowed to perform %s" % diff --git a/patrole_tempest_plugin/tests/unit/test_rbac_rule_validation.py b/patrole_tempest_plugin/tests/unit/test_rbac_rule_validation.py index 41af3b23..369c5636 100644 --- a/patrole_tempest_plugin/tests/unit/test_rbac_rule_validation.py +++ b/patrole_tempest_plugin/tests/unit/test_rbac_rule_validation.py @@ -255,7 +255,8 @@ class RBACRuleValidationTest(base.TestCase): "sentinel.action"), e.__str__()) mock_log.error.assert_called_once_with( - "Role Member was allowed to perform sentinel.action") + 'Role %s was allowed to perform %s', ('Member', + mock.sentinel.action)) @mock.patch.object(rbac_rv, 'rbac_policy_parser', autospec=True) def test_invalid_policy_rule_throws_parsing_exception( diff --git a/tox.ini b/tox.ini index be355099..d2e83e96 100644 --- a/tox.ini +++ b/tox.ini @@ -53,9 +53,9 @@ commands = commands = oslo_debug_helper -t patrole_tempest_plugin/tests {posargs} [flake8] -# E123, E125 skipped as they are invalid PEP-8. - +enable-extensions = H106,H203,H904 show-source = True +# E123, E125 skipped as they are invalid PEP-8. ignore = E123,E125 builtins = _ exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build