Revision 99e222b1
b/lib/backend.py | ||
---|---|---|
64 | 64 |
from ganeti import compat |
65 | 65 |
from ganeti import pathutils |
66 | 66 |
from ganeti import vcluster |
67 |
from ganeti import ht |
|
67 | 68 |
|
68 | 69 |
|
69 | 70 |
_BOOT_ID_PATH = "/proc/sys/kernel/random/boot_id" |
... | ... | |
3768 | 3769 |
lock = None |
3769 | 3770 |
|
3770 | 3771 |
|
3772 |
def SetWatcherPause(until, _filename=pathutils.WATCHER_PAUSEFILE): |
|
3773 |
"""Creates or removes the watcher pause file. |
|
3774 |
|
|
3775 |
@type until: None or number |
|
3776 |
@param until: Unix timestamp saying until when the watcher shouldn't run |
|
3777 |
|
|
3778 |
""" |
|
3779 |
if until is None: |
|
3780 |
logging.info("Received request to no longer pause watcher") |
|
3781 |
utils.RemoveFile(_filename) |
|
3782 |
else: |
|
3783 |
logging.info("Received request to pause watcher until %s", until) |
|
3784 |
|
|
3785 |
if not ht.TNumber(until): |
|
3786 |
_Fail("Duration must be numeric") |
|
3787 |
|
|
3788 |
utils.WriteFile(_filename, data="%d\n" % (until, ), mode=0644) |
|
3789 |
|
|
3790 |
|
|
3771 | 3791 |
class HooksRunner(object): |
3772 | 3792 |
"""Hook runner. |
3773 | 3793 |
|
b/lib/rpc_defs.py | ||
---|---|---|
505 | 505 |
("hvname", None, "Hypervisor name"), |
506 | 506 |
("hvfull", None, "Parameters to be validated"), |
507 | 507 |
], None, None, "Validate hypervisor params"), |
508 |
("set_watcher_pause", MULTI, None, constants.RPC_TMO_URGENT, [ |
|
509 |
("until", None, None), |
|
510 |
], None, None, "Set watcher pause end"), |
|
508 | 511 |
] |
509 | 512 |
|
510 | 513 |
CALLS = { |
b/lib/server/noded.py | ||
---|---|---|
827 | 827 |
(values,) = params |
828 | 828 |
return ssconf.WriteSsconfFiles(values) |
829 | 829 |
|
830 |
@staticmethod |
|
831 |
def perspective_set_watcher_pause(params): |
|
832 |
"""Set watcher pause. |
|
833 |
|
|
834 |
""" |
|
835 |
(until, ) = params |
|
836 |
return backend.SetWatcherPause(until) |
|
837 |
|
|
830 | 838 |
# os ----------------------- |
831 | 839 |
|
832 | 840 |
@staticmethod |
b/test/ganeti.backend_unittest.py | ||
---|---|---|
482 | 482 |
self.fail("Did not raise exception") |
483 | 483 |
|
484 | 484 |
|
485 |
class TestSetWatcherPause(unittest.TestCase): |
|
486 |
def setUp(self): |
|
487 |
self.tmpdir = tempfile.mkdtemp() |
|
488 |
self.filename = utils.PathJoin(self.tmpdir, "pause") |
|
489 |
|
|
490 |
def tearDown(self): |
|
491 |
shutil.rmtree(self.tmpdir) |
|
492 |
|
|
493 |
def testUnsetNonExisting(self): |
|
494 |
self.assertFalse(os.path.exists(self.filename)) |
|
495 |
backend.SetWatcherPause(None, _filename=self.filename) |
|
496 |
self.assertFalse(os.path.exists(self.filename)) |
|
497 |
|
|
498 |
def testSetNonNumeric(self): |
|
499 |
for i in ["", [], {}, "Hello World", "0", "1.0"]: |
|
500 |
self.assertFalse(os.path.exists(self.filename)) |
|
501 |
|
|
502 |
try: |
|
503 |
backend.SetWatcherPause(i, _filename=self.filename) |
|
504 |
except backend.RPCFail, err: |
|
505 |
self.assertEqual(str(err), "Duration must be numeric") |
|
506 |
else: |
|
507 |
self.fail("Did not raise exception") |
|
508 |
|
|
509 |
self.assertFalse(os.path.exists(self.filename)) |
|
510 |
|
|
511 |
def testSet(self): |
|
512 |
self.assertFalse(os.path.exists(self.filename)) |
|
513 |
|
|
514 |
for i in range(10): |
|
515 |
backend.SetWatcherPause(i, _filename=self.filename) |
|
516 |
self.assertEqual(utils.ReadFile(self.filename), "%s\n" % i) |
|
517 |
self.assertEqual(os.stat(self.filename).st_mode & 0777, 0644) |
|
518 |
|
|
519 |
|
|
485 | 520 |
if __name__ == "__main__": |
486 | 521 |
testutils.GanetiTestProgram() |
Also available in: Unified diff