Commit 57efdaf5 authored by Hrvoje Ribicic's avatar Hrvoje Ribicic

Add an expected block option to RunWithLocks

To compensate for the cases where a QA test is supposed to block when
a lock is present, add an additional option showing whether blocking is
supposed to happen or not.
Signed-off-by: default avatarHrvoje Ribicic <riba@google.com>
Reviewed-by: default avatarPetr Pudlak <pudlak@google.com>
parent 34c5ec6c
......@@ -192,7 +192,7 @@ def _GetBlockingLocks():
# TODO: Can this be done as a decorator? Implement as needed.
def RunWithLocks(fn, locks, timeout, *args, **kwargs):
def RunWithLocks(fn, locks, timeout, block, *args, **kwargs):
""" Runs the given function, acquiring a set of locks beforehand.
@type fn: function
......@@ -202,6 +202,8 @@ def RunWithLocks(fn, locks, timeout, *args, **kwargs):
@type timeout: number
@param timeout: The number of seconds the locks should be held before
expiring.
@type block: bool
@param block: Whether the test should block when locks are used or not.
This function allows a set of locks to be acquired in preparation for a QA
test, to try and see if the function can run in parallel with other
......@@ -256,10 +258,13 @@ def RunWithLocks(fn, locks, timeout, *args, **kwargs):
qa_thread.join()
if test_blocked:
blocking_lock_names = map(lock_name_map.get, blocking_owned_locks)
raise qa_error.Error("QA test succeded, but was blocked by the locks: %s" %
", ".join(blocking_lock_names))
blocking_lock_names = ", ".join(map(lock_name_map.get, blocking_owned_locks))
if not block and test_blocked:
raise qa_error.Error("QA test succeded, but was blocked by locks: %s" %
blocking_lock_names)
elif block and not test_blocked:
raise qa_error.Error("QA test succeded, but was not blocked as it was "
"expected to by locks: %s" % blocking_lock_names)
else:
_TerminateDelayFunction(termination_socket)
......
......@@ -968,7 +968,7 @@ def TestInterClusterInstanceMove(src_instance, dest_instance,
# assures that this happens, and while we cannot be sure where the instance
# will land, it is a real move.
locks = {locking.LEVEL_NODE: [pnode.primary]}
RunWithLocks(_InvokeMoveInstance, locks, 600.0,
RunWithLocks(_InvokeMoveInstance, locks, 600.0, False,
dest_instance.name, src_instance.name, rapi_pw_file.name,
master.primary, perform_checks)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment