From f08ea64233bb359852974d860b38e1eecaf44ea8 Mon Sep 17 00:00:00 2001 From: Petr Pudlak Date: Tue, 21 Oct 2014 11:37:35 +0200 Subject: [PATCH] Add a 'with' context for running tests with paused watcher The context is responsible for stopping and re-starting the watcher for the corresponding block of code. Signed-off-by: Petr Pudlak Reviewed-by: Helga Velroyen --- qa/qa_job_utils.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/qa/qa_job_utils.py b/qa/qa_job_utils.py index e0c7f3506..4c34e0675 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. -- GitLab