def test_acquire(self): image = vm.Image("test", "/vmimage") o = object() image.acquire(o) self.assertIs(image.master, o) exc = self.assertRaises(errors.LockedImageError, image.acquire, object()) self.assertEqual(exc.args, (image, o)) image.acquire(o)
def test_release(self): image = vm.Image("test", "/vmimage") exc = self.assertRaises(errors.LockedImageError, image.release, object()) self.assertEqual(exc.args, (image, None)) image.release(None) o = object() image.acquire(o) image.release(o) self.assertRaises(errors.LockedImageError, image.release, o)
def test_release(self): self.assertFalse(self.disk.cow) self.assertIs(self.disk.image, None) self.assertFalse(self.vm.config["snapshot"]) self.disk.release() image = vm.Image("test", "/vmimage") self.vm.set({"snapshot": False, "privatehda": False}) self.disk.set_image(image) self.disk.acquire() self.disk.release()
def new_disk_image(self, name, path, description=""): """Add one disk image to the library.""" logger.info(create_image, path=path) path = os.path.abspath(path) self.assert_path_not_in_use(path) img = virtualmachines.Image(self.normalize_name(name), path, description) self.disk_images.append(img) self._notify("image-added", img) return img
def test_acquire(self): self.assertFalse(self.disk.cow) self.assertIs(self.disk.image, None) self.assertFalse(self.vm.config["snapshot"]) self.disk.acquire() image = vm.Image("test", "/vmimage") self.vm.set({"snapshot": False, "privatehda": False}) self.disk.set_image(image) self.disk.acquire() self.assertIs(image.master, self.disk) disk = DiskStub(self.vm, "hdb") disk.set_image(image) self.assertRaises(errors.LockedImageError, disk.acquire)
def test_lock(self): self.vm.acquire() self.vm.release() image = vm.Image("test", "/vmimage") disk = DiskStub(self.vm, "hdb") disk.set_image(image) disk.acquire() self.vm.config["hda"].set_image(image) self.assertRaises(errors.LockedImageError, self.vm.acquire) _image = _Image() self.vm.config["hdb"].set_image(_image) try: self.vm.acquire() except errors.LockedImageError: pass else: self.fail("vm lock acquired but it should not happend") self.assertEqual(_image.acquired, _image.released)
def setUp(self): self.factory = stubs.FactoryStub() self.vm = stubs.VirtualMachineStub(self.factory, "vm") self.image_path = os.path.abspath(self.mktemp()) self.image = vm.Image("test", self.image_path) self.vm.get("hda").set_image(self.image)