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 test_produce_non_existing_volume(self): sd = FakeSD("fake manifest") self.assertRaises(se.VolumeDoesNotExist, sd.produceVolume, "img_uuid", "vol_uuid")
def test_produce_existing_volume(self): fake_vol = FakeVolume() sd = FakeSD("fake manifest") sd.volumes = {("img_uuid", "vol_uuid"): fake_vol} vol = sd.produceVolume("img_uuid", "vol_uuid") self.assertIs(vol, fake_vol)
def test_produce_manifest(self): sdc = FakeStorageDomainCache() sdc.domains["uuid"] = FakeSD("fake manifest") self.assertEqual("fake manifest", sdc.produce_manifest("uuid"))