Revision d4fa5c23 test/ganeti.utils_unittest.py
b/test/ganeti.utils_unittest.py | ||
---|---|---|
99 | 99 |
"noexisting process detected") |
100 | 100 |
|
101 | 101 |
|
102 |
class TestLocking(unittest.TestCase): |
|
103 |
"""Testing case for the Lock/Unlock functions""" |
|
104 |
|
|
105 |
def setUp(self): |
|
106 |
lock_dir = tempfile.mkdtemp(prefix="ganeti.unittest.", |
|
107 |
suffix=".locking") |
|
108 |
self.old_lock_dir = constants.LOCK_DIR |
|
109 |
constants.LOCK_DIR = lock_dir |
|
110 |
|
|
111 |
def tearDown(self): |
|
112 |
try: |
|
113 |
ganeti.utils.Unlock("unittest") |
|
114 |
except LockError: |
|
115 |
pass |
|
116 |
shutil.rmtree(constants.LOCK_DIR, ignore_errors=True) |
|
117 |
constants.LOCK_DIR = self.old_lock_dir |
|
118 |
|
|
119 |
def clean_lock(self, name): |
|
120 |
try: |
|
121 |
ganeti.utils.Unlock("unittest") |
|
122 |
except LockError: |
|
123 |
pass |
|
124 |
|
|
125 |
|
|
126 |
def testLock(self): |
|
127 |
self.clean_lock("unittest") |
|
128 |
self.assertEqual(None, Lock("unittest")) |
|
129 |
|
|
130 |
|
|
131 |
def testUnlock(self): |
|
132 |
self.clean_lock("unittest") |
|
133 |
ganeti.utils.Lock("unittest") |
|
134 |
self.assertEqual(None, Unlock("unittest")) |
|
135 |
|
|
136 |
def testDoubleLock(self): |
|
137 |
self.clean_lock("unittest") |
|
138 |
ganeti.utils.Lock("unittest") |
|
139 |
self.assertRaises(LockError, Lock, "unittest") |
|
140 |
|
|
141 |
|
|
142 | 102 |
class TestRunCmd(unittest.TestCase): |
143 | 103 |
"""Testing case for the RunCmd function""" |
144 | 104 |
|
Also available in: Unified diff