]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Enable undefined-loop-variable pylint check
authorAngus Lees <gus@inodes.org>
Wed, 13 Aug 2014 05:42:10 +0000 (15:42 +1000)
committerAngus Lees <gus@inodes.org>
Fri, 28 Nov 2014 00:40:41 +0000 (11:40 +1100)
This required a trivial refactor of two existing cases in the codebase.

These two cases were perfectly correct, but the check uncovered a 3rd
case which was a real bug (fixed separately).  The new versions also
make it clear that if the loop fails to break early then the 'result' is
None (and thus an error) and not simply the last element.  On balance,
it's probably worth enforcing this small inconvenience to coding style.

Change-Id: I780a95241f1454c6886d91f980eb9ada7678a119
Related-Bug: #1362466

.pylintrc
neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py
neutron/services/loadbalancer/drivers/haproxy/cfg.py

index 0c90b4ad3a4e8391a89f2d98ac684887e216e036..23a04a7d07f854cfd04e63317318507696147e58 100644 (file)
--- a/.pylintrc
+++ b/.pylintrc
@@ -56,7 +56,6 @@ disable=
  signature-differs,
  star-args,
  super-init-not-called,
- undefined-loop-variable,
  unnecessary-lambda,
  unnecessary-pass,
  unpacking-non-sequence,
index 3617d7ecc35e827c0d309af327e0f908149100a5..706f051040401fd3f262e93509f538e49ee7a343 100755 (executable)
@@ -523,15 +523,17 @@ class LinuxBridgeManager:
                          'command': 'bridge fdb',
                          'mode': 'VXLAN UCAST'})
             return False
-        for segmentation_id in moves.xrange(1, constants.MAX_VXLAN_VNI + 1):
+
+        test_iface = None
+        for seg_id in moves.xrange(1, constants.MAX_VXLAN_VNI + 1):
             if not ip_lib.device_exists(
-                    self.get_vxlan_device_name(segmentation_id)):
+                    self.get_vxlan_device_name(seg_id)):
+                test_iface = self.ensure_vxlan(seg_id)
                 break
         else:
             LOG.error(_LE('No valid Segmentation ID to perform UCAST test.'))
             return False
 
-        test_iface = self.ensure_vxlan(segmentation_id)
         try:
             utils.execute(
                 cmd=['bridge', 'fdb', 'append', constants.FLOODING_ENTRY[0],
index 1200cf80e7462424dad72ed1b4460229d4488c28..78e76eb908b98e2c32673d24bc121b990c6da988 100644 (file)
@@ -158,12 +158,13 @@ def _get_first_ip_from_port(port):
 
 def _get_server_health_option(config):
     """return the first active health option."""
-    for monitor in config['healthmonitors']:
+    for m in config['healthmonitors']:
         # not checking the status of healthmonitor for two reasons:
         # 1) status field is absent in HealthMonitor model
         # 2) only active HealthMonitors are fetched with
         # LoadBalancerCallbacks.get_logical_device
-        if monitor['admin_state_up']:
+        if m['admin_state_up']:
+            monitor = m
             break
     else:
         return '', []