Merge "Store a list of held nodes per held build in hold request"

This commit is contained in:
Zuul 2019-10-24 21:04:45 +00:00 committed by Gerrit Code Review
commit 678b8bb6e3
5 changed files with 26 additions and 4 deletions

View File

@ -1797,6 +1797,7 @@ class TestScheduler(ZuulTestCase):
request2 = self.zk.getHoldRequest(request.id)
self.assertEqual(request.current_count + 1, request2.current_count)
self.assertEqual(1, len(request2.nodes))
self.assertEqual(1, len(request2.nodes[0]["nodes"]))
# Another failed change should not hold any more nodes
C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')

View File

@ -4727,6 +4727,16 @@ class HoldRequest(object):
# When max_count == current_count, hold request can no longer be used.
self.max_count = 1
self.current_count = 0
# The hold request 'nodes' attribute is a list of dictionaries
# (one list entry per hold request count) containing the build
# ID (build) and a list of nodes (nodes) held for that build.
# Example:
#
# hold_request.nodes = [
# { 'build': 'ca01...', 'nodes': ['00000001', '00000002'] },
# { 'build': 'fb72...', 'nodes': ['00000003', '00000004'] },
# ]
self.nodes = []
def __str__(self):

View File

@ -169,7 +169,7 @@ class Nodepool(object):
except Exception:
log.exception("Unable to unlock node request %s", request)
def holdNodeSet(self, nodeset, request):
def holdNodeSet(self, nodeset, request, build):
'''
Perform a hold on the given set of nodes.
@ -192,7 +192,10 @@ class Nodepool(object):
node.hold_expiration = request.node_expiration
self.sched.zk.storeNode(node)
request.nodes += [node.id for node in nodes]
request.nodes.append(dict(
build=build.uuid,
nodes=[node.id for node in nodes],
))
request.current_count += 1
# Request has been used at least the maximum number of times so set

View File

@ -1436,7 +1436,7 @@ class Scheduler(threading.Thread):
request = self._getAutoholdRequest(build)
self.log.debug("Got autohold %s", request)
if request is not None:
self.nodepool.holdNodeSet(build.nodeset, request)
self.nodepool.holdNodeSet(build.nodeset, request, build)
def _doBuildCompletedEvent(self, event):
build = event.build

View File

@ -585,10 +585,18 @@ class ZooKeeper(object):
def _markHeldNodesAsUsed(self, hold_request):
'''
Changes the state for each held node for the hold request to 'used'.
:returns: True if all nodes marked USED, False otherwise.
'''
def getHeldNodeIDs(request):
node_ids = []
for data in request.nodes:
node_ids += data['nodes']
return node_ids
failure = False
for node_id in hold_request.nodes:
for node_id in getHeldNodeIDs(hold_request):
node = self.getNode(node_id)
if not node or node['state'] == zuul.model.STATE_USED:
continue