]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix incorrect int/tuple comparison during binary search
authorAngus Lees <gus@inodes.org>
Thu, 28 Aug 2014 04:39:52 +0000 (14:39 +1000)
committerAngus Lees <gus@inodes.org>
Wed, 29 Oct 2014 01:05:40 +0000 (12:05 +1100)
The code contains an incorrect int/tuple comparison during the binary
search, which completely breaks the "priority" feature.
(Apparently python2 thinks int < tuple is not an error and always True.)

Change-Id: Ic404b38eabc87b105c7c2443b6177071b26d97ce
Closes-Bug: #1386946

neutron/plugins/bigswitch/tests/test_server.py

index 392ab92e9f14c7a2b80259a70bd48bbc3fe120df..4970435653ff0854dabd1fa61b202c0abaac7d21 100755 (executable)
@@ -45,12 +45,12 @@ class TestNetworkCtrl(object):
 
     def match(self, prior, method_regexp, uri_regexp, handler, data=None,
               multi=True):
-        """Add to the list of exptected inputs.
+        """Add to the list of expected inputs.
 
         The incoming request is matched in the order of priority. For same
         priority, match the oldest match request first.
 
-        :param prior: intgere priority of this match (e.g. 100)
+        :param prior: integer priority of this match (e.g. 100)
         :param method_regexp: regexp to match method (e.g. 'PUT|POST')
         :param uri_regexp: regexp to match uri (e.g. '/quantum/v?.?/')
         :param handler: function with signature:
@@ -75,7 +75,7 @@ class TestNetworkCtrl(object):
         lo, hi = 0, len(self.matches)
         while lo < hi:
             mid = (lo + hi) // 2
-            if prior < self.matches[mid]:
+            if prior < self.matches[mid][0]:
                 hi = mid
             else:
                 lo = mid + 1
@@ -91,8 +91,8 @@ class TestNetworkCtrl(object):
         retstatus = self.default_status
         retbody = self.default_response
         for i in moves.xrange(len(self.matches)):
-            (prior, method_regexp, uri_regexp, handler, data, multi) = \
-                self.matches[i]
+            (unused_prior, method_regexp, uri_regexp, handler, data,
+             multi) = self.matches[i]
             if re.match(method_regexp, method) and re.match(uri_regexp, uri):
                 kwargs = {
                     'data': data,