diff --git a/aodh/api/controllers/v2/alarm_rules/composite.py b/aodh/api/controllers/v2/alarm_rules/composite.py index 5062a899a..4f11cfedc 100644 --- a/aodh/api/controllers/v2/alarm_rules/composite.py +++ b/aodh/api/controllers/v2/alarm_rules/composite.py @@ -116,4 +116,5 @@ class CompositeRule(wtypes.UserType): def __call__(**rule): return rule + composite_rule = CompositeRule() diff --git a/aodh/api/controllers/v2/query.py b/aodh/api/controllers/v2/query.py index a58e35f79..b750a91c9 100644 --- a/aodh/api/controllers/v2/query.py +++ b/aodh/api/controllers/v2/query.py @@ -100,7 +100,7 @@ class ValidatedComplexQuery(object): valid_fields = _list_to_regexp(valid_keys) if metadata_allowed: - valid_filter_fields = valid_fields + "|^metadata\.[\S]+$" + valid_filter_fields = valid_fields + r"|^metadata\.[\S]+$" else: valid_filter_fields = valid_fields diff --git a/aodh/api/middleware.py b/aodh/api/middleware.py index 58b292e2b..64574d541 100644 --- a/aodh/api/middleware.py +++ b/aodh/api/middleware.py @@ -113,7 +113,7 @@ class ParsableErrorMiddleware(object): if error is not None and 'faultstring' in fault: fault['faultstring'] = i18n.translate(error, user_locale) - except ValueError as err: + except ValueError: fault = app_data body = json.dumps({'error_message': fault}) if six.PY3: diff --git a/aodh/evaluator/__init__.py b/aodh/evaluator/__init__.py index 91b6c07ba..b4eabe0b7 100644 --- a/aodh/evaluator/__init__.py +++ b/aodh/evaluator/__init__.py @@ -198,7 +198,7 @@ class AlarmEvaluationService(cotyledon.Service): super(AlarmEvaluationService, self).__init__(worker_id) self.conf = conf - ef = lambda: futures.ThreadPoolExecutor(max_workers=10) + ef = lambda: futures.ThreadPoolExecutor(max_workers=10) # noqa: E731 self.periodic = periodics.PeriodicWorker.create( [], executor_factory=ef) diff --git a/aodh/evaluator/loadbalancer.py b/aodh/evaluator/loadbalancer.py index bc8d02a9e..c9bd4fdc0 100644 --- a/aodh/evaluator/loadbalancer.py +++ b/aodh/evaluator/loadbalancer.py @@ -86,7 +86,7 @@ class LoadBalancerMemberHealthEvaluator(evaluator.Evaluator): for m in ret.get("members", []): try: created_time = parser.parse(m['created_at'], ignoretz=True) - except ValueError as e: + except ValueError: LOG.warning('Failed to parse the member created time.') continue diff --git a/aodh/storage/sqlalchemy/alembic/env.py b/aodh/storage/sqlalchemy/alembic/env.py index fd15eb5f9..f35eb2813 100644 --- a/aodh/storage/sqlalchemy/alembic/env.py +++ b/aodh/storage/sqlalchemy/alembic/env.py @@ -82,6 +82,7 @@ def run_migrations_online(): context.run_migrations() conn.disconnect() + if not hasattr(config, "conf"): from aodh import service config.conf = service.prepare_service([]) diff --git a/aodh/tests/functional/api/v2/test_capabilities.py b/aodh/tests/functional/api/v2/test_capabilities.py index 78c4996e9..334e1109c 100644 --- a/aodh/tests/functional/api/v2/test_capabilities.py +++ b/aodh/tests/functional/api/v2/test_capabilities.py @@ -18,8 +18,8 @@ from aodh.tests.functional.api import v2 as tests_api class TestCapabilitiesController(tests_api.FunctionalTest): def setUp(self): - super(TestCapabilitiesController, self).setUp() - self.url = '/capabilities' + super(TestCapabilitiesController, self).setUp() + self.url = '/capabilities' def test_capabilities(self): data = self.get_json(self.url) diff --git a/aodh/tests/functional/api/v2/test_quotas.py b/aodh/tests/functional/api/v2/test_quotas.py index b855268b8..7ef9fcd01 100644 --- a/aodh/tests/functional/api/v2/test_quotas.py +++ b/aodh/tests/functional/api/v2/test_quotas.py @@ -32,14 +32,14 @@ class TestQuotas(v2.FunctionalTest): resp = self.get_json('/quotas', headers=self.auth_headers, status=200) self.assertEqual(self.project, resp.get('project_id')) - self.assertTrue(len(resp.get('quotas', [])) > 0) + self.assertGreater(len(resp.get('quotas', [])), 0) def test_get_project_quotas_by_user(self): resp = self.get_json('/quotas?project_id=%s' % self.project, headers=self.auth_headers, status=200) self.assertEqual(self.project, resp.get('project_id')) - self.assertTrue(len(resp.get('quotas', [])) > 0) + self.assertGreater(len(resp.get('quotas', [])), 0) def test_get_other_project_quotas_by_user_failed(self): self.get_json( @@ -58,7 +58,7 @@ class TestQuotas(v2.FunctionalTest): status=200) self.assertEqual(self.other_project, resp.get('project_id')) - self.assertTrue(len(resp.get('quotas', [])) > 0) + self.assertGreater(len(resp.get('quotas', [])), 0) def test_post_quotas_by_admin(self): auth_headers = copy.copy(self.auth_headers) diff --git a/aodh/tests/functional/storage/test_storage_scenarios.py b/aodh/tests/functional/storage/test_storage_scenarios.py index e7dc57c85..6991be5f6 100644 --- a/aodh/tests/functional/storage/test_storage_scenarios.py +++ b/aodh/tests/functional/storage/test_storage_scenarios.py @@ -317,7 +317,7 @@ class AlarmHistoryTest(AlarmTestBase): "on_behalf_of": alarm.project_id, "severity": severity, "timestamp": datetime.datetime(2014, 4, 7, 7, 34) - } + } self.alarm_conn.record_alarm_change(alarm_change=alarm_change) filter_expr = {"=": {"severity": "low"}} history = list(self.alarm_conn.query_alarm_history( diff --git a/tox.ini b/tox.ini index f1df82e75..91b8af3d5 100644 --- a/tox.ini +++ b/tox.ini @@ -80,7 +80,10 @@ setenv = OS_TEST_PATH=aodh/tests/functional/ commands = pifpaf -g AODH_TEST_STORAGE_URL run postgresql -- oslo_debug_helper {posargs} [flake8] -ignore = +# W503 line break before binary operator +# W504 line break after binary operator +# E402 module level import not at top of file +ignore = W503,W504,E402 exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build # [H106] Do not put vim configuration in source files. # [H203] Use assertIs(Not)None to check for None.