use the fact that empty sequences are false

fixed bug #1156473

Change-Id: I43470eb884107111cbea958868f4cf8241c8d6e6
This commit is contained in:
shu,xinxin 2013-03-21 18:48:00 +08:00
parent 9683664ff3
commit b1067c94c5
9 changed files with 24 additions and 24 deletions

View File

@ -91,7 +91,7 @@ class DhcpRpcCallbackMixin(object):
try:
filters = dict(network_id=[network_id], device_id=[device_id])
ports = plugin.get_ports(context, filters=filters)
if len(ports):
if ports:
# Ensure that fixed_ips cover all dhcp_enabled subnets.
port = ports[0]
for fixed_ip in port['fixed_ips']:
@ -144,7 +144,7 @@ class DhcpRpcCallbackMixin(object):
filters = dict(network_id=[network_id], device_id=[device_id])
ports = plugin.get_ports(context, filters=filters)
if len(ports):
if ports:
plugin.delete_port(context, ports[0]['id'])
def release_port_fixed_ip(self, context, **kwargs):
@ -160,7 +160,7 @@ class DhcpRpcCallbackMixin(object):
filters = dict(network_id=[network_id], device_id=[device_id])
ports = plugin.get_ports(context, filters=filters)
if len(ports):
if ports:
port = ports[0]
fixed_ips = port.get('fixed_ips', [])

View File

