From 823bb91ae78c8cfcc1255c8a150240bb394300fb Mon Sep 17 00:00:00 2001 From: Mark McClain Date: Wed, 11 Jun 2014 21:23:53 -0400 Subject: [PATCH] enable F402 check for flake8 The change removes the shadowed loop variables and enables F402 checking Change-Id: I015797feec463ffb0b5e97229a6ec2c9a41df9de Partial-Bug: 1329017 --- neutron/db/securitygroups_db.py | 14 +++++++------- neutron/tests/unit/test_agent_ext_plugin.py | 8 ++++---- neutron/tests/unit/test_l3_agent.py | 6 +++--- tox.ini | 3 +-- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/neutron/db/securitygroups_db.py b/neutron/db/securitygroups_db.py index 23b5c80cb11..6fc0d870ec7 100644 --- a/neutron/db/securitygroups_db.py +++ b/neutron/db/securitygroups_db.py @@ -18,7 +18,7 @@ from sqlalchemy import orm from sqlalchemy.orm import exc from sqlalchemy.orm import scoped_session -from neutron.api.v2 import attributes as attr +from neutron.api.v2 import attributes from neutron.common import constants from neutron.db import db_base_plugin_v2 from neutron.db import model_base @@ -481,11 +481,11 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase): # Register dict extend functions for ports db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs( - attr.PORTS, ['_extend_port_dict_security_group']) + attributes.PORTS, ['_extend_port_dict_security_group']) def _process_port_create_security_group(self, context, port, security_group_ids): - if attr.is_attr_set(security_group_ids): + if attributes.is_attr_set(security_group_ids): for security_group_id in security_group_ids: self._create_port_security_group_binding(context, port['id'], security_group_id) @@ -517,7 +517,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase): :returns: all security groups IDs on port belonging to tenant. """ p = port['port'] - if not attr.is_attr_set(p.get(ext_sg.SECURITYGROUPS)): + if not attributes.is_attr_set(p.get(ext_sg.SECURITYGROUPS)): return if p.get('device_owner') and p['device_owner'].startswith('network:'): return @@ -546,7 +546,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase): tenant_id = self._get_tenant_id_for_create(context, port['port']) default_sg = self._ensure_default_security_group(context, tenant_id) - if attr.is_attr_set(port['port'].get(ext_sg.SECURITYGROUPS)): + if attributes.is_attr_set(port['port'].get(ext_sg.SECURITYGROUPS)): sgids = port['port'].get(ext_sg.SECURITYGROUPS) else: sgids = [default_sg] @@ -557,7 +557,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase): is either [] or not is_attr_set, otherwise return False """ if (ext_sg.SECURITYGROUPS in port['port'] and - not (attr.is_attr_set(port['port'][ext_sg.SECURITYGROUPS]) + not (attributes.is_attr_set(port['port'][ext_sg.SECURITYGROUPS]) and port['port'][ext_sg.SECURITYGROUPS] != [])): return True return False @@ -567,7 +567,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase): security_group field is is_attr_set or []. """ if (ext_sg.SECURITYGROUPS in port['port'] and - (attr.is_attr_set(port['port'][ext_sg.SECURITYGROUPS]) and + (attributes.is_attr_set(port['port'][ext_sg.SECURITYGROUPS]) and port['port'][ext_sg.SECURITYGROUPS] != [])): return True return False diff --git a/neutron/tests/unit/test_agent_ext_plugin.py b/neutron/tests/unit/test_agent_ext_plugin.py index ddbf4f02e9b..a1da827ebe2 100644 --- a/neutron/tests/unit/test_agent_ext_plugin.py +++ b/neutron/tests/unit/test_agent_ext_plugin.py @@ -211,12 +211,12 @@ class AgentDBTestCase(AgentDBTestMixIn, def test_list_agent(self): agents = self._register_agent_states() res = self._list('agents') - for agent in res['agents']: - if (agent['host'] == DHCP_HOSTA and - agent['agent_type'] == constants.AGENT_TYPE_DHCP): + for agt in res['agents']: + if (agt['host'] == DHCP_HOSTA and + agt['agent_type'] == constants.AGENT_TYPE_DHCP): self.assertEqual( 'dhcp_driver', - agent['configurations']['dhcp_driver']) + agt['configurations']['dhcp_driver']) break self.assertEqual(len(agents), len(res['agents'])) diff --git a/neutron/tests/unit/test_l3_agent.py b/neutron/tests/unit/test_l3_agent.py index df362342d7f..c381a66be60 100644 --- a/neutron/tests/unit/test_l3_agent.py +++ b/neutron/tests/unit/test_l3_agent.py @@ -794,9 +794,9 @@ class TestBasicRouterOperations(base.BaseTestCase): def _verify_snat_rules(self, rules, router, negate=False): interfaces = router[l3_constants.INTERFACE_KEY] source_cidrs = [] - for interface in interfaces: - prefix = interface['subnet']['cidr'].split('/')[1] - source_cidr = "%s/%s" % (interface['fixed_ips'][0]['ip_address'], + for iface in interfaces: + prefix = iface['subnet']['cidr'].split('/')[1] + source_cidr = "%s/%s" % (iface['fixed_ips'][0]['ip_address'], prefix) source_cidrs.append(source_cidr) source_nat_ip = router['gw_port']['fixed_ips'][0]['ip_address'] diff --git a/tox.ini b/tox.ini index 63abb846134..9185ac0b848 100644 --- a/tox.ini +++ b/tox.ini @@ -65,7 +65,6 @@ commands = python setup.py build_sphinx # E128 continuation line under-indented for visual indent # E129 visually indented line with same indent as next logical line # E265 block comment should start with ‘# ‘ -# F402 import module shadowed by loop variable # F811 redefinition of unused variable # F812 list comprehension redefines name from line # H237 module is removed in Python 3 @@ -76,7 +75,7 @@ commands = python setup.py build_sphinx # H405 multi line docstring summary not separated with an empty line # H904 Wrap long lines in parentheses instead of a backslash # TODO(marun) H404 multi line docstring should start with a summary -ignore = E125,E126,E128,E129,E265,F402,F811,F812,H237,H305,H307,H401,H402,H404,H405,H904 +ignore = E125,E126,E128,E129,E265,F811,F812,H237,H305,H307,H401,H402,H404,H405,H904 show-source = true builtins = _ exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools,.ropeproject,rally-scenarios