Commit f08ea642 authored by Petr Pudlak's avatar Petr Pudlak

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: default avatarPetr Pudlak <pudlak@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent 09ff6a25
......@@ -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.
......
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