From 742557d20dffb4325974f6ceceb4bab108281a17 Mon Sep 17 00:00:00 2001 From: Zhongyue Luo Date: Wed, 30 Jan 2013 16:57:20 +0800 Subject: [PATCH] Remove redunant key list generation in Cisco plugin Evaluates existance of key directly on dictionary. Fixes bug #1110957 Change-Id: I9b46a991ab9c764d7451cc122d208e06778c1ee1 --- .../plugins/cisco/models/network_multi_blade_v2.py | 10 ++++++---- quantum/plugins/cisco/models/virt_phy_sw_v2.py | 11 +++++++---- quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py | 9 ++++++--- quantum/plugins/cisco/services/services_logistics.py | 9 ++++++--- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/quantum/plugins/cisco/models/network_multi_blade_v2.py b/quantum/plugins/cisco/models/network_multi_blade_v2.py index e477632917..84bb43b736 100644 --- a/quantum/plugins/cisco/models/network_multi_blade_v2.py +++ b/quantum/plugins/cisco/models/network_multi_blade_v2.py @@ -1,6 +1,7 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2012 Cisco Systems, Inc. All rights reserved. + +# Copyright 2012 Cisco Systems, Inc. +# All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -15,6 +16,7 @@ # under the License. # # @author: Sumit Naiksatam, Cisco Systems, Inc. +# from copy import deepcopy import inspect @@ -74,7 +76,7 @@ class NetworkMultiBladeV2(quantum_plugin_base_v2.QuantumPluginBaseV2): Invokes a device plugin's relevant functions (on the it's inventory and plugin implementation) for completing this operation. """ - if not plugin_key in self._plugins.keys(): + if plugin_key not in self._plugins: LOG.info(_("No %s Plugin loaded"), plugin_key) LOG.info(_("%(plugin_key)s: %(function_name)s with args %(args)s " "ignored"), locals()) @@ -99,7 +101,7 @@ class NetworkMultiBladeV2(quantum_plugin_base_v2.QuantumPluginBaseV2): Invokes the relevant function on a device plugin's inventory for completing this operation. """ - if not plugin_key in self._inventory.keys(): + if plugin_key not in self._inventory: LOG.info(_("No %s inventory loaded"), plugin_key) LOG.info(_("%(plugin_key)s: %(function_name)s with args %(args)s " "ignored"), locals()) diff --git a/quantum/plugins/cisco/models/virt_phy_sw_v2.py b/quantum/plugins/cisco/models/virt_phy_sw_v2.py index ed2230c498..22a77e3498 100644 --- a/quantum/plugins/cisco/models/virt_phy_sw_v2.py +++ b/quantum/plugins/cisco/models/virt_phy_sw_v2.py @@ -1,6 +1,7 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2012 Cisco Systems, Inc. All rights reserved. + +# Copyright 2012 Cisco Systems, Inc. +# All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -16,6 +17,7 @@ # # @author: Sumit Naiksatam, Cisco Systems, Inc. # @author: Rohit Agarwalla, Cisco Systems, Inc. +# from copy import deepcopy import inspect @@ -34,6 +36,7 @@ from quantum.plugins.cisco import l2network_plugin_configuration as conf from quantum.plugins.openvswitch import ovs_db_v2 as odb from quantum import quantum_plugin_base_v2 + LOG = logging.getLogger(__name__) @@ -114,7 +117,7 @@ class VirtualPhysicalSwitchModelV2(quantum_plugin_base_v2.QuantumPluginBaseV2): Invokes a device plugin's relevant functions (on the it's inventory and plugin implementation) for completing this operation. """ - if not plugin_key in self._plugins.keys(): + if plugin_key not in self._plugins: LOG.info(_("No %s Plugin loaded"), plugin_key) LOG.info(_("%(plugin_key)s: %(function_name)s with args %(args)s " "ignored"), locals()) @@ -139,7 +142,7 @@ class VirtualPhysicalSwitchModelV2(quantum_plugin_base_v2.QuantumPluginBaseV2): Invokes the relevant function on a device plugin's inventory for completing this operation. """ - if not plugin_key in self._inventory.keys(): + if plugin_key not in self._inventory: LOG.info(_("No %s inventory loaded"), plugin_key) LOG.info(_("%(plugin_key)s: %(function_name)s with args %(args)s " "ignored"), locals()) diff --git a/quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py b/quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py index fb62ddc927..232bad945d 100644 --- a/quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py +++ b/quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py @@ -1,6 +1,7 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2012 Cisco Systems, Inc. All rights reserved. + +# Copyright 2012 Cisco Systems, Inc. +# All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -18,9 +19,11 @@ # @author: Edgar Magana, Cisco Systems, Inc. # @author: Arvind Somya, Cisco Systems, Inc. (asomya@cisco.com) # + """ PlugIn for Nexus OS driver """ + import logging from quantum.common import exceptions as exc @@ -55,7 +58,7 @@ class NexusPlugin(L2DevicePluginBase): self.credentials = {} def get_credential(self, nexus_ip): - if not nexus_ip in self.credentials.keys(): + if nexus_ip not in self.credentials: _nexus_username = cred.Store.get_username(nexus_ip) _nexus_password = cred.Store.get_password(nexus_ip) self.credentials[nexus_ip] = { diff --git a/quantum/plugins/cisco/services/services_logistics.py b/quantum/plugins/cisco/services/services_logistics.py index 57f8fc8e94..d09a67ee0d 100644 --- a/quantum/plugins/cisco/services/services_logistics.py +++ b/quantum/plugins/cisco/services/services_logistics.py @@ -1,6 +1,7 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2011 Cisco Systems, Inc. All rights reserved. + +# Copyright 2011 Cisco Systems, Inc. +# All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -15,6 +16,8 @@ # under the License. # # @author: Edgar Magana, Cisco Systems +# + """ Logistic components for Service Insertion utility """ @@ -109,7 +112,7 @@ class ServicesLogistics(): for key in conf.PLUGINS[const.PLUGINS].keys(): plugin_obj = conf.PLUGINS[const.PLUGINS][key] _plugins[key] = importutils.import_object(plugin_obj) - if not plugin_key in _plugins.keys(): + if plugin_key not in _plugins: LOG.debug(_("No %s Plugin loaded"), plugin_key) return False else: