From a440759d40902edeee8590e20ff04efa8892f858 Mon Sep 17 00:00:00 2001 From: Igor Degtiarov Date: Wed, 25 Jun 2014 17:55:59 +0300 Subject: [PATCH] Fix F402 violations and re-enable gating F402 got stricter in hacking 0.9, so fix new violations and re-enable gating. Change-Id: I81a1b14311ea6dc7f01353aa27d1f18f1aec8e81 --- ceilometer/agent.py | 14 +-- ceilometer/storage/impl_sqlalchemy.py | 14 +-- ceilometer/tests/agentbase.py | 6 +- .../api/v2/test_complex_query_scenarios.py | 56 ++++----- ceilometer/tests/publisher/test_file.py | 6 +- .../tests/publisher/test_rpc_publisher.py | 4 +- .../tests/storage/test_storage_scenarios.py | 112 +++++++++--------- tox.ini | 3 +- 8 files changed, 109 insertions(+), 106 deletions(-) diff --git a/ceilometer/agent.py b/ceilometer/agent.py index 0427a5b62..4dc17eb8d 100644 --- a/ceilometer/agent.py +++ b/ceilometer/agent.py @@ -69,8 +69,8 @@ class PollingTask(object): def add(self, pollster, pipelines): self.publish_context.add_pipelines(pipelines) - for pipeline in pipelines: - self.resources[pollster.name].extend(pipeline) + for pipe_line in pipelines: + self.resources[pollster.name].extend(pipe_line) self.pollsters.update([pollster]) def poll_and_publish(self): @@ -121,15 +121,15 @@ class AgentManager(os_service.Service): def setup_polling_tasks(self): polling_tasks = {} - for pipeline, pollster in itertools.product( + for pipe_line, pollster in itertools.product( self.pipeline_manager.pipelines, self.pollster_manager.extensions): - if pipeline.support_meter(pollster.name): - polling_task = polling_tasks.get(pipeline.get_interval()) + if pipe_line.support_meter(pollster.name): + polling_task = polling_tasks.get(pipe_line.get_interval()) if not polling_task: polling_task = self.create_polling_task() - polling_tasks[pipeline.get_interval()] = polling_task - polling_task.add(pollster, [pipeline]) + polling_tasks[pipe_line.get_interval()] = polling_task + polling_task.add(pollster, [pipe_line]) return polling_tasks diff --git a/ceilometer/storage/impl_sqlalchemy.py b/ceilometer/storage/impl_sqlalchemy.py index 62306b848..46d0d8354 100644 --- a/ceilometer/storage/impl_sqlalchemy.py +++ b/ceilometer/storage/impl_sqlalchemy.py @@ -1029,11 +1029,11 @@ class Connection(base.Connection): and_(*event_join_conditions)) if event_filter_conditions: query = query.filter(and_(*event_filter_conditions)) - for (id, generated, message_id, desc) in query.all(): - event_models_dict[id] = api_models.Event(message_id, - desc, - generated, - []) + for (id_, generated, message_id, desc_) in query.all(): + event_models_dict[id_] = api_models.Event(message_id, + desc_, + generated, + []) # Build event models for the events event_query = event_query.subquery() @@ -1099,8 +1099,8 @@ class Connection(base.Connection): models.TraitType.data_type) .distinct()) - for desc, type in query.all(): - yield {'name': desc, 'data_type': type} + for desc_, dtype in query.all(): + yield {'name': desc_, 'data_type': dtype} def get_traits(self, event_type, trait_type=None): """Return all trait instances associated with an event_type. If diff --git a/ceilometer/tests/agentbase.py b/ceilometer/tests/agentbase.py index 72bd909d6..598f9c369 100644 --- a/ceilometer/tests/agentbase.py +++ b/ceilometer/tests/agentbase.py @@ -482,8 +482,8 @@ class BaseAgentManagerTestCase(base.BaseTestCase): amalgamated_resources = set(['test://', 'another://']) self.assertEqual(amalgamated_resources, set(self.Pollster.samples[0][1])) - for pipeline in self.mgr.pipeline_manager.pipelines: - self.assertEqual(1, len(pipeline.publishers[0].samples)) - published = pipeline.publishers[0].samples[0] + for pipe_line in self.mgr.pipeline_manager.pipelines: + self.assertEqual(1, len(pipe_line.publishers[0].samples)) + published = pipe_line.publishers[0].samples[0] self.assertEqual(amalgamated_resources, set(published.resource_metadata['resources'])) diff --git a/ceilometer/tests/api/v2/test_complex_query_scenarios.py b/ceilometer/tests/api/v2/test_complex_query_scenarios.py index 983088683..5aba5f464 100644 --- a/ceilometer/tests/api/v2/test_complex_query_scenarios.py +++ b/ceilometer/tests/api/v2/test_complex_query_scenarios.py @@ -106,8 +106,8 @@ class TestQueryMetersController(tests_api.FunctionalTest, + isotime + '"}}'}) self.assertEqual(2, len(data.json)) - for sample in data.json: - result_time = timeutils.parse_isotime(sample['timestamp']) + for sample_item in data.json: + result_time = timeutils.parse_isotime(sample_item['timestamp']) result_time = result_time.replace(tzinfo=None) self.assertTrue(result_time >= date_time) @@ -115,8 +115,8 @@ class TestQueryMetersController(tests_api.FunctionalTest, data = self.post_json(self.url, params={}, headers=non_admin_header) - for sample in data.json: - self.assertEqual("project-id1", sample['project_id']) + for sample_item in data.json: + self.assertEqual("project-id1", sample_item['project_id']) def test_non_admin_tenant_cannot_query_others_project(self): data = self.post_json(self.url, @@ -135,8 +135,8 @@ class TestQueryMetersController(tests_api.FunctionalTest, '{"=": {"project_id": "project-id1"}}'}, headers=non_admin_header) - for sample in data.json: - self.assertEqual("project-id1", sample['project_id']) + for sample_item in data.json: + self.assertEqual("project-id1", sample_item['project_id']) def test_admin_tenant_sees_every_project(self): data = self.post_json(self.url, @@ -144,8 +144,8 @@ class TestQueryMetersController(tests_api.FunctionalTest, headers=admin_header) self.assertEqual(3, len(data.json)) - for sample in data.json: - self.assertIn(sample['project_id'], + for sample_item in data.json: + self.assertIn(sample_item['project_id'], (["project-id1", "project-id2", "project-id3"])) def test_admin_tenant_sees_every_project_with_complex_filter(self): @@ -157,8 +157,8 @@ class TestQueryMetersController(tests_api.FunctionalTest, headers=admin_header) self.assertEqual(2, len(data.json)) - for sample in data.json: - self.assertIn(sample['project_id'], + for sample_item in data.json: + self.assertIn(sample_item['project_id'], (["project-id1", "project-id2"])) def test_admin_tenant_sees_every_project_with_in_filter(self): @@ -169,8 +169,8 @@ class TestQueryMetersController(tests_api.FunctionalTest, headers=admin_header) self.assertEqual(2, len(data.json)) - for sample in data.json: - self.assertIn(sample['project_id'], + for sample_item in data.json: + self.assertIn(sample_item['project_id'], (["project-id1", "project-id2"])) def test_admin_tenant_can_query_any_project(self): @@ -180,8 +180,8 @@ class TestQueryMetersController(tests_api.FunctionalTest, headers=admin_header) self.assertEqual(1, len(data.json)) - for sample in data.json: - self.assertIn(sample['project_id'], set(["project-id2"])) + for sample_item in data.json: + self.assertIn(sample_item['project_id'], set(["project-id2"])) def test_query_with_orderby(self): data = self.post_json(self.url, @@ -197,8 +197,8 @@ class TestQueryMetersController(tests_api.FunctionalTest, '{"=": {"project": "project-id2"}}'}) self.assertEqual(1, len(data.json)) - for sample in data.json: - self.assertIn(sample['project_id'], set(["project-id2"])) + for sample_item in data.json: + self.assertIn(sample_item['project_id'], set(["project-id2"])) def test_query_with_field_name_resource(self): data = self.post_json(self.url, @@ -206,8 +206,8 @@ class TestQueryMetersController(tests_api.FunctionalTest, '{"=": {"resource": "resource-id2"}}'}) self.assertEqual(1, len(data.json)) - for sample in data.json: - self.assertIn(sample['resource_id'], set(["resource-id2"])) + for sample_item in data.json: + self.assertIn(sample_item['resource_id'], set(["resource-id2"])) def test_query_with_field_name_user(self): data = self.post_json(self.url, @@ -215,8 +215,8 @@ class TestQueryMetersController(tests_api.FunctionalTest, '{"=": {"user": "user-id2"}}'}) self.assertEqual(1, len(data.json)) - for sample in data.json: - self.assertIn(sample['user_id'], set(["user-id2"])) + for sample_item in data.json: + self.assertIn(sample_item['user_id'], set(["user-id2"])) def test_query_with_field_name_meter(self): data = self.post_json(self.url, @@ -224,8 +224,8 @@ class TestQueryMetersController(tests_api.FunctionalTest, '{"=": {"meter": "meter.test"}}'}) self.assertEqual(3, len(data.json)) - for sample in data.json: - self.assertIn(sample['meter'], set(["meter.test"])) + for sample_item in data.json: + self.assertIn(sample_item['meter'], set(["meter.test"])) def test_query_with_lower_and_upper_case_orderby(self): data = self.post_json(self.url, @@ -264,8 +264,8 @@ class TestQueryMetersController(tests_api.FunctionalTest, '{">=": {"metadata.util": 0.5}}'}) self.assertEqual(2, len(data.json)) - for sample in data.json: - self.assertTrue(sample["metadata"]["util"] >= 0.5) + for sample_item in data.json: + self.assertTrue(sample_item["metadata"]["util"] >= 0.5) def test_filter_with_negation(self): filter_expr = '{"not": {">=": {"metadata.util": 0.5}}}' @@ -273,8 +273,8 @@ class TestQueryMetersController(tests_api.FunctionalTest, params={"filter": filter_expr}) self.assertEqual(1, len(data.json)) - for sample in data.json: - self.assertTrue(float(sample["metadata"]["util"]) < 0.5) + for sample_item in data.json: + self.assertTrue(float(sample_item["metadata"]["util"]) < 0.5) def test_limit_should_be_positive(self): data = self.post_json(self.url, @@ -415,8 +415,8 @@ class TestQueryAlarmsController(tests_api.FunctionalTest, '{"=": {"project": "project-id2"}}'}) self.assertEqual(6, len(data.json)) - for sample in data.json: - self.assertIn(sample['project_id'], set(["project-id2"])) + for sample_item in data.json: + self.assertIn(sample_item['project_id'], set(["project-id2"])) def test_query_with_field_user_in_orderby(self): data = self.post_json(self.alarm_url, diff --git a/ceilometer/tests/publisher/test_file.py b/ceilometer/tests/publisher/test_file.py index e5022be38..d1563b1bf 100644 --- a/ceilometer/tests/publisher/test_file.py +++ b/ceilometer/tests/publisher/test_file.py @@ -104,9 +104,9 @@ class TestFilePublisher(test.BaseTestCase): self.assertTrue(os.path.exists(name)) with open(name, 'r') as f: content = f.read() - for sample in self.test_data: - self.assertTrue(sample.id in content) - self.assertTrue(sample.timestamp in content) + for sample_item in self.test_data: + self.assertTrue(sample_item.id in content) + self.assertTrue(sample_item.timestamp in content) def test_file_publisher_invalid(self): # Test invalid max bytes, backup count configurations diff --git a/ceilometer/tests/publisher/test_rpc_publisher.py b/ceilometer/tests/publisher/test_rpc_publisher.py index c8000a01d..78ff429e6 100644 --- a/ceilometer/tests/publisher/test_rpc_publisher.py +++ b/ceilometer/tests/publisher/test_rpc_publisher.py @@ -117,8 +117,8 @@ class TestPublish(tests_base.BaseTestCase): class Matcher(object): @staticmethod def __eq__(data): - for i, sample in enumerate(data): - if sample['counter_name'] != self.test_data[i].name: + for i, sample_item in enumerate(data): + if sample_item['counter_name'] != self.test_data[i].name: return False return True diff --git a/ceilometer/tests/storage/test_storage_scenarios.py b/ceilometer/tests/storage/test_storage_scenarios.py index 28f862e59..20b2e6dfc 100644 --- a/ceilometer/tests/storage/test_storage_scenarios.py +++ b/ceilometer/tests/storage/test_storage_scenarios.py @@ -471,10 +471,10 @@ class RawSampleTest(DBTestBase, def test_get_samples_in_default_order(self): f = storage.SampleFilter() prev_timestamp = None - for sample in self.conn.get_samples(f): + for sample_item in self.conn.get_samples(f): if prev_timestamp is not None: - self.assertTrue(prev_timestamp >= sample.timestamp) - prev_timestamp = sample.timestamp + self.assertTrue(prev_timestamp >= sample_item.timestamp) + prev_timestamp = sample_item.timestamp def test_get_samples_by_user(self): f = storage.SampleFilter(user='user-id') @@ -742,8 +742,8 @@ class ComplexSampleQueryTest(DBTestBase, def test_no_filter(self): results = list(self.conn.query_samples()) self.assertEqual(len(results), len(self.msgs)) - for sample in results: - d = sample.as_dict() + for sample_item in results: + d = sample_item.as_dict() del d['recorded_at'] self.assertIn(d, self.msgs) @@ -761,28 +761,28 @@ class ComplexSampleQueryTest(DBTestBase, simple_filter = {"=": {"resource_id": "resource-id-8"}} results = list(self.conn.query_samples(filter_expr=simple_filter)) self.assertEqual(len(results), 1) - for sample in results: - self.assertEqual(sample.resource_id, "resource-id-8") + for sample_item in results: + self.assertEqual(sample_item.resource_id, "resource-id-8") def test_query_simple_filter_with_not_equal_relation(self): simple_filter = {"!=": {"resource_id": "resource-id-8"}} results = list(self.conn.query_samples(filter_expr=simple_filter)) self.assertEqual(len(results), len(self.msgs) - 1) - for sample in results: - self.assertNotEqual(sample.resource_id, "resource-id-8") + for sample_item in results: + self.assertNotEqual(sample_item.resource_id, "resource-id-8") def test_query_complex_filter(self): self._create_samples() results = list(self.conn.query_samples(filter_expr=( self.complex_filter))) self.assertEqual(len(results), 6) - for sample in results: - self.assertIn(sample.resource_id, + for sample_item in results: + self.assertIn(sample_item.resource_id, set(["resource-id-42", "resource-id-44"])) - self.assertEqual(sample.counter_name, + self.assertEqual(sample_item.counter_name, "cpu_util") - self.assertTrue(sample.counter_volume > 0.4) - self.assertTrue(sample.counter_volume <= 0.8) + self.assertTrue(sample_item.counter_volume > 0.4) + self.assertTrue(sample_item.counter_volume <= 0.8) def test_query_complex_filter_with_limit(self): self._create_samples() @@ -822,15 +822,15 @@ class ComplexSampleQueryTest(DBTestBase, results = list( self.conn.query_samples(filter_expr=self.complex_filter_list)) self.assertEqual(len(results), 9) - for sample in results: - self.assertIn(sample.resource_id, + for sample_item in results: + self.assertIn(sample_item.resource_id, set(["resource-id-42", "resource-id-43", "resource-id-44"])) - self.assertEqual(sample.counter_name, + self.assertEqual(sample_item.counter_name, "cpu_util") - self.assertTrue(sample.counter_volume > 0.4) - self.assertTrue(sample.counter_volume <= 0.8) + self.assertTrue(sample_item.counter_volume > 0.4) + self.assertTrue(sample_item.counter_volume <= 0.8) def test_query_complex_filter_with_list_with_limit(self): self._create_samples() @@ -888,15 +888,15 @@ class ComplexSampleQueryTest(DBTestBase, results = list( self.conn.query_samples(filter_expr=self.complex_filter_in)) self.assertEqual(len(results), 9) - for sample in results: - self.assertIn(sample.resource_id, + for sample_item in results: + self.assertIn(sample_item.resource_id, set(["resource-id-42", "resource-id-43", "resource-id-44"])) - self.assertEqual(sample.counter_name, + self.assertEqual(sample_item.counter_name, "cpu_util") - self.assertTrue(sample.counter_volume > 0.4) - self.assertTrue(sample.counter_volume <= 0.8) + self.assertTrue(sample_item.counter_volume > 0.4) + self.assertTrue(sample_item.counter_volume <= 0.8) def test_query_simple_metadata_filter(self): self._create_samples() @@ -906,8 +906,8 @@ class ComplexSampleQueryTest(DBTestBase, results = list(self.conn.query_samples(filter_expr=filter_expr)) self.assertEqual(len(results), 6) - for sample in results: - self.assertTrue(sample.resource_metadata["a_bool_key"]) + for sample_item in results: + self.assertTrue(sample_item.resource_metadata["a_bool_key"]) def test_query_simple_metadata_with_in_op(self): self._create_samples() @@ -917,8 +917,9 @@ class ComplexSampleQueryTest(DBTestBase, results = list(self.conn.query_samples(filter_expr=filter_expr)) self.assertEqual(len(results), 12) - for sample in results: - self.assertIn(sample.resource_metadata["an_int_key"], [42, 43]) + for sample_item in results: + self.assertIn(sample_item.resource_metadata["an_int_key"], + [42, 43]) def test_query_complex_metadata_filter(self): self._create_samples() @@ -931,11 +932,12 @@ class ComplexSampleQueryTest(DBTestBase, results = list(self.conn.query_samples(filter_expr=filter_expr)) self.assertEqual(len(results), 8) - for sample in results: - self.assertTrue((sample.resource_metadata["a_string_key"] == + for sample_item in results: + self.assertTrue((sample_item.resource_metadata["a_string_key"] == "meta-value0.81" or - sample.resource_metadata["a_float_key"] <= 0.41)) - self.assertTrue(sample.resource_metadata["an_int_key"] > 42) + sample_item.resource_metadata["a_float_key"] <= + 0.41)) + self.assertTrue(sample_item.resource_metadata["an_int_key"] > 42) def test_query_mixed_data_and_metadata_filter(self): self._create_samples() @@ -949,11 +951,12 @@ class ComplexSampleQueryTest(DBTestBase, results = list(self.conn.query_samples(filter_expr=filter_expr)) self.assertEqual(len(results), 4) - for sample in results: - self.assertTrue((sample.resource_metadata["a_string_key"] == + for sample_item in results: + self.assertTrue((sample_item.resource_metadata["a_string_key"] == "meta-value0.81" or - sample.resource_metadata["a_float_key"] <= 0.41)) - self.assertEqual(sample.resource_id, "resource-id-42") + sample_item.resource_metadata["a_float_key"] <= + 0.41)) + self.assertEqual(sample_item.resource_id, "resource-id-42") def test_query_non_existing_metadata_with_result(self): self._create_samples() @@ -966,8 +969,8 @@ class ComplexSampleQueryTest(DBTestBase, results = list(self.conn.query_samples(filter_expr=filter_expr)) self.assertEqual(len(results), 3) - for sample in results: - self.assertEqual(sample.resource_metadata["a_string_key"], + for sample_item in results: + self.assertEqual(sample_item.resource_metadata["a_string_key"], "meta-value0.81") def test_query_non_existing_metadata_without_result(self): @@ -994,10 +997,11 @@ class ComplexSampleQueryTest(DBTestBase, results = list(self.conn.query_samples(filter_expr=filter_expr)) self.assertEqual(len(results), 3) - for sample in results: - self.assertEqual(sample.resource_id, "resource-id-42") - self.assertTrue(sample.resource_metadata["an_int_key"] <= 43) - self.assertTrue(sample.resource_metadata["a_float_key"] > 0.41) + for sample_item in results: + self.assertEqual(sample_item.resource_id, "resource-id-42") + self.assertTrue(sample_item.resource_metadata["an_int_key"] <= 43) + self.assertTrue(sample_item.resource_metadata["a_float_key"] > + 0.41) def test_query_negated_complex_expression(self): self._create_samples() @@ -1016,11 +1020,11 @@ class ComplexSampleQueryTest(DBTestBase, results = list(self.conn.query_samples(filter_expr=filter_expr)) self.assertEqual(len(results), 4) - for sample in results: - self.assertEqual(sample.resource_id, + for sample_item in results: + self.assertEqual(sample_item.resource_id, "resource-id-43") - self.assertIn(sample.counter_volume, [0.39, 0.4, 0.8, 0.81]) - self.assertEqual(sample.counter_name, + self.assertIn(sample_item.counter_volume, [0.39, 0.4, 0.8, 0.81]) + self.assertEqual(sample_item.counter_name, "cpu_util") def test_query_with_double_negation(self): @@ -1039,11 +1043,11 @@ class ComplexSampleQueryTest(DBTestBase, results = list(self.conn.query_samples(filter_expr=filter_expr)) self.assertEqual(len(results), 4) - for sample in results: - self.assertEqual(sample.resource_id, + for sample_item in results: + self.assertEqual(sample_item.resource_id, "resource-id-43") - self.assertIn(sample.counter_volume, [0.39, 0.4, 0.8, 0.81]) - self.assertEqual(sample.counter_name, + self.assertIn(sample_item.counter_volume, [0.39, 0.4, 0.8, 0.81]) + self.assertEqual(sample_item.counter_name, "cpu_util") def test_query_negate_not_equal(self): @@ -1053,8 +1057,8 @@ class ComplexSampleQueryTest(DBTestBase, results = list(self.conn.query_samples(filter_expr=filter_expr)) self.assertEqual(len(results), 6) - for sample in results: - self.assertEqual(sample.resource_id, + for sample_item in results: + self.assertEqual(sample_item.resource_id, "resource-id-43") def test_query_negated_in_op(self): @@ -1066,8 +1070,8 @@ class ComplexSampleQueryTest(DBTestBase, results = list(self.conn.query_samples(filter_expr=filter_expr)) self.assertEqual(len(results), 3) - for sample in results: - self.assertIn(sample.counter_volume, + for sample_item in results: + self.assertIn(sample_item.counter_volume, [0.41, 0.8, 0.81]) diff --git a/tox.ini b/tox.ini index 4b2da8afd..a1e2df600 100644 --- a/tox.ini +++ b/tox.ini @@ -37,12 +37,11 @@ commands = python setup.py build_sphinx commands = {posargs} [flake8] -# F402 import module shadowed by loop variable # H305 imports not grouped correctly # H307 like imports should be grouped together # H405 multi line docstring summary not separated with an empty line # H904 Wrap long lines in parentheses instead of a backslash -ignore = F402,H305,H307,H405,H904 +ignore = H305,H307,H405,H904 builtins = _ exclude=.venv,.git,.tox,dist,doc,./ceilometer/openstack/common,*lib/python*,*egg,tools,nova_tests,build show-source = True