Merge "getHoldRequest: pad zeros if not full length"
This commit is contained in:
commit
9e39c2b316
|
@ -2017,6 +2017,31 @@ class TestScheduler(ZuulTestCase):
|
||||||
request_list = self.scheds.first.sched.zk_nodepool.getHoldRequests()
|
request_list = self.scheds.first.sched.zk_nodepool.getHoldRequests()
|
||||||
self.assertEqual([], request_list)
|
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):
|
def _test_autohold_scoped(self, change_obj, change, ref):
|
||||||
client = zuul.rpcclient.RPCClient('127.0.0.1',
|
client = zuul.rpcclient.RPCClient('127.0.0.1',
|
||||||
self.gearman_server.port)
|
self.gearman_server.port)
|
||||||
|
|
|
@ -150,6 +150,19 @@ class ZooKeeperNodepool(ZooKeeperBase):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def getHoldRequest(self, hold_request_id):
|
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
|
path = self.HOLD_REQUEST_ROOT + "/" + hold_request_id
|
||||||
try:
|
try:
|
||||||
data, stat = self.kazoo_client.get(path)
|
data, stat = self.kazoo_client.get(path)
|
||||||
|
|
Loading…
Reference in New Issue