diff --git a/qa/qa_job_utils.py b/qa/qa_job_utils.py index e0c7f3506b3ae8e8b1bf634ae26dc5fbe492deb7..4c34e0675ba55114aafa6ce13187683d395dad0a 100644 --- a/qa/qa_job_utils.py +++ b/qa/qa_job_utils.py @@ -44,6 +44,7 @@ from ganeti import utils from ganeti.utils import retry import qa_config +import qa_logging import qa_error from qa_utils import AssertCommand, GetCommandOutput, GetObjectInfo @@ -315,6 +316,26 @@ class QAThreadGroup(object): thread.reraise() +class PausedWatcher(object): + """Pauses the watcher for the duration of the inner code + + """ + def __enter__(self): + AssertCommand(["gnt-cluster", "watcher", "pause", "12h"]) + + def __exit__(self, _ex_type, ex_value, _ex_traceback): + try: + AssertCommand(["gnt-cluster", "watcher", "continue"]) + except qa_error.Error, err: + # If an exception happens during 'continue', re-raise it only if there + # is no exception from the inner block: + if ex_value is None: + raise + else: + print qa_logging.FormatError('Re-enabling watcher failed: %s' % + (err, )) + + # TODO: Can this be done as a decorator? Implement as needed. def RunWithLocks(fn, locks, timeout, block, *args, **kwargs): """ Runs the given function, acquiring a set of locks beforehand.