From 4ab676fc4f98f2b67e7b1ae7dbed657d602a95a1 Mon Sep 17 00:00:00 2001 From: Zhongyue Luo Date: Thu, 31 Jan 2013 16:08:26 +0800 Subject: [PATCH] Fixes 'not in' operator usage Fixes bug #1110058 Change-Id: I45c10097abfb929918925e7befb8ed6c36b1de1c --- quantum/agent/l3_agent.py | 2 +- quantum/agent/linux/iptables_firewall.py | 2 +- quantum/api/extensions.py | 4 ++-- quantum/extensions/servicetype.py | 2 +- .../plugins/cisco/ucs/cisco_ucs_inventory_v2.py | 10 +++++----- .../plugins/hyperv/agent/hyperv_quantum_agent.py | 2 +- .../agent/linuxbridge_quantum_agent.py | 2 +- .../plugins/metaplugin/meta_quantum_plugin.py | 16 ++++++++-------- .../nicira/nicira_nvp_plugin/QuantumPlugin.py | 2 +- .../nicira/nicira_nvp_plugin/common/config.py | 2 +- quantum/tests/unit/test_servicetype.py | 2 +- quantum/wsgi.py | 2 +- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/quantum/agent/l3_agent.py b/quantum/agent/l3_agent.py index ead519880..f15fff6f5 100644 --- a/quantum/agent/l3_agent.py +++ b/quantum/agent/l3_agent.py @@ -502,7 +502,7 @@ class L3NATAgent(manager.Manager): device = ip_lib.IPDevice(interface_name, self.conf.root_helper, namespace=ri.ns_name()) - if not ip_cidr in [addr['cidr'] for addr in device.addr.list()]: + if ip_cidr not in [addr['cidr'] for addr in device.addr.list()]: net = netaddr.IPNetwork(ip_cidr) device.addr.add(net.version, ip_cidr, str(net.broadcast)) self._send_gratuitous_arp_packet(ri, interface_name, floating_ip) diff --git a/quantum/agent/linux/iptables_firewall.py b/quantum/agent/linux/iptables_firewall.py index c01e22676..a0f342e41 100644 --- a/quantum/agent/linux/iptables_firewall.py +++ b/quantum/agent/linux/iptables_firewall.py @@ -56,7 +56,7 @@ class IptablesFirewallDriver(firewall.FirewallDriver): def update_port_filter(self, port): LOG.debug(_("Updating device (%s) filter"), port['device']) - if not port['device'] in self.filtered_ports: + if port['device'] not in self.filtered_ports: LOG.info(_('Attempted to update port filter which is not ' 'filtered %s'), port['device']) return diff --git a/quantum/api/extensions.py b/quantum/api/extensions.py index bcb8603cf..707383fe8 100644 --- a/quantum/api/extensions.py +++ b/quantum/api/extensions.py @@ -302,7 +302,7 @@ class ExtensionMiddleware(wsgi.Middleware): """Return a dict of ActionExtensionController-s by collection.""" action_controllers = {} for action in ext_mgr.get_actions(): - if not action.collection in action_controllers.keys(): + if action.collection not in action_controllers.keys(): controller = ActionExtensionController(application) mapper.connect("/%s/:(id)/action.:(format)" % action.collection, @@ -321,7 +321,7 @@ class ExtensionMiddleware(wsgi.Middleware): """Returns a dict of RequestExtensionController-s by collection.""" request_ext_controllers = {} for req_ext in ext_mgr.get_request_extensions(): - if not req_ext.key in request_ext_controllers.keys(): + if req_ext.key not in request_ext_controllers.keys(): controller = RequestExtensionController(application) mapper.connect(req_ext.url_route + '.:(format)', action='process', diff --git a/quantum/extensions/servicetype.py b/quantum/extensions/servicetype.py index b5e4b7f13..45ea1612f 100644 --- a/quantum/extensions/servicetype.py +++ b/quantum/extensions/servicetype.py @@ -103,7 +103,7 @@ def _validate_service_defs(data, valid_values=None): LOG.error(_("%(f_name)s: %(msg)s"), locals()) return msg # Validate 'service' attribute - if not svc_name in constants.ALLOWED_SERVICES: + if svc_name not in constants.ALLOWED_SERVICES: msg = (_("Service name '%s' unspecified " "or invalid") % svc_name) LOG.error(_("%(f_name)s: %(msg)s"), locals()) diff --git a/quantum/plugins/cisco/ucs/cisco_ucs_inventory_v2.py b/quantum/plugins/cisco/ucs/cisco_ucs_inventory_v2.py index ac757e56c..d9d78bf30 100644 --- a/quantum/plugins/cisco/ucs/cisco_ucs_inventory_v2.py +++ b/quantum/plugins/cisco/ucs/cisco_ucs_inventory_v2.py @@ -166,15 +166,15 @@ class UCSInventory(L2NetworkDeviceInventoryBase): # marked as reserved, else we temporarily mark it as unreserved # based on the UCSM state, but may later change it if a port # association is found in the DB - if not const.TENANTID in blade_intf_data[blade_intf].keys(): + if const.TENANTID not in blade_intf_data[blade_intf].keys(): blade_intf_data[blade_intf][const.TENANTID] = None - if not const.PORTID in blade_intf_data[blade_intf].keys(): + if const.PORTID not in blade_intf_data[blade_intf].keys(): blade_intf_data[blade_intf][const.PORTID] = None - if not const.PROFILE_ID in blade_intf_data[blade_intf].keys(): + if const.PROFILE_ID not in blade_intf_data[blade_intf].keys(): blade_intf_data[blade_intf][const.PROFILE_ID] = None - if not const.INSTANCE_ID in blade_intf_data[blade_intf].keys(): + if const.INSTANCE_ID not in blade_intf_data[blade_intf].keys(): blade_intf_data[blade_intf][const.INSTANCE_ID] = None - if not const.VIF_ID in blade_intf_data[blade_intf].keys(): + if const.VIF_ID not in blade_intf_data[blade_intf].keys(): blade_intf_data[blade_intf][const.VIF_ID] = None if (blade_intf_data[blade_intf][const.BLADE_INTF_LINK_STATE] == diff --git a/quantum/plugins/hyperv/agent/hyperv_quantum_agent.py b/quantum/plugins/hyperv/agent/hyperv_quantum_agent.py index 35d042a78..81e50437f 100644 --- a/quantum/plugins/hyperv/agent/hyperv_quantum_agent.py +++ b/quantum/plugins/hyperv/agent/hyperv_quantum_agent.py @@ -220,7 +220,7 @@ class HyperVQuantumAgent(object): def _port_unbound(self, port_id): (net_uuid, map) = self._get_network_vswitch_map_by_port_id(port_id) - if not net_uuid in self._network_vswitch_map: + if net_uuid not in self._network_vswitch_map: LOG.info(_('Network %s is not avalailable on this agent'), net_uuid) return diff --git a/quantum/plugins/linuxbridge/agent/linuxbridge_quantum_agent.py b/quantum/plugins/linuxbridge/agent/linuxbridge_quantum_agent.py index 56d11ccfd..75ba36324 100755 --- a/quantum/plugins/linuxbridge/agent/linuxbridge_quantum_agent.py +++ b/quantum/plugins/linuxbridge/agent/linuxbridge_quantum_agent.py @@ -414,7 +414,7 @@ class LinuxBridgeRpcCallbacks(sg_rpc.SecurityGroupAgentRpcCallbackMixin): port = kwargs.get('port') tap_device_name = self.agent.br_mgr.get_tap_device_name(port['id']) devices = self.agent.br_mgr.udev_get_tap_devices() - if not tap_device_name in devices: + if tap_device_name not in devices: return if 'security_groups' in port: diff --git a/quantum/plugins/metaplugin/meta_quantum_plugin.py b/quantum/plugins/metaplugin/meta_quantum_plugin.py index 6312f72ed..dccd1fe3e 100644 --- a/quantum/plugins/metaplugin/meta_quantum_plugin.py +++ b/quantum/plugins/metaplugin/meta_quantum_plugin.py @@ -87,12 +87,12 @@ class MetaPluginV2(db_base_plugin_v2.QuantumDbPluginV2, db._ENGINE = None self.default_flavor = cfg.CONF.META.default_flavor - if not self.default_flavor in self.plugins: + if self.default_flavor not in self.plugins: raise exc.Invalid(_('default_flavor %s is not plugin list') % self.default_flavor) self.default_l3_flavor = cfg.CONF.META.default_l3_flavor - if not self.default_l3_flavor in self.l3_plugins: + if self.default_l3_flavor not in self.l3_plugins: raise exc.Invalid(_('default_l3_flavor %s is not plugin list') % self.default_l3_flavor) @@ -114,12 +114,12 @@ class MetaPluginV2(db_base_plugin_v2.QuantumDbPluginV2, return plugin_klass() def _get_plugin(self, flavor): - if not flavor in self.plugins: + if flavor not in self.plugins: raise FlavorNotFound(flavor=flavor) return self.plugins[flavor] def _get_l3_plugin(self, flavor): - if not flavor in self.l3_plugins: + if flavor not in self.l3_plugins: raise FlavorNotFound(flavor=flavor) return self.l3_plugins[flavor] @@ -152,7 +152,7 @@ class MetaPluginV2(db_base_plugin_v2.QuantumDbPluginV2, def create_network(self, context, network): n = network['network'] flavor = n.get(FLAVOR_NETWORK) - if not str(flavor) in self.plugins: + if str(flavor) not in self.plugins: flavor = self.default_flavor plugin = self._get_plugin(flavor) with context.session.begin(subtransactions=True): @@ -238,7 +238,7 @@ class MetaPluginV2(db_base_plugin_v2.QuantumDbPluginV2, def create_port(self, context, port): p = port['port'] - if not 'network_id' in p: + if 'network_id' not in p: raise exc.NotFound plugin = self._get_plugin_by_network_id(context, p['network_id']) return plugin.create_port(context, port) @@ -260,7 +260,7 @@ class MetaPluginV2(db_base_plugin_v2.QuantumDbPluginV2, def create_subnet(self, context, subnet): s = subnet['subnet'] - if not 'network_id' in s: + if 'network_id' not in s: raise exc.NotFound plugin = self._get_plugin_by_network_id(context, s['network_id']) @@ -285,7 +285,7 @@ class MetaPluginV2(db_base_plugin_v2.QuantumDbPluginV2, def create_router(self, context, router): r = router['router'] flavor = r.get(FLAVOR_ROUTER) - if not str(flavor) in self.l3_plugins: + if str(flavor) not in self.l3_plugins: flavor = self.default_l3_flavor plugin = self._get_l3_plugin(flavor) with context.session.begin(subtransactions=True): diff --git a/quantum/plugins/nicira/nicira_nvp_plugin/QuantumPlugin.py b/quantum/plugins/nicira/nicira_nvp_plugin/QuantumPlugin.py index 1d21da3a9..51864393c 100644 --- a/quantum/plugins/nicira/nicira_nvp_plugin/QuantumPlugin.py +++ b/quantum/plugins/nicira/nicira_nvp_plugin/QuantumPlugin.py @@ -305,7 +305,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2, if allow_extra_lswitches: main_ls = [ls for ls in lswitches if ls['uuid'] == network.id] tag_dict = dict((x['scope'], x['tag']) for x in main_ls[0]['tags']) - if not 'multi_lswitch' in tag_dict: + if 'multi_lswitch' not in tag_dict: nvplib.update_lswitch(cluster, main_ls[0]['uuid'], main_ls[0]['display_name'], diff --git a/quantum/plugins/nicira/nicira_nvp_plugin/common/config.py b/quantum/plugins/nicira/nicira_nvp_plugin/common/config.py index c1fa6851f..aa8911427 100644 --- a/quantum/plugins/nicira/nicira_nvp_plugin/common/config.py +++ b/quantum/plugins/nicira/nicira_nvp_plugin/common/config.py @@ -132,7 +132,7 @@ def _retrieve_extra_groups(conf, key=None, delimiter=':'): results = [] for parsed_file in cfg.CONF._cparser.parsed: for parsed_item in parsed_file.keys(): - if not parsed_item in cfg.CONF: + if parsed_item not in cfg.CONF: items = key and parsed_item.split(delimiter) if not key or key == items[0]: results.append(parsed_item) diff --git a/quantum/tests/unit/test_servicetype.py b/quantum/tests/unit/test_servicetype.py index e2c937d35..160c806f9 100644 --- a/quantum/tests/unit/test_servicetype.py +++ b/quantum/tests/unit/test_servicetype.py @@ -283,7 +283,7 @@ class ServiceTypeManagerTestCase(ServiceTypeTestCaseBase): } if default: data[self.resource_name]['default'] = default - if not 'tenant_id' in data[self.resource_name]: + if 'tenant_id' not in data[self.resource_name]: data[self.resource_name]['tenant_id'] = 'fake' return self.api.post_json(_get_path('service-types'), data, expect_errors=expect_errors) diff --git a/quantum/wsgi.py b/quantum/wsgi.py index baa0e7298..5b052712b 100644 --- a/quantum/wsgi.py +++ b/quantum/wsgi.py @@ -192,7 +192,7 @@ class Request(webob.Request): def get_content_type(self): allowed_types = ("application/xml", "application/json") - if not "Content-Type" in self.headers: + if "Content-Type" not in self.headers: LOG.debug(_("Missing Content-Type")) return None type = self.content_type -- 2.45.2