@ -221,7 +221,7 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
'admin_state_up': True,
'name': ''}})
if not len(gw_port['fixed_ips']):
if not gw_port['fixed_ips']:
self.delete_port(context.elevated(), gw_port['id'],
l3_port_check=False)
msg = (_('No IPs available for external network %s') %
@ -550,7 +550,7 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
raise q_exc.BadRequest(resource='floatingip', msg=msg)
else:
ips = [ip['ip_address'] for ip in internal_port['fixed_ips']]
if len(ips) == 0:
if not ips:
msg = (_('Cannot add floating IP to port %s that has'
'no fixed IP addresses') % internal_port['id'])
raise q_exc.BadRequest(resource='floatingip', msg=msg)

View File

@ -85,7 +85,7 @@ def _validate_servicetype_ref(data, valid_values=None):
def _validate_service_defs(data, valid_values=None):
""" Validate the list of service definitions. """
try:
if len(data) == 0:
if not data:
return _("No service type definition was provided. At least a "
"service type definition must be provided")
f_name = _validate_service_defs.__name__
@ -137,7 +137,7 @@ def _validate_service_defs(data, valid_values=None):
return msg
del svc_def_copy[DRIVER_ATTR]
# Anything left - it should be an error
if len(svc_def_copy):
if svc_def_copy:
msg = (_("Unparseable attributes found in "
"service definition %s") % svc_def)
LOG.error(_("%(f_name)s: %(msg)s"), locals())

View File

@ -72,7 +72,7 @@ class HyperVUtils(object):
def _get_vnic_settings(self, vnic_name):
vnic_settings = self._conn.Msvm_SyntheticEthernetPortSettingData(
ElementName=vnic_name)
if not len(vnic_settings):
if not vnic_settings:
raise HyperVException(msg=_('Vnic not found: %s') % vnic_name)
return vnic_settings[0]
@ -185,7 +185,7 @@ class HyperVUtils(object):
def _get_vswitch(self, vswitch_name):
vswitch = self._conn.Msvm_VirtualSwitch(ElementName=vswitch_name)
if not len(vswitch):
if not vswitch:
raise HyperVException(msg=_('VSwitch not found: %s') %
vswitch_name)
return vswitch[0]
@ -196,7 +196,7 @@ class HyperVUtils(object):
for vswitch_port in vswitch_ports:
lan_endpoints = vswitch_port.associators(
wmi_result_class='Msvm_SwitchLanEndpoint')
if len(lan_endpoints):
if lan_endpoints:
ext_port = lan_endpoints[0].associators(
wmi_result_class='Msvm_ExternalEthernetPort')
if ext_port:

View File

@ -354,7 +354,7 @@ class NECPluginV2(nec_plugin_base.NECPluginV2Base,
# delete unnessary ofc_tenant
filters = dict(tenant_id=[tenant_id])
nets = super(NECPluginV2, self).get_networks(context, filters=filters)
if len(nets) == 0:
if not nets:
try:
self.ofc.delete_ofc_tenant(context, tenant_id)
except (nexc.OFCException, nexc.OFCConsistencyBroken) as exc:

View File

@ -1048,7 +1048,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
except q_exc.NetworkNotFound:
continue
pairs.append((c, lswitches))
if len(pairs) == 0:
if not pairs:
raise q_exc.NetworkNotFound(net_id=netw_id)
LOG.debug(_("Returning pairs for network: %s"), pairs)
return pairs
@ -1172,7 +1172,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
# do not make the case in which switches are found in NVP
# but not in Quantum catastrophic.
if len(nvp_lswitches):
if nvp_lswitches:
LOG.warning(_("Found %s logical switches not bound "
"to Quantum networks. Quantum and NVP are "
"potentially out of sync"), len(nvp_lswitches))
@ -1304,7 +1304,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
lports.append(quantum_lport)
# do not make the case in which ports are found in NVP
# but not in Quantum catastrophic.
if len(nvp_lports):
if nvp_lports:
LOG.warning(_("Found %s logical ports not bound "
"to Quantum ports. Quantum and NVP are "
"potentially out of sync"), len(nvp_lports))
@ -1561,7 +1561,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
msg = (_("Network '%s' is not a valid external "
"network") % network_id)
raise q_exc.BadRequest(resource='router', msg=msg)
if len(ext_net.subnets):
if ext_net.subnets:
ext_subnet = ext_net.subnets[0]
nexthop = ext_subnet.gateway_ip
cluster = self._find_target_cluster(router)
@ -1610,7 +1610,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
msg = (_("Network '%s' is not a valid external "
"network") % network_id)
raise q_exc.BadRequest(resource='router', msg=msg)
if len(ext_net.subnets):
if ext_net.subnets:
ext_subnet = ext_net.subnets[0]
nexthop = ext_subnet.gateway_ip
cluster = self._find_target_cluster(router)
@ -1721,7 +1721,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
# do not make the case in which routers are found in NVP
# but not in Quantum catastrophic.
if len(nvp_lrouters):
if nvp_lrouters:
LOG.warning(_("Found %s logical routers not bound "
"to Quantum routers. Quantum and NVP are "
"potentially out of sync"), len(nvp_lrouters))
@ -1748,7 +1748,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
results = nvplib.query_lswitch_lports(
cluster, '*',
filters={'tag': port_id, 'tag_scope': 'q_port_id'})
if len(results):
if results:
ls_port = results[0]
else:
raise nvp_exc.NvpPluginException(
@ -1825,7 +1825,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
cluster, '*', relations="LogicalPortAttachment",
filters={'tag': port_id, 'tag_scope': 'q_port_id'})
lrouter_port_id = None
if len(results):
if results:
lport = results[0]
attachment_data = lport['_relations'].get('LogicalPortAttachment')
lrouter_port_id = (attachment_data and

View File

@ -95,7 +95,7 @@ def main(argv):
print "NVP Default Cluster Name %s" % nvp_opts.default_cluster_name
print "-----------Cluster Options--------------------"
if not len(clusters_opts):
if not clusters_opts:
print "No NVP Clusters detected in nvp.ini!"
exit(1)
clusters, default_cluster = QuantumPlugin.parse_clusters_opts(

View File

@ -137,7 +137,7 @@ def _build_uri_path(resource,
params.extend(['%s=%s' % (k, v) for (k, v) in filters.iteritems()])
uri_path = "%s/%s" % (URI_PREFIX, res_path)
non_empty_params = [x for x in params if x is not None]
if len(non_empty_params):
if non_empty_params:
query_string = '&'.join(non_empty_params)
if query_string:
uri_path += "?%s" % query_string
@ -1127,7 +1127,7 @@ def update_security_group_rules(cluster, spid, rules):
'port_range_max': constants.DHCP_RESPONSE_PORT,
'ip_prefix': '0.0.0.0/0'})
# If there are no ingress rules add bunk rule to drop all ingress traffic
if not len(rules['logical_port_ingress_rules']):
if not rules['logical_port_ingress_rules']:
rules['logical_port_ingress_rules'].append(
{'ethertype': 'IPv4', 'ip_prefix': '127.0.0.1/32'})
try:

View File

@ -437,7 +437,7 @@ class FakeClient:
self.SECPROF_RESOURCE in res_type or
'gatewayservice' in res_type):
LOG.debug("UUIDS:%s", uuids)
if len(uuids) > 0:
if uuids:
return self._show(res_type, response_file, uuids[0],
relations=relations)
else:
@ -461,7 +461,7 @@ class FakeClient:
if val_func:
val_func(body_json)
args = [body]
if len(uuids):
if uuids:
args.append(uuids[0])
response = response_template % add_resource(*args)
return response