Ejemplo n.º 1
0
def tmp_repo(tmpdir, monkeypatch):
    """
    Provide a temporary repo directory and patch vsdm to use it instead of
    /rhev/data-center.
    """
    # Create rhev/data-center directory in the tmpdir, so we don't mix
    # temporary files created by the same test in the data-center.
    data_center = str(tmpdir.mkdir("rhev").mkdir("data-center"))

    pool_id = str(uuid.uuid4())
    repo = tmprepo.TemporaryRepo(data_center, pool_id)

    # Patch repo directory.
    monkeypatch.setattr(sc, "REPO_DATA_CENTER", repo.path)
    monkeypatch.setattr(sc, "REPO_MOUNT_DIR", repo.mnt_dir)

    # Invalidate sdCache so stale data from previous test will affect
    # this test.
    sdCache.refresh()
    sdCache.knownSDs.clear()

    try:
        yield repo
    finally:
        # ioprocess is typically invoked from tests using tmp_repo. This
        # terminate ioprocess instances, avoiding thread and process leaks in
        # tests, and errors in __del__ during test shutdown.
        oop.stop()

        # Invalidate sdCache so stale data from this test will affect
        # the next test.
        sdCache.refresh()
        sdCache.knownSDs.clear()
Ejemplo n.º 2
0
def tmp_repo(tmpdir, monkeypatch):
    """
    Provide a temporary repo directory and patch vsdm to use it instead of
    /rhev/data-center.
    """
    # Create data-center directory in the tmpdir, so we don't mix temporary
    # files from other tests in the data-center.
    data_center = tmpdir.mkdir("data-center")
    mnt_dir = data_center.mkdir(sc.DOMAIN_MNT_POINT)

    # Patch repo directory.
    monkeypatch.setattr(sc, "REPO_DATA_CENTER", str(data_center))
    monkeypatch.setattr(sc, "REPO_MOUNT_DIR", str(mnt_dir))

    class tmp_repo:
        path = str(data_center)
        pool_id = str(uuid.uuid4())
        pool_path = str(data_center.join(pool_id))

    try:
        yield tmp_repo
    finally:
        # ioprocess is typically invoked from tests using tmp_repo. This
        # terminate ioprocess instances, avoiding thread and process leaks in
        # tests, and errors in __del__ during test shutdown.
        oop.stop()
Ejemplo n.º 3
0
def tmp_repo(tmpdir, monkeypatch, tmp_fs):
    """
    Provide a temporary repo directory and patch vsdm to use it instead of
    /rhev/data-center.
    """
    repo = tmprepo.TemporaryRepo(tmpdir, tmp_fs)

    # Patch repo directory.
    monkeypatch.setattr(sc, "REPO_DATA_CENTER", repo.path)
    monkeypatch.setattr(sc, "REPO_MOUNT_DIR", repo.mnt_dir)

    # Invalidate sdCache so stale data from previous test will affect
    # this test.
    sdCache.refresh()
    sdCache.knownSDs.clear()

    try:
        yield repo
    finally:
        # ioprocess is typically invoked from tests using tmp_repo. This
        # terminate ioprocess instances, avoiding thread and process leaks in
        # tests, and errors in __del__ during test shutdown.
        oop.stop()

        # Invalidate sdCache so stale data from this test will affect
        # the next test.
        sdCache.refresh()
        sdCache.knownSDs.clear()
Ejemplo n.º 4
0
def tmp_repo(tmpdir, monkeypatch):
    """
    Provide a temporary repo directory and patch vsdm to use it instead of
    /rhev/data-center.
    """
    repo = tmprepo.TemporaryRepo(tmpdir)

    # Patch repo directory.
    monkeypatch.setattr(sc, "REPO_DATA_CENTER", repo.path)
    monkeypatch.setattr(sc, "REPO_MOUNT_DIR", repo.mnt_dir)

    # Invalidate sdCache so stale data from previous test will affect
    # this test.
    sdCache.refresh()
    sdCache.knownSDs.clear()

    try:
        yield repo
    finally:
        # ioprocess is typically invoked from tests using tmp_repo. This
        # terminate ioprocess instances, avoiding thread and process leaks in
        # tests, and errors in __del__ during test shutdown.
        oop.stop()

        # Invalidate sdCache so stale data from this test will affect
        # the next test.
        sdCache.refresh()
        sdCache.knownSDs.clear()
Ejemplo n.º 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()
Ejemplo n.º 6
0
def storage(request):
    storage, alignment = request.param
    if not storage.exists():
        pytest.xfail("{} storage not available".format(storage.name))

    with open(storage.path, "w") as f:
        f.truncate(0)

    yield Storage(storage.path, storage.sector_size, alignment)
    oop.stop()
Ejemplo n.º 7
0
def async_task(called, task_id):
    task = Task(id=task_id)
    t = concurrent.thread(task.prepare, args=(called, ))
    t.start()
    try:
        called.wait_until_running()
        yield task
    finally:
        called.finish()
        t.join(timeout=1)
        oop.stop()
Ejemplo n.º 8
0
def task_manager(workers=1):
    tm = taskManager.TaskManager(tpSize=workers, waitTimeout=0.05)
    try:
        yield tm
    finally:
        # Stop all managed tasks without auto recovery
        for task_id in tm.getAllTasks():
            task = tm._getTask(task_id)
            task.setRecoveryPolicy("none")
            task.stop()
        tm.prepareForShutdown(wait=True)
        tm.unloadTasks()
        oop.stop()
