Error when enqueue-ref doesn't get long enough rev
The zuul executors (and the python git bindings they use) need full
length sha1 commit hashes. If you provide a short (or too long) hash
when attempting to enqueue a ref via the rpcclient the executors will
all fail and eventually you'll get a retry limit. We can avoid this
entirely if we error quickly and provide the user a nice error message.
Add a check for the old rev and new rev commit hash length. Additionally
check if the hash is a valid base 16 number. If not return a nice error
message.
Change-Id: Ia1cf4ac2bb87ce3248b34f246a6d6353df079dbf
diff --git a/tests/unit/test_scheduler.py b/tests/unit/test_scheduler.py
index c833fa2..b640e33 100755
--- a/tests/unit/test_scheduler.py
+++ b/tests/unit/test_scheduler.py
@@ -3577,6 +3577,56 @@
self.assertEqual(len(self.history), 0)
self.assertEqual(len(self.builds), 0)
+ def test_client_enqueue_ref_negative(self):
+ "Test that the RPC client returns errors"
+ client = zuul.rpcclient.RPCClient('127.0.0.1',
+ self.gearman_server.port)
+ self.addCleanup(client.shutdown)
+ with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
+ "New rev must be 40 character sha1"):
+ r = client.enqueue_ref(
+ tenant='tenant-one',
+ pipeline='post',
+ project='org/project',
+ trigger='gerrit',
+ ref='master',
+ oldrev='90f173846e3af9154517b88543ffbd1691f31366',
+ newrev='10054041')
+ self.assertEqual(r, False)
+ with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
+ "Old rev must be 40 character sha1"):
+ r = client.enqueue_ref(
+ tenant='tenant-one',
+ pipeline='post',
+ project='org/project',
+ trigger='gerrit',
+ ref='master',
+ oldrev='10054041',
+ newrev='90f173846e3af9154517b88543ffbd1691f31366')
+ self.assertEqual(r, False)
+ with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
+ "New rev must be base16 hash"):
+ r = client.enqueue_ref(
+ tenant='tenant-one',
+ pipeline='post',
+ project='org/project',
+ trigger='gerrit',
+ ref='master',
+ oldrev='90f173846e3af9154517b88543ffbd1691f31366',
+ newrev='notbase16')
+ self.assertEqual(r, False)
+ with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
+ "Old rev must be base16 hash"):
+ r = client.enqueue_ref(
+ tenant='tenant-one',
+ pipeline='post',
+ project='org/project',
+ trigger='gerrit',
+ ref='master',
+ oldrev='notbase16',
+ newrev='90f173846e3af9154517b88543ffbd1691f31366')
+ self.assertEqual(r, False)
+
def test_client_promote(self):
"Test that the RPC client can promote a change"
self.executor_server.hold_jobs_in_build = True