def test_repr(self): lock = volume.VolumeLease(HOST_ID, 'dom', 'img', 'vol') lock_string = str(lock) self.assertIn("VolumeLease", lock_string) self.assertIn("ns=04_lease_dom", lock_string) self.assertIn("name=vol", lock_string) self.assertIn("mode=exclusive", lock_string) self.assertIn("%x" % id(lock), lock_string)
def expected_locks(self, subchain): img_ns = rm.getNamespace(sc.IMAGE_NAMESPACE, subchain.sd_id) return [ rm.ResourceManagerLock(sc.STORAGE, subchain.sd_id, rm.SHARED), rm.ResourceManagerLock(img_ns, subchain.img_id, rm.EXCLUSIVE), volume.VolumeLease(subchain.host_id, subchain.sd_id, subchain.img_id, subchain.base_id) ]
def test_repr(self): lock = volume.VolumeLease(HOST_ID, 'dom', 'img', 'vol') lock_string = str(lock) assert "VolumeLease" in lock_string assert "ns=04_lease_dom" in lock_string assert "name=vol" in lock_string assert "mode=exclusive" in lock_string assert "%x" % id(lock) in lock_string
def locks(self): img_ns = rm.getNamespace(sc.IMAGE_NAMESPACE, self.sd_id) ret = [rm.ResourceManagerLock(sc.STORAGE, self.sd_id, rm.SHARED), rm.ResourceManagerLock(img_ns, self.img_id, rm.EXCLUSIVE)] dom = sdCache.produce_manifest(self.sd_id) if dom.hasVolumeLeases(): ret.append(volume.VolumeLease(self._host_id, self.sd_id, self.img_id, self.vol_id)) return ret
def locks(self): img_ns = rm.getNamespace(sc.IMAGE_NAMESPACE, self.sd_id) ret = [rm.ResourceManagerLock(sc.STORAGE, self.sd_id, rm.SHARED), rm.ResourceManagerLock(img_ns, self.img_id, rm.EXCLUSIVE)] dom = sdCache.produce_manifest(self.sd_id) if dom.hasVolumeLeases(): # We take only the base lease since no other volumes are modified ret.append(volume.VolumeLease(self.host_id, self.sd_id, self.img_id, self.base_id)) return ret
def locks(self): img_ns = rm.getNamespace(sc.IMAGE_NAMESPACE, self.sd_id) mode = rm.EXCLUSIVE if self._writable else rm.SHARED ret = [rm.Lock(sc.STORAGE, self.sd_id, rm.SHARED), rm.Lock(img_ns, self.img_id, mode)] if self._writable: dom = sdCache.produce_manifest(self.sd_id) if dom.hasVolumeLeases(): ret.append(volume.VolumeLease(self._host_id, self.sd_id, self.img_id, self.vol_id)) return ret
def expected_locks(self, base_vol): img_ns = rm.getNamespace(sc.IMAGE_NAMESPACE, base_vol.sdUUID) ret = [ # Domain lock rm.ResourceManagerLock(sc.STORAGE, base_vol.sdUUID, rm.SHARED), # Image lock rm.ResourceManagerLock(img_ns, base_vol.imgUUID, rm.EXCLUSIVE), # Volume lease volume.VolumeLease( 0, base_vol.sdUUID, base_vol.imgUUID, base_vol.volUUID) ] return ret
def test_acquire_release(self): sdcache = FakeStorageDomainCache() manifest = FakeSDManifest() sdcache.domains['dom'] = FakeSD(manifest) expected = [('acquireVolumeLease', (HOST_ID, 'img', 'vol'), {}), ('releaseVolumeLease', ('img', 'vol'), {})] with MonkeyPatchScope([(volume, 'sdCache', sdcache)]): lock = volume.VolumeLease(HOST_ID, 'dom', 'img', 'vol') lock.acquire() self.assertEqual(expected[:1], manifest.__calls__) lock.release() self.assertEqual(expected, manifest.__calls__)
def test_acquire_release(self, monkeypatch): sdcache = FakeStorageDomainCache() manifest = FakeSDManifest() sdcache.domains['dom'] = FakeSD(manifest) expected = [('acquireVolumeLease', (HOST_ID, 'img', 'vol'), {}), ('releaseVolumeLease', ('img', 'vol'), {})] monkeypatch.setattr(volume, 'sdCache', sdcache) lock = volume.VolumeLease(HOST_ID, 'dom', 'img', 'vol') lock.acquire() assert expected[:1] == manifest.__calls__ lock.release() assert expected == manifest.__calls__
def expected_locks(src_vol, dst_vol): src_img_ns = rm.getNamespace(sc.IMAGE_NAMESPACE, src_vol.sdUUID) dst_img_ns = rm.getNamespace(sc.IMAGE_NAMESPACE, dst_vol.sdUUID) ret = [ # Domain lock for each volume rm.Lock(sc.STORAGE, src_vol.sdUUID, rm.SHARED), rm.Lock(sc.STORAGE, dst_vol.sdUUID, rm.SHARED), # Image lock for each volume, exclusive for the destination rm.Lock(src_img_ns, src_vol.imgUUID, rm.SHARED), rm.Lock(dst_img_ns, dst_vol.imgUUID, rm.EXCLUSIVE), # Volume lease for the destination volume volume.VolumeLease(0, dst_vol.sdUUID, dst_vol.imgUUID, dst_vol.volUUID) ] return ret
def locks(self): # A shared lock is always required ret = [rm.Lock(sc.STORAGE, self.sd_id, rm.SHARED)] # An exclusive lock will be taken if source and destination images # are not the same, otherwise there will be a deadlock. if self.lock_image: img_ns = rm.getNamespace(sc.IMAGE_NAMESPACE, self.sd_id) mode = rm.EXCLUSIVE if self._writable else rm.SHARED ret.append(rm.Lock(img_ns, self.img_id, mode)) if self._writable: dom = sdCache.produce_manifest(self.sd_id) if dom.hasVolumeLeases(): ret.append( volume.VolumeLease(self._host_id, self.sd_id, self.img_id, self.vol_id)) return ret
def test_equality_different_host_id(self): a = volume.VolumeLease(0, 'dom', 'img', 'vol') b = volume.VolumeLease(1, 'dom', 'img', 'vol') self.assertEqual(a, b)
def test_equality_different_image(self): a = volume.VolumeLease(HOST_ID, 'dom', 'img1', 'vol') b = volume.VolumeLease(HOST_ID, 'dom', 'img2', 'vol') self.assertEqual(a, b)
def test_equality(self): a = volume.VolumeLease(HOST_ID, 'dom', 'img', 'vol') b = volume.VolumeLease(HOST_ID, 'dom', 'img', 'vol') self.assertEqual(a, b)
def test_less_than(self, a, b): b = volume.VolumeLease(HOST_ID, *b) a = volume.VolumeLease(HOST_ID, *a) self.assertLess(a, b)
def test_properties(self): a = volume.VolumeLease(HOST_ID, 'dom', 'img', 'vol') self.assertEqual(rm.getNamespace(sc.VOLUME_LEASE_NAMESPACE, 'dom'), a.ns) self.assertEqual('vol', a.name) self.assertEqual(rm.EXCLUSIVE, a.mode)
def test_equality(self): a = volume.VolumeLease(HOST_ID, 'dom', 'img', 'vol') b = volume.VolumeLease(HOST_ID, 'dom', 'img', 'vol') assert a == b
def test_properties(self): a = volume.VolumeLease(HOST_ID, 'dom', 'img', 'vol') assert rm.getNamespace(sc.VOLUME_LEASE_NAMESPACE, 'dom') == a.ns assert 'vol' == a.name assert rm.EXCLUSIVE == a.mode