Exemplo n.º 1
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()
Exemplo n.º 2
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()
Exemplo n.º 3
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)
Exemplo n.º 4
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()
Exemplo n.º 5
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()
Exemplo n.º 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')
        estimated_size = img.estimate_qcow2_size(vol_params, "sdUUID")

        assert estimated_size == 1074135040
Exemplo n.º 7
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()
Exemplo n.º 8
0
 def test_manually_remove_domain(self):
     sdc = FakeStorageDomainCache()
     sdc.domains["uuid"] = "fake domain"
     sdc.manuallyRemoveDomain("uuid")
     self.assertRaises(se.StorageDomainDoesNotExist, sdc.produce, "uuid")
Exemplo n.º 9
0
 def test_produce_manifest(self):
     sdc = FakeStorageDomainCache()
     sdc.domains["uuid"] = FakeSD("fake manifest")
     self.assertEqual("fake manifest", sdc.produce_manifest("uuid"))
Exemplo n.º 10
0
 def test_produce(self):
     sdc = FakeStorageDomainCache()
     sdc.domains["uuid"] = "fake domain"
     self.assertEqual("fake domain", sdc.produce("uuid"))
Exemplo n.º 11
0
 def test_domain_does_not_exist(self):
     sdc = FakeStorageDomainCache()
     self.assertRaises(se.StorageDomainDoesNotExist, sdc.produce, "uuid")