]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
use the fact that empty sequences are false
authorshu,xinxin <xinxin.shu@intel.com>
Thu, 21 Mar 2013 10:48:00 +0000 (18:48 +0800)
committershu,xinxin <xinxin.shu@intel.com>
Thu, 21 Mar 2013 13:07:07 +0000 (21:07 +0800)
fixed bug #1156473

Change-Id: I43470eb884107111cbea958868f4cf8241c8d6e6

quantum/db/dhcp_rpc_base.py
quantum/db/l3_db.py
quantum/extensions/servicetype.py
quantum/plugins/hyperv/agent/utils.py
quantum/plugins/nec/nec_plugin.py
quantum/plugins/nicira/nicira_nvp_plugin/QuantumPlugin.py
quantum/plugins/nicira/nicira_nvp_plugin/check_nvp_config.py
quantum/plugins/nicira/nicira_nvp_plugin/nvplib.py
quantum/tests/unit/nicira/fake_nvpapiclient.py

index 08b8c99c243a0d8cb67a60e5eeeb86ff0ddf32f8..ea4a5a5f7e6aee5d32b4b05b63ad9f21ca23403a 100644 (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', [])
index e21e8b4dc677dccf5667552f84847608fb83f609..70d1ab4fdd857aa9008481e6ac7a6f3013d0f95e 100644 (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)
index 3d43f7f6326478b31c4604eb582a7a02754061ad..0468d1f885b49db8ca8b9e74d0da714d62af7229 100644 (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())
index a49248682bb0b401f5f730be8385585d672b683c..703b617656277baadcbf31b994f0b1d562f286cd 100644 (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:
index d2cd6e6a9ba88fb4269a52b50407e166cee8041f..5e230371f82b2779362142f913a943edb2d953ee 100644 (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:
index abc9ac191f84de1bc3a441ed99d711192a1e7687..ea8017e2339f9bb4512c3caf182fcd85d7b80ef9 100644 (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
index 16af11337d3352c79fe55342ade9400e9003e7a7..49e7f021c73898c51ecaf644a7d23d58d9f2631f 100644 (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(
index c07a7bc2d197dc9b7520a2427e7191f624ccedcf..d7f3cf5e231c8af9a234974baf1585514083af3d 100644 (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:
index 0ddae758534ec505d8b4a1598d11cfe8685e49c3..f9106fd16092295a184b2f23205bbc80d9f1e7a5 100644 (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