def setup(monkeysession): if not tool_exists("lvs"): pytest.skip("LVM is not found") temp_file_name = tempfile.NamedTemporaryFile(delete=False).name subprocess.run( ["dd", "if=/dev/zero", f"of={temp_file_name}", "bs=1M", "count=100"], stderr=subprocess.STDOUT, check=True, ) loopback_file = ( subprocess.check_output( ["losetup", "-f", "--show", temp_file_name], stderr=subprocess.STDOUT ) .decode() .strip("\n") ) # v is being added in start to ensure the lvm volume group starts with a letter # don't know if it is required or not volume_group = "v" + "".join( secrets.choice(string.ascii_letters + string.digits) for i in range(5) ) # pvcreate is automatically used by this internally subprocess.check_output( ["vgcreate", volume_group, loopback_file], stderr=subprocess.STDOUT ) def install_patch(): return InstallInfo( vcpus=1, memory=512, storage_backend="lvm", disk_size="25M", iso_path=None, # not being required zfs_tank_name=None, lvm_volume_group=volume_group, enable_unattended=None, iso_sha256=None, ) monkeysession.setattr(InstallInfo, "load", install_patch) monkeysession.setattr(InstallInfo, "try_load", install_patch) yield subprocess.run(["vgchange", "-an", volume_group], stderr=subprocess.STDOUT) subprocess.run(["vgremove", "-y", volume_group], stderr=subprocess.STDOUT) subprocess.run(["losetup", "-d", loopback_file], stderr=subprocess.STDOUT) safe_delete(temp_file_name)
def setup(monkeysession): if not tool_exists('lvs'): pytest.skip("LVM is not found") temp_file_name = tempfile.NamedTemporaryFile(delete=False).name subprocess.run( ['dd', 'if=/dev/zero', f'of={temp_file_name}', 'bs=1M', 'count=100'], stderr=subprocess.STDOUT, check=True) loopback_file = subprocess.check_output( ['losetup', '-f', '--show', temp_file_name], stderr=subprocess.STDOUT).decode().strip('\n') # v is being added in start to ensure the lvm volume group starts with a letter # don't know if it is required or not volume_group = 'v' + ''.join( secrets.choice(string.ascii_letters + string.digits) for i in range(5)) # pvcreate is automatically used by this internally subprocess.check_output(['vgcreate', volume_group, loopback_file], stderr=subprocess.STDOUT) def install_patch(): return InstallInfo( vcpus=1, memory=512, storage_backend='lvm', disk_size='25M', iso_path=None, # not being required zfs_tank_name=None, lvm_volume_group=volume_group, enable_unattended=None, iso_sha256=None) monkeysession.setattr(InstallInfo, "load", install_patch) monkeysession.setattr(InstallInfo, "try_load", install_patch) yield subprocess.run(['vgchange', '-an', volume_group], stderr=subprocess.STDOUT) subprocess.run(['vgremove', '-y', volume_group], stderr=subprocess.STDOUT) subprocess.run(['losetup', '-d', loopback_file], stderr=subprocess.STDOUT) safe_delete(temp_file_name)
def patch(monkeysession): if not tool_exists("xl"): pytest.skip("xen is not found") def install_patch(): return InstallInfo( vcpus=1, memory=512, storage_backend="qcow2", disk_size="200M", iso_path=None, # not being required zfs_tank_name=None, lvm_volume_group=None, enable_unattended=None, iso_sha256=None, ) monkeysession.setattr(InstallInfo, "load", install_patch) monkeysession.setattr(InstallInfo, "try_load", install_patch) # being yielded so the the monkeypatch doesn't start cleanup if returned yield monkeysession