Fixes if statement inefficiency in quantum.agent.linux.interface

Changed logic of checking the existance of a port value

Change-Id: Id06447a753fd0201ef44a047657bd747ce18d546
This commit is contained in:
Zhongyue Luo 2013-01-30 16:07:46 +08:00
parent abdb32c377
commit 46e5c83c88

View File

@ -28,6 +28,7 @@ from quantum.openstack.common import cfg
from quantum.openstack.common import importutils
from quantum.openstack.common import log as logging
LOG = logging.getLogger(__name__)
OPTS = [
@ -269,7 +270,7 @@ class MetaInterfaceDriver(LinuxInterfaceDriver):
device = ip_lib.IPDevice(device_name, self.conf.root_helper, namespace)
mac_address = device.link.address
ports = self.quantum.list_ports(mac_address=mac_address)
if not 'ports' in ports or len(ports['ports']) < 1:
if not ports.get('ports'):
raise Exception(_('No port for this device %s') % device_name)
return self._get_driver_by_network_id(ports['ports'][0]['network_id'])