From e0321f0daa395508b00ede277ad0cae938e009dc Mon Sep 17 00:00:00 2001 From: Simon Westphahl Date: Thu, 14 Mar 2019 15:27:28 +0100 Subject: [PATCH] Ensure correct lexical sorting of node requests The recently introduced change to request child nodes of paused jobs with a higher priority causes the priority to be actually lower in case the pipeline precedence is set to 'high'. Due to the lexical sorting of node requests in Nodepool, 99 will be treated as the lowest prio in this case. This is especially apparent when Nodepool is up against quota. Change-Id: I094dee4f357c9974b6d9e95fcd70b02115d9de93 --- .../config/job-pause-priority/git/common-config/zuul.yaml | 1 + tests/unit/test_v3.py | 4 ++-- zuul/zk.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/fixtures/config/job-pause-priority/git/common-config/zuul.yaml b/tests/fixtures/config/job-pause-priority/git/common-config/zuul.yaml index a07342e2ec..1480b90051 100644 --- a/tests/fixtures/config/job-pause-priority/git/common-config/zuul.yaml +++ b/tests/fixtures/config/job-pause-priority/git/common-config/zuul.yaml @@ -2,6 +2,7 @@ name: check manager: independent post-review: true + precedence: high trigger: gerrit: - event: patchset-created diff --git a/tests/unit/test_v3.py b/tests/unit/test_v3.py index c0c5d6c565..075f77611a 100644 --- a/tests/unit/test_v3.py +++ b/tests/unit/test_v3.py @@ -5265,7 +5265,7 @@ class TestJobPausePriority(AnsibleZuulTestCase): reqs = self.fake_nodepool.getNodeRequests() self.assertEqual(len(reqs), 1) - self.assertEqual(reqs[0]['_oid'], '200-0000000000') + self.assertEqual(reqs[0]['_oid'], '100-0000000000') self.assertEqual(reqs[0]['provider'], None) self.fake_nodepool.unpause() @@ -5280,7 +5280,7 @@ class TestJobPausePriority(AnsibleZuulTestCase): break self.assertEqual(len(reqs), 1) - self.assertEqual(reqs[0]['_oid'], '199-0000000001') + self.assertEqual(reqs[0]['_oid'], '099-0000000001') self.assertEqual(reqs[0]['provider'], 'test-provider') self.fake_nodepool.unpause() diff --git a/zuul/zk.py b/zuul/zk.py index d35a5df1ac..433fc983fe 100644 --- a/zuul/zk.py +++ b/zuul/zk.py @@ -166,7 +166,7 @@ class ZooKeeper(object): node_request.created_time = time.time() data = node_request.toDict() - path = '%s/%s-' % (self.REQUEST_ROOT, node_request.priority) + path = '{}/{:0>3}-'.format(self.REQUEST_ROOT, node_request.priority) path = self.client.create(path, self._dictToStr(data), makepath=True, sequence=True, ephemeral=True)