From 320b4e2dc5bf691d1de6daea514f43d424d396e5 Mon Sep 17 00:00:00 2001 From: Alexander Schreiber <als@google.com> Date: Mon, 3 Dec 2007 14:32:24 +0000 Subject: [PATCH] Fix the unittest for locking. Reviewed-by: imsnah --- test/ganeti.utils_unittest.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/ganeti.utils_unittest.py b/test/ganeti.utils_unittest.py index 020365626..560c7aca7 100755 --- a/test/ganeti.utils_unittest.py +++ b/test/ganeti.utils_unittest.py @@ -26,6 +26,7 @@ import os import time import tempfile import os.path +import os import md5 import socket import shutil @@ -89,6 +90,21 @@ class TestIsProcessAlive(unittest.TestCase): class TestLocking(unittest.TestCase): """Testing case for the Lock/Unlock functions""" + + def setUp(self): + lock_dir = tempfile.mkdtemp(prefix="ganeti.unittest.", + suffix=".locking") + self.old_lock_dir = constants.LOCK_DIR + constants.LOCK_DIR = lock_dir + + def tearDown(self): + try: + ganeti.utils.Unlock("unittest") + except LockError: + pass + shutil.rmtree(constants.LOCK_DIR, ignore_errors=True) + constants.LOCK_DIR = self.old_lock_dir + def clean_lock(self, name): try: ganeti.utils.Unlock("unittest") @@ -106,7 +122,6 @@ class TestLocking(unittest.TestCase): ganeti.utils.Lock("unittest") self.assertEqual(None, Unlock("unittest")) - def testDoubleLock(self): self.clean_lock("unittest") ganeti.utils.Lock("unittest") -- GitLab