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()
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()
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()
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()
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()
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()
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()
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()
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
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()
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()
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()
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()
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()
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()
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()
def tearDown(self): # scanDomains is implemented using oop, leaving stale ioprocess child # processes. oop.stop()
def oop_ns(): try: yield oop.getProcessPool("test") finally: oop.stop()
def tearDown(self): oop.stop()
def teardown_method(self, m): oop.stop()
def oop_cleanup(): yield oop.stop()