def test_release_not_acquired(self): fs = FakeSanlock() fs.write_resource("lockspace", "resource", [("path", 1048576)]) fs.add_lockspace("lockspace", 1, "path") fd = fs.register() with self.assertRaises(fs.SanlockException) as e: fs.release("lockspace", "resource", [("path", 1048576)], slkfd=fd) self.assertEqual(e.exception.errno, errno.EPERM)
def test_acquire(self): fs = FakeSanlock() fs.write_resource("lockspace", "resource", [("path", 1048576)]) fs.add_lockspace("lockspace", 1, "path") fd = fs.register() fs.acquire("lockspace", "resource", [("path", 1048576)], slkfd=fd) res = fs.read_resource("path", 1048576) self.assertTrue(res["acquired"], "resource is not acquired")
def test_add_lockspace_sync(self): fs = FakeSanlock() fs.add_lockspace("lockspace", 1, "path") ls = fs.spaces["lockspace"] self.assertEqual(ls["host_id"], 1) self.assertEqual(ls["path"], "path") self.assertEqual(ls["offset"], 0) self.assertEqual(ls["iotimeout"], 0) self.assertTrue(ls["ready"].is_set(), "lockspace is not ready")
def test_acquire_an_acquired_resource(self): fs = FakeSanlock() fs.write_resource("lockspace", "resource", [("path", 1048576)]) fs.add_lockspace("lockspace", 1, "path") fd = fs.register() fs.acquire("lockspace", "resource", [("path", 1048576)], slkfd=fd) with self.assertRaises(fs.SanlockException) as e: fs.acquire("lockspace", "resource", [("path", 1048576)], slkfd=fd) self.assertEqual(e.exception.errno, errno.EEXIST) res = fs.read_resource("path", 1048576) self.assertTrue(res["acquired"], "resource is not acquired")
def test_inq_lockspace_releasing_wait(self): fs = FakeSanlock() fs.add_lockspace("lockspace", 1, "path") fs.rem_lockspace("lockspace", 1, "path", async=True) t = concurrent.thread(fs.complete_async, args=("lockspace", )) t.start() try: acquired = fs.inq_lockspace("lockspace", 1, "path", wait=True) finally: t.join() self.assertFalse(acquired, "lockspace not released")
def test_inq_lockspace_released(self): fs = FakeSanlock() fs.add_lockspace("lockspace", 1, "path") fs.rem_lockspace("lockspace", 1, "path") acquired = fs.inq_lockspace("lockspace", 1, "path") self.assertFalse(acquired, "lockspace not released")
def test_inq_lockspace_acquired(self): fs = FakeSanlock() fs.add_lockspace("lockspace", 1, "path") acquired = fs.inq_lockspace("lockspace", 1, "path") self.assertTrue(acquired, "lockspace not acquired")
def test_rem_lockspace_async(self): fs = FakeSanlock() fs.add_lockspace("lockspace", 1, "path") fs.rem_lockspace("lockspace", 1, "path", async=True) ls = fs.spaces["lockspace"] self.assertFalse(ls["ready"].is_set(), "lockspace is ready")
def test_rem_lockspace_sync(self): fs = FakeSanlock() fs.add_lockspace("lockspace", 1, "path") fs.rem_lockspace("lockspace", 1, "path") self.assertNotIn("lockspace", fs.spaces)
def test_add_lockspace_options(self): fs = FakeSanlock() fs.add_lockspace("lockspace", 1, "path", offset=42, iotimeout=10) ls = fs.spaces["lockspace"] self.assertEqual(ls["offset"], 42) self.assertEqual(ls["iotimeout"], 10)
def test_inq_lockspace_releasing_no_wait(self): fs = FakeSanlock() fs.add_lockspace("lockspace", 1, "path") fs.rem_lockspace("lockspace", 1, "path", async=True) acquired = fs.inq_lockspace("lockspace", 1, "path") self.assertFalse(acquired, "lockspace not released")