示例#1
0
    def make_env(self, gluster_volume_info):
        sdcache = FakeStorageDomainCache()
        sdcache.domains['sd_id'] = FakeSD()

        svdsm = FakeSuperVdsm(gluster_volume_info)

        with MonkeyPatchScope([(glusterVolume, 'sdCache', sdcache),
                               (glusterVolume, 'svdsm', svdsm)]):
            yield
示例#2
0
文件: volume_test.py 项目: nirs/vdsm
 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__
示例#3
0
 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__)
示例#4
0
 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__
示例#5
0
def fake_file_env(obj=None,
                  sd_version=3,
                  data_center=None,
                  remote_path="server:/path"):
    with temp_dir(path=data_center) as tmpdir:
        mnt_dir = os.path.join(tmpdir, "mnt")
        local_path = fileUtils.transformPath(remote_path)
        mountpoint = os.path.join(mnt_dir, local_path)
        os.makedirs(mountpoint)

        fake_sdc = FakeStorageDomainCache()
        with MonkeyPatchScope([
            [sc, 'REPO_DATA_CENTER', tmpdir],
            [sc, 'REPO_MOUNT_DIR', mnt_dir],
            [volume, 'sdCache', fake_sdc],
            [fileVolume, 'sdCache', fake_sdc],
            [hsm, 'sdCache', fake_sdc],
            [nbd, 'sdCache', fake_sdc],
        ]):
            sd_manifest = make_filesd_manifest(mountpoint,
                                               sd_version=sd_version)
            fake_sdc.domains[sd_manifest.sdUUID] = FakeSD(sd_manifest)
            try:
                yield FakeFileEnv(tmpdir, sd_manifest, fake_sdc)
            finally:
                oop.stop()
示例#6
0
    def test_raw_to_qcow2_estimated_size(self, monkeypatch, sd_class):
        monkeypatch.setattr(image, "config", CONFIG)
        monkeypatch.setattr(
            qemuimg,
            'measure',
            # the estimated size for converting 1 gb
            # raw empty volume to qcow2 format
            # cmd:
            #   qemu-img measure -f raw -O qcow2 test.raw
            # output:
            #   required size: 393216
            #   fully allocated size: 1074135040
            lambda **args: {"required": 393216})
        monkeypatch.setattr(image, 'sdCache', FakeStorageDomainCache())

        image.sdCache.domains['sdUUID'] = sd_class("fake manifest")
        img = image.Image("/path/to/repo")

        vol_params = dict(capacity=GiB,
                          volFormat=sc.RAW_FORMAT,
                          path='path',
                          block=sd_class.is_block())
        estimated_size = img.estimate_qcow2_size(vol_params, "sdUUID")

        assert estimated_size == 1074135040
示例#7
0
def fake_file_env(obj=None, sd_version=3):
    with namedTemporaryDir() as tmpdir:
        sd_manifest = make_filesd_manifest(tmpdir, sd_version=sd_version)
        fake_sdc = FakeStorageDomainCache()
        with MonkeyPatchScope([
            [sd, 'storage_repository', tmpdir],
            [volume, 'sdCache', fake_sdc],
            [fileVolume, 'sdCache', fake_sdc],
            [hsm, 'sdCache', fake_sdc],
        ]):
            fake_sdc.domains[sd_manifest.sdUUID] = FakeSD(sd_manifest)
            try:
                yield FakeFileEnv(tmpdir, sd_manifest, fake_sdc)
            finally:
                oop.stop()
示例#8
0
def fake_file_env(obj=None, sd_version=3, mnt_dir="server:_path"):
    with namedTemporaryDir() as tmpdir:
        mountpoint = os.path.join(tmpdir, mnt_dir)
        os.mkdir(mountpoint)
        sd_manifest = make_filesd_manifest(mountpoint, sd_version=sd_version)
        fake_sdc = FakeStorageDomainCache()
        with MonkeyPatchScope([
            [sc, 'REPO_DATA_CENTER', tmpdir],
            [volume, 'sdCache', fake_sdc],
            [fileVolume, 'sdCache', fake_sdc],
            [hsm, 'sdCache', fake_sdc],
            [nbd, 'sdCache', fake_sdc],
        ]):
            fake_sdc.domains[sd_manifest.sdUUID] = FakeSD(sd_manifest)
            try:
                yield FakeFileEnv(tmpdir, sd_manifest, fake_sdc)
            finally:
                oop.stop()
示例#9
0
def monitor_env(shutdown=False, refresh=300):
    config = make_config([("irs", "repo_stats_cache_refresh_timeout",
                           str(refresh))])
    with MonkeyPatchScope([
        (monitor, "sdCache", FakeStorageDomainCache()),
        (monitor, 'config', config),
    ]):
        event = FakeEvent()
        checker = FakeCheckService()
        thread = monitor.MonitorThread('uuid', 'host_id', MONITOR_INTERVAL,
                                       event, checker)
        try:
            yield MonitorEnv(thread, event, checker)
        finally:
            thread.stop(shutdown=shutdown)
            try:
                thread.join()
            except RuntimeError as e:
                log.error("Error joining thread: %s", e)
