Browse Source

Merge "getHoldRequest: pad zeros if not full length"

changes/15/788915/2
Zuul 1 month ago
committed by Gerrit Code Review
parent
commit
9e39c2b316
2 changed files with 38 additions and 0 deletions
  1. +25
    -0
      tests/unit/test_scheduler.py
  2. +13
    -0
      zuul/zk/nodepool.py

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

@ -2017,6 +2017,31 @@ class TestScheduler(ZuulTestCase):
request_list = self.scheds.first.sched.zk_nodepool.getHoldRequests()
self.assertEqual([], request_list)
def test_autohold_padding(self):
client = zuul.rpcclient.RPCClient('127.0.0.1',
self.gearman_server.port)
self.addCleanup(client.shutdown)
r = client.autohold('tenant-one', 'org/project', 'project-test2',
"", "", "reason text", 1)
self.assertTrue(r)
# There should be a record in ZooKeeper
request_list = self.scheds.first.sched.zk_nodepool.getHoldRequests()
self.assertEqual(1, len(request_list))
request = self.scheds.first.sched.zk_nodepool.getHoldRequest(
request_list[0])
self.assertIsNotNone(request)
# Assert the ID leads with a bunch of zeros, them strip them
# off to test autohold_delete can handle a user passing in an
# ID without leading zeros.
self.assertEqual(request.id[0:5], '00000')
trimmed_request = request.id[5:]
# Delete and verify no more requests
self.assertTrue(client.autohold_delete(trimmed_request))
request_list = self.scheds.first.sched.zk_nodepool.getHoldRequests()
self.assertEqual([], request_list)
def _test_autohold_scoped(self, change_obj, change, ref):
client = zuul.rpcclient.RPCClient('127.0.0.1',
self.gearman_server.port)


+ 13
- 0
zuul/zk/nodepool.py View File

@ -150,6 +150,19 @@ class ZooKeeperNodepool(ZooKeeperBase):
return []
def getHoldRequest(self, hold_request_id):
# To be friendly, zero pad if this request came from a client
# call, where the user might have done "zuul autohold-delete
# 123" thinking that would match the "0000000123" shown in
# "autohold-list".
#
# "A sequential node will be given the specified path plus a
# suffix i where i is the current sequential number of the
# node. The sequence number is always fixed length of 10
# digits, 0 padded. Once such a node is created, the
# sequential number will be incremented by one."
if len(hold_request_id) != 10:
hold_request_id = hold_request_id.rjust(10, '0')
path = self.HOLD_REQUEST_ROOT + "/" + hold_request_id
try:
data, stat = self.kazoo_client.get(path)


Loading…
Cancel
Save