Ejemplo n.º 9
0
def direct_file(request):
    """
    Returns a direct file factory function accpting a path. Test for
    xlease.*DirectFile can use this fixture for testing both implemntations.
    """
    if request.param == xlease.InterruptibleDirectFile:
        try:
            test_oop = oop.getProcessPool("test")
            yield functools.partial(request.param, oop=test_oop)
        finally:
            oop.stop()
    else:
        yield request.param
Ejemplo n.º 10
0
def direct_file(request):
    """
    Returns a direct file factory function accpting a path. Test for
    xlease.*DirectFile can use this fixture for testing both implemntations.
    """
    if request.param == xlease.InterruptibleDirectFile:
        try:
            test_oop = oop.getProcessPool("test")
            yield functools.partial(request.param, oop=test_oop)
        finally:
            oop.stop()
    else:
        yield request.param
Ejemplo n.º 11
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],
            [hsm, 'sdCache', fake_sdc],
        ]):
            fake_sdc.domains[sd_manifest.sdUUID] = FakeSD(sd_manifest)
            try:
                yield FakeFileEnv(tmpdir, sd_manifest, fake_sdc)
            finally:
                oop.stop()
Ejemplo n.º 12
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],
            [hsm, 'sdCache', fake_sdc],
        ]):
            fake_sdc.domains[sd_manifest.sdUUID] = FakeSD(sd_manifest)
            try:
                yield FakeFileEnv(tmpdir, sd_manifest, fake_sdc)
            finally:
                oop.stop()
Ejemplo n.º 13
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()
Ejemplo n.º 14
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),
            (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)
            try:
                yield FakeBlockEnv(tmpdir, sd_manifest, fake_sdc, lvm)
            finally:
                oop.stop()
Ejemplo n.º 15
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),
            (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)
            try:
                yield FakeBlockEnv(tmpdir, sd_manifest, fake_sdc, lvm)
            finally:
                oop.stop()
Ejemplo n.º 16
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()
Ejemplo n.º 17
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()
Ejemplo n.º 18
0
def tmp_repo(tmpdir, monkeypatch):
    """
    Provide a temporary repo directory and patch vsdm to use it instead of
    /rhev/data-center.
    """
    # Create rhev/data-center directory in the tmpdir, so we don't mix
    # temporary files created by the same test in the data-center.
    data_center = str(tmpdir.mkdir("rhev").mkdir("data-center"))

    pool_id = str(uuid.uuid4())
    repo = tmprepo.TemporaryRepo(data_center, pool_id)

    # Patch repo directory.
    monkeypatch.setattr(sc, "REPO_DATA_CENTER", repo.path)
    monkeypatch.setattr(sc, "REPO_MOUNT_DIR", repo.mnt_dir)

    try:
        yield repo
    finally:
        # ioprocess is typically invoked from tests using tmp_repo. This
        # terminate ioprocess instances, avoiding thread and process leaks in
        # tests, and errors in __del__ during test shutdown.
        oop.stop()
Ejemplo n.º 19
0
def tmp_repo(tmpdir, monkeypatch, tmp_fs):
    """
    Provide a temporary repo directory and patch vsdm to use it instead of
    /rhev/data-center.
    """
    repo = tmprepo.TemporaryRepo(tmpdir, tmp_fs)

    # Patch repo directory.
    monkeypatch.setattr(sc, "REPO_DATA_CENTER", repo.path)
    monkeypatch.setattr(sc, "REPO_MOUNT_DIR", repo.mnt_dir)

    # Patch multipath discovery and resize
    monkeypatch.setattr(multipath, "rescan", lambda: None)
    monkeypatch.setattr(multipath, "resize_devices", lambda: None)

    # Patch the resource manager.
    manager = rm._ResourceManager()
    manager.registerNamespace(sc.STORAGE, rm.SimpleResourceFactory())
    monkeypatch.setattr(rm, "_manager", manager)

    # Invalidate sdCache so stale data from previous test will affect
    # this test.
    sdCache.refresh()
    sdCache.knownSDs.clear()

    try:
        yield repo
    finally:
        # ioprocess is typically invoked from tests using tmp_repo. This
        # terminate ioprocess instances, avoiding thread and process leaks in
        # tests, and errors in __del__ during test shutdown.
        oop.stop()

        # Invalidate sdCache so stale data from this test will affect
        # the next test.
        sdCache.refresh()
        sdCache.knownSDs.clear()
Ejemplo n.º 20
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()
Ejemplo n.º 21
0
 def tearDown(self):
     # scanDomains is implemented using oop, leaving stale ioprocess child
     # processes.
     oop.stop()
Ejemplo n.º 22
0
def oop_ns():
    try:
        yield oop.getProcessPool("test")
    finally:
        oop.stop()
Ejemplo n.º 23
0
 def tearDown(self):
     oop.stop()
Ejemplo n.º 24
0
 def tearDown(self):
     # scanDomains is implemented using oop, leaving stale ioprocess child
     # processes.
     oop.stop()
Ejemplo n.º 25
0
 def tearDown(self):
     oop.stop()
Ejemplo n.º 26
0
def oop_ns():
    try:
        yield oop.getProcessPool("test")
    finally:
        oop.stop()
Ejemplo n.º 27
0
 def teardown_method(self, m):
     oop.stop()
Ejemplo n.º 28
0
def oop_cleanup():
    yield
    oop.stop()