示例#10
0
def fake_block_env(obj=None, sd_version=3):
    with namedTemporaryDir() as tmpdir:
        lvm = FakeLVM(tmpdir)
        fake_sdc = FakeStorageDomainCache()
        with MonkeyPatchScope([
            (blockSD, 'lvm', lvm),
            (blockVolume, 'lvm', lvm),
            (blockVolume, 'sdCache', fake_sdc),
            (volume_artifacts, 'lvm', lvm),
            (sd, 'storage_repository', tmpdir),
            (volume, 'sdCache', fake_sdc),
            (hsm, 'sdCache', fake_sdc),
        ]):
            sd_manifest = make_blocksd_manifest(tmpdir, lvm,
                                                sd_version=sd_version)
            fake_sdc.domains[sd_manifest.sdUUID] = FakeSD(sd_manifest, lvm)
            try:
                yield FakeBlockEnv(tmpdir, sd_manifest, fake_sdc, lvm)
            finally:
                oop.stop()
示例#11
0
def fake_block_env(obj=None, sd_version=3, data_center=None):
    with temp_dir(path=data_center) as tmpdir:
        lvm = FakeLVM(tmpdir)
        fake_sdc = FakeStorageDomainCache()
        with MonkeyPatchScope([
            (blockSD, 'lvm', lvm),
            (blockVolume, 'lvm', lvm),
            (blockVolume, 'sdCache', fake_sdc),
            (sc, 'REPO_DATA_CENTER', tmpdir),
            (sc, "REPO_MOUNT_DIR", os.path.join(tmpdir, sc.DOMAIN_MNT_POINT,
                                                sd.BLOCKSD_DIR)),
            (volume, 'sdCache', fake_sdc),
            (hsm, 'sdCache', fake_sdc),
            [nbd, 'sdCache', fake_sdc],
        ]):
            sd_manifest = make_blocksd_manifest(tmpdir, lvm,
                                                sd_version=sd_version)
            fake_sdc.domains[sd_manifest.sdUUID] = FakeSD(sd_manifest, lvm)
            try:
                yield FakeBlockEnv(tmpdir, sd_manifest, fake_sdc, lvm)
            finally:
                oop.stop()
示例#12
0
    def test_qcow2_to_qcow2_estimated_size(self, monkeypatch, sd_class):
        monkeypatch.setattr(image, "config", CONFIG)
        monkeypatch.setattr(
            qemuimg,
            'measure',
            # the estimated size for converting 1 gb
            # qcow2 empty volume to qcow2 format
            # cmd:
            #   qemu-img measure -f qcow2 -O qcow2 test.qcow2
            # output:
            #   required size: 393216
            #   fully allocated size: 1074135040
            lambda **args: {"required": 393216})
        monkeypatch.setattr(image, 'sdCache', FakeStorageDomainCache())

        image.sdCache.domains['sdUUID'] = sd_class("fake manifest")
        img = image.Image("/path/to/repo")

        vol_params = dict(size=constants.GIB,
                          volFormat=sc.COW_FORMAT,
                          path='path')
        estimated_size_blk = img.estimate_qcow2_size_blk(vol_params, "sdUUID")

        assert estimated_size_blk == 2097920
示例#13
0
 def test_manually_remove_domain(self):
     sdc = FakeStorageDomainCache()
     sdc.domains["uuid"] = "fake domain"
     sdc.manuallyRemoveDomain("uuid")
     self.assertRaises(se.StorageDomainDoesNotExist, sdc.produce, "uuid")
示例#14
0
 def test_produce_manifest(self):
     sdc = FakeStorageDomainCache()
     sdc.domains["uuid"] = FakeSD("fake manifest")
     self.assertEqual("fake manifest", sdc.produce_manifest("uuid"))
示例#15
0
 def test_produce(self):
     sdc = FakeStorageDomainCache()
     sdc.domains["uuid"] = "fake domain"
     self.assertEqual("fake domain", sdc.produce("uuid"))
示例#16
0
 def test_domain_does_not_exist(self):
     sdc = FakeStorageDomainCache()
     self.assertRaises(se.StorageDomainDoesNotExist, sdc.produce, "uuid")
示例#17
0
文件: fakelib_test.py 项目: nirs/vdsm
 def test_produce(self):
     sdc = FakeStorageDomainCache()
     sdc.domains["uuid"] = "fake domain"
     self.assertEqual("fake domain", sdc.produce("uuid"))
示例#18
0
文件: fakelib_test.py 项目: nirs/vdsm
 def test_produce_manifest(self):
     sdc = FakeStorageDomainCache()
     sdc.domains["uuid"] = FakeSD("fake manifest")
     self.assertEqual("fake manifest", sdc.produce_manifest("uuid"))
示例#19
0
文件: fakelib_test.py 项目: nirs/vdsm
 def test_manually_remove_domain(self):
     sdc = FakeStorageDomainCache()
     sdc.domains["uuid"] = "fake domain"
     sdc.manuallyRemoveDomain("uuid")
     self.assertRaises(se.StorageDomainDoesNotExist, sdc.produce, "uuid")