Browse Source

Fix updating relative priority

This code path was untested and had some typos.  Correct them and
ensure the path is tested.

Change-Id: Ib4a283f739b12295f480684b9b93ad8a60abf350
tags/3.4.0
James E. Blair 5 months ago
parent
commit
505c32e4b2
No account linked to committer's email address
3 changed files with 25 additions and 3 deletions
  1. 19
    0
      tests/unit/test_scheduler.py
  2. 5
    2
      zuul/manager/__init__.py
  3. 1
    1
      zuul/zk.py

+ 19
- 0
tests/unit/test_scheduler.py View File

@@ -5149,6 +5149,7 @@ For CI problems and help debugging, contact ci@example.org"""
5149 5149
         self.fake_nodepool.unpause()
5150 5150
         self.waitUntilSettled()
5151 5151
 
5152
+    @simple_layout('layouts/two-projects-integrated.yaml')
5152 5153
     def test_nodepool_relative_priority_check(self):
5153 5154
         "Test that nodes are requested at the relative priority"
5154 5155
 
@@ -5182,6 +5183,24 @@ For CI problems and help debugging, contact ci@example.org"""
5182 5183
         self.assertEqual(reqs[2]['_oid'], '200-0000000001')
5183 5184
         self.assertEqual(reqs[2]['relative_priority'], 1)
5184 5185
 
5186
+        # Fulfill only the first request
5187
+        self.fake_nodepool.fulfillRequest(reqs[0])
5188
+        for x in iterate_timeout(30, 'fulfill request'):
5189
+            self.log.debug(len(self.sched.nodepool.requests))
5190
+            if len(self.sched.nodepool.requests) < 3:
5191
+                break
5192
+        self.waitUntilSettled()
5193
+
5194
+        reqs = self.fake_nodepool.getNodeRequests()
5195
+
5196
+        # Change B, now first change for project, equal priority.
5197
+        self.assertEqual(reqs[0]['_oid'], '200-0000000001')
5198
+        self.assertEqual(reqs[0]['relative_priority'], 0)
5199
+
5200
+        # Change C, now first change for project1, equal priority.
5201
+        self.assertEqual(reqs[1]['_oid'], '200-0000000002')
5202
+        self.assertEqual(reqs[1]['relative_priority'], 0)
5203
+
5185 5204
         self.fake_nodepool.unpause()
5186 5205
         self.waitUntilSettled()
5187 5206
 

+ 5
- 2
zuul/manager/__init__.py View File

@@ -88,7 +88,10 @@ class PipelineManager(object):
88 88
     def getNodePriority(self, item):
89 89
         items = self.pipeline.getAllItems()
90 90
         items = [i for i in items if i.change.project == item.change.project]
91
-        return items.index(item)
91
+        for idx, val in enumerate(items):
92
+            if item == val:
93
+                return idx
94
+        return len(items)
92 95
 
93 96
     def isChangeAlreadyInPipeline(self, change):
94 97
         # Checks live items in the pipeline
@@ -700,7 +703,7 @@ class PipelineManager(object):
700 703
             priority = item.getNodePriority()
701 704
             for node_request in item.current_build_set.node_requests.values():
702 705
                 if node_request.relative_priority != priority:
703
-                    self.sched.nodepool.reviseNodeRequest(
706
+                    self.sched.nodepool.reviseRequest(
704 707
                         node_request, priority)
705 708
         return (changed, nnfi)
706 709
 

+ 1
- 1
zuul/zk.py View File

@@ -217,7 +217,7 @@ class ZooKeeper(object):
217 217
         :param NodeRequest node_request: The request to update.
218 218
         '''
219 219
 
220
-        path = '%s/%s' % (self.NODE_REQUEST_ROOT, node_request.id)
220
+        path = '%s/%s' % (self.REQUEST_ROOT, node_request.id)
221 221
         self.client.set(path, self._dictToStr(node_request.toDict()))
222 222
 
223 223
     def updateNodeRequest(self, node_request, data=None):

Loading…
Cancel
Save