Revision 383477e9 test/ganeti.jqueue_unittest.py
b/test/ganeti.jqueue_unittest.py | ||
---|---|---|
31 | 31 |
import random |
32 | 32 |
import operator |
33 | 33 |
|
34 |
try: |
|
35 |
# pylint: disable=E0611 |
|
36 |
from pyinotify import pyinotify |
|
37 |
except ImportError: |
|
38 |
import pyinotify |
|
39 |
|
|
34 | 40 |
from ganeti import constants |
35 | 41 |
from ganeti import utils |
36 | 42 |
from ganeti import errors |
... | ... | |
195 | 201 |
self._EnsureNotifierClosed(waiter._filewaiter._notifier) |
196 | 202 |
|
197 | 203 |
|
204 |
class _FailingWatchManager(pyinotify.WatchManager): |
|
205 |
"""Subclass of L{pyinotify.WatchManager} which always fails to register. |
|
206 |
|
|
207 |
""" |
|
208 |
def add_watch(self, filename, mask): |
|
209 |
assert mask == (pyinotify.EventsCodes.ALL_FLAGS["IN_MODIFY"] | |
|
210 |
pyinotify.EventsCodes.ALL_FLAGS["IN_IGNORED"]) |
|
211 |
|
|
212 |
return { |
|
213 |
filename: -1, |
|
214 |
} |
|
215 |
|
|
216 |
|
|
198 | 217 |
class TestWaitForJobChangesHelper(unittest.TestCase): |
199 | 218 |
def setUp(self): |
200 | 219 |
self.tmpdir = tempfile.mkdtemp() |
... | ... | |
228 | 247 |
self.assert_(wfjc(self.filename, self._LoadLostJob, |
229 | 248 |
["status"], None, None, 1.0) is None) |
230 | 249 |
|
250 |
def testNonExistentFile(self): |
|
251 |
wfjc = jqueue._WaitForJobChangesHelper() |
|
252 |
|
|
253 |
filename = utils.PathJoin(self.tmpdir, "does-not-exist") |
|
254 |
self.assertFalse(os.path.exists(filename)) |
|
255 |
|
|
256 |
result = wfjc(filename, self._LoadLostJob, ["status"], None, None, 1.0, |
|
257 |
_waiter_cls=compat.partial(jqueue._JobChangesWaiter, |
|
258 |
_waiter_cls=NotImplemented)) |
|
259 |
self.assertTrue(result is None) |
|
260 |
|
|
261 |
def testInotifyError(self): |
|
262 |
jobfile_waiter_cls = \ |
|
263 |
compat.partial(jqueue._JobFileChangesWaiter, |
|
264 |
_inotify_wm_cls=_FailingWatchManager) |
|
265 |
|
|
266 |
jobchange_waiter_cls = \ |
|
267 |
compat.partial(jqueue._JobChangesWaiter, _waiter_cls=jobfile_waiter_cls) |
|
268 |
|
|
269 |
wfjc = jqueue._WaitForJobChangesHelper() |
|
270 |
|
|
271 |
# Test if failing to watch a job file (e.g. due to |
|
272 |
# fs.inotify.max_user_watches being too low) raises errors.InotifyError |
|
273 |
self.assertRaises(errors.InotifyError, wfjc, |
|
274 |
self.filename, self._LoadWaitingJob, |
|
275 |
["status"], [constants.JOB_STATUS_WAITING], None, 1.0, |
|
276 |
_waiter_cls=jobchange_waiter_cls) |
|
277 |
|
|
231 | 278 |
|
232 | 279 |
class TestEncodeOpError(unittest.TestCase): |
233 | 280 |
def test(self): |
Also available in: Unified diff