# Create VG by using iscsi device lv_utils.vg_create(vg_name, iscsi_device) cleanup_logical = True except Exception, detail: if cleanup_iscsi: utils_test.libvirt.setup_or_cleanup_iscsi(False) raise error.TestFail("iscsi setup failed:\n%s" % detail) # Run virsh cmd options = "%s %s " % (source_host, source_port) + options if ro_flag: logging.debug("Readonly mode test") try: cmd_result = virsh.find_storage_pool_sources_as(source_type, options, ignore_status=True, debug=True, readonly=ro_flag) output = cmd_result.stdout.strip() err = cmd_result.stderr.strip() status = cmd_result.exit_status if not status_error: if status: raise error.TestFail(err) else: logging.debug("Command outout:\n%s", output) elif status_error and status == 0: raise error.TestFail("Expect fail, but run successfully") finally: # Clean up if cleanup_logical:
def run(test, params, env): """ Test command: virsh find-storage-pool-sources-as 1. Prepare env to provide source storage: 1). For 'netfs' source type, setup nfs server 2). For 'iscsi' source type, setup iscsi server 3). For 'logcial' type pool, setup iscsi storage to create vg 2. Find the pool source by running virsh cmd """ source_type = params.get("source_type", "") source_host = params.get("source_host", "127.0.0.1") source_port = params.get("source_port", "") options = params.get("extra_options", "") vg_name = params.get("vg_name", "virttest_vg_0") ro_flag = "yes" == params.get("readonly_mode", "no") status_error = "yes" == params.get("status_error", "no") if not source_type: raise exceptions.TestFail("Command requires <type> value") cleanup_nfs = False cleanup_iscsi = False cleanup_logical = False if source_host == "127.0.0.1": if source_type == "netfs": # Set up nfs res = utils_test.libvirt.setup_or_cleanup_nfs(True) selinux_bak = res["selinux_status_bak"] cleanup_nfs = True if source_type in ["iscsi", "logical"]: # Set up iscsi try: iscsi_device = utils_test.libvirt.setup_or_cleanup_iscsi(True) # If we got nothing, force failure if not iscsi_device: raise exceptions.TestFail("Did not setup an iscsi device") cleanup_iscsi = True if source_type == "logical": # Create VG by using iscsi device lv_utils.vg_create(vg_name, iscsi_device) cleanup_logical = True except Exception as detail: if cleanup_iscsi: utils_test.libvirt.setup_or_cleanup_iscsi(False) raise exceptions.TestFail("iscsi setup failed:\n%s" % detail) # Run virsh cmd options = "%s %s " % (source_host, source_port) + options if ro_flag: logging.debug("Readonly mode test") try: cmd_result = virsh.find_storage_pool_sources_as(source_type, options, ignore_status=True, debug=True, readonly=ro_flag) utils_test.libvirt.check_exit_status(cmd_result, status_error) finally: # Clean up if cleanup_logical: cmd = "pvs |grep %s |awk '{print $1}'" % vg_name pv_name = to_text(process.system_output(cmd, shell=True)) lv_utils.vg_remove(vg_name) process.run("pvremove %s" % pv_name) if cleanup_iscsi: utils_test.libvirt.setup_or_cleanup_iscsi(False) if cleanup_nfs: utils_test.libvirt.setup_or_cleanup_nfs( False, restore_selinux=selinux_bak)
def create_pool(): """ Define and start a pool. """ sp = libvirt_storage.StoragePool() if create_by_xml: p_xml = pool_xml.PoolXML(pool_type=pool_type) p_xml.name = pool_name s_xml = pool_xml.SourceXML() s_xml.vg_name = disk_src_pool source_host = [] for (host_name, host_port) in zip(disk_src_host.split(), disk_src_port.split()): source_host.append({'name': host_name, 'port': host_port}) s_xml.hosts = source_host if auth_type: s_xml.auth_type = auth_type if auth_user: s_xml.auth_username = auth_user if auth_usage: s_xml.secret_usage = auth_usage p_xml.source = s_xml logging.debug("Pool xml: %s", p_xml) p_xml.xmltreefile.write() ret = virsh.pool_define(p_xml.xml, **virsh_dargs) libvirt.check_exit_status(ret) ret = virsh.pool_build(pool_name, **virsh_dargs) libvirt.check_exit_status(ret) ret = virsh.pool_start(pool_name, **virsh_dargs) libvirt.check_exit_status(ret) else: auth_opt = "" if client_name and client_key: auth_opt = ( "--auth-type %s --auth-username %s --secret-usage '%s'" % (auth_type, auth_user, auth_usage)) if not sp.define_rbd_pool( pool_name, mon_host, disk_src_pool, extra=auth_opt): test.fail("Failed to define storage pool") if not sp.build_pool(pool_name): test.fail("Failed to build storage pool") if not sp.start_pool(pool_name): test.fail("Failed to start storage pool") # Check pool operation ret = virsh.pool_refresh(pool_name, **virsh_dargs) libvirt.check_exit_status(ret) ret = virsh.pool_uuid(pool_name, **virsh_dargs) libvirt.check_exit_status(ret) # pool-info pool_info = sp.pool_info(pool_name) if pool_info["Autostart"] != 'no': test.fail("Failed to check pool information") # pool-autostart if not sp.set_pool_autostart(pool_name): test.fail("Failed to set pool autostart") pool_info = sp.pool_info(pool_name) if pool_info["Autostart"] != 'yes': test.fail("Failed to check pool information") # pool-autostart --disable if not sp.set_pool_autostart(pool_name, "--disable"): test.fail("Failed to set pool autostart") # If port is not pre-configured, port value should not be hardcoded in pool information. if "yes" == params.get("rbd_port", "no"): if 'port' in virsh.pool_dumpxml(pool_name): test.fail("port attribute should not be in pool information") # find-storage-pool-sources-as if "yes" == params.get("find_storage_pool_sources_as", "no"): ret = virsh.find_storage_pool_sources_as("rbd", mon_host) libvirt.check_result(ret, skip_if=unsupported_err)
def run(test, params, env): """ Test command: virsh find-storage-pool-sources-as 1. Prepare env to provide source storage: 1). For 'netfs' source type, setup nfs server 2). For 'iscsi' source type, setup iscsi server 3). For 'logcial' type pool, setup iscsi storage to create vg 2. Find the pool source by running virsh cmd """ source_type = params.get("source_type", "") source_host = params.get("source_host", "127.0.0.1") source_port = params.get("source_port", "") options = params.get("extra_options", "") vg_name = params.get("vg_name", "virttest_vg_0") ro_flag = "yes" == params.get("readonly_mode", "no") status_error = "yes" == params.get("status_error", "no") if not source_type: raise exceptions.TestFail("Command requires <type> value") cleanup_nfs = False cleanup_iscsi = False cleanup_logical = False if source_host == "127.0.0.1": if source_type == "netfs": # Set up nfs res = utils_test.libvirt.setup_or_cleanup_nfs(True) selinux_bak = res["selinux_status_bak"] cleanup_nfs = True if source_type in ["iscsi", "logical"]: # Set up iscsi try: iscsi_device = utils_test.libvirt.setup_or_cleanup_iscsi(True) # If we got nothing, force failure if not iscsi_device: raise exceptions.TestFail("Did not setup an iscsi device") cleanup_iscsi = True if source_type == "logical": # Create VG by using iscsi device lv_utils.vg_create(vg_name, iscsi_device) cleanup_logical = True except Exception as detail: if cleanup_iscsi: utils_test.libvirt.setup_or_cleanup_iscsi(False) raise exceptions.TestFail("iscsi setup failed:\n%s" % detail) # Run virsh cmd options = "%s %s " % (source_host, source_port) + options if ro_flag: logging.debug("Readonly mode test") try: cmd_result = virsh.find_storage_pool_sources_as( source_type, options, ignore_status=True, debug=True, readonly=ro_flag) utils_test.libvirt.check_exit_status(cmd_result, status_error) finally: # Clean up if cleanup_logical: cmd = "pvs |grep %s |awk '{print $1}'" % vg_name pv_name = to_text(process.system_output(cmd, shell=True)) lv_utils.vg_remove(vg_name) process.run("pvremove %s" % pv_name) if cleanup_iscsi: utils_test.libvirt.setup_or_cleanup_iscsi(False) if cleanup_nfs: utils_test.libvirt.setup_or_cleanup_nfs( False, restore_selinux=selinux_bak)
# Create VG by using iscsi device lv_utils.vg_create(vg_name, iscsi_device) cleanup_logical = True except Exception, detail: if cleanup_iscsi: utils_test.libvirt.setup_or_cleanup_iscsi(False) raise exceptions.TestFail("iscsi setup failed:\n%s" % detail) # Run virsh cmd options = "%s %s " % (source_host, source_port) + options if ro_flag: logging.debug("Readonly mode test") try: cmd_result = virsh.find_storage_pool_sources_as( source_type, options, ignore_status=True, debug=True, readonly=ro_flag) utils_test.libvirt.check_exit_status(cmd_result, status_error) finally: # Clean up if cleanup_logical: cmd = "pvs |grep %s |awk '{print $1}'" % vg_name pv_name = process.system_output(cmd, shell=True) lv_utils.vg_remove(vg_name) process.run("pvremove %s" % pv_name) if cleanup_iscsi: utils_test.libvirt.setup_or_cleanup_iscsi(False) if cleanup_nfs: utils_test.libvirt.setup_or_cleanup_nfs( False, restore_selinux=selinux_bak)
def run(test, params, env): """ Test command: virsh find-storage-pool-sources-as 1. Prepare env to provide source storage: 1). For 'netfs' source type, setup nfs server 2). For 'iscsi' source type, setup iscsi server 3). For 'logcial' type pool, setup iscsi storage to create vg 2. Find the pool source by running virsh cmd """ source_type = params.get("source_type", "") source_host = params.get("source_host", "localhost") source_port = params.get("source_port", "") options = params.get("extra_options", "") vg_name = params.get("vg_name", "virttest_vg_0") ro_flag = "yes" == params.get("readonly_mode", "no") status_error = "yes" == params.get("status_error", "no") if not source_type: raise error.TestFail("Command requires <type> value") cleanup_nfs = False cleanup_iscsi = False cleanup_logical = False if source_host == "localhost": if source_type == "netfs": # Set up nfs utils_test.libvirt.setup_or_cleanup_nfs(True) cleanup_nfs = True if source_type in ["iscsi", "logical"]: # Set up iscsi iscsi_device = utils_test.libvirt.setup_or_cleanup_iscsi(True) cleanup_iscsi = True if source_type == "logical": # Create VG by using iscsi device lv_utils.vg_create(vg_name, iscsi_device) cleanup_logical = True # Run virsh cmd options = "%s %s " % (source_host, source_port) + options if ro_flag: logging.debug("Readonly mode test") try: cmd_result = virsh.find_storage_pool_sources_as(source_type, options, ignore_status=True, debug=True, readonly=ro_flag) output = cmd_result.stdout.strip() err = cmd_result.stderr.strip() status = cmd_result.exit_status if not status_error: if status: raise error.TestFail(err) else: logging.debug("Command outout:\n%s", output) elif status_error and status == 0: raise error.TestFail("Expect fail, but run successfully") finally: # Clean up if cleanup_logical: cmd = "pvs |grep %s |awk '{print $1}'" % vg_name pv_name = utils.system_output(cmd) lv_utils.vg_remove(vg_name) utils.run("pvremove %s" % pv_name) if cleanup_iscsi: utils_test.libvirt.setup_or_cleanup_iscsi(False) if cleanup_nfs: utils_test.libvirt.setup_or_cleanup_nfs(False)
def create_pool(): """ Define and start a pool. """ sp = libvirt_storage.StoragePool() if create_by_xml: p_xml = pool_xml.PoolXML(pool_type=pool_type) p_xml.name = pool_name s_xml = pool_xml.SourceXML() s_xml.vg_name = disk_src_pool source_host = [] for (host_name, host_port) in zip( disk_src_host.split(), disk_src_port.split()): source_host.append({'name': host_name, 'port': host_port}) s_xml.hosts = source_host if auth_type: s_xml.auth_type = auth_type if auth_user: s_xml.auth_username = auth_user if auth_usage: s_xml.secret_usage = auth_usage p_xml.source = s_xml logging.debug("Pool xml: %s", p_xml) p_xml.xmltreefile.write() ret = virsh.pool_define(p_xml.xml, **virsh_dargs) libvirt.check_exit_status(ret) ret = virsh.pool_build(pool_name, **virsh_dargs) libvirt.check_exit_status(ret) ret = virsh.pool_start(pool_name, **virsh_dargs) libvirt.check_exit_status(ret) else: auth_opt = "" if client_name and client_key: auth_opt = ("--auth-type %s --auth-username %s --secret-usage '%s'" % (auth_type, auth_user, auth_usage)) if not sp.define_rbd_pool(pool_name, mon_host, disk_src_pool, extra=auth_opt): test.fail("Failed to define storage pool") if not sp.build_pool(pool_name): test.fail("Failed to build storage pool") if not sp.start_pool(pool_name): test.fail("Failed to start storage pool") # Check pool operation ret = virsh.pool_refresh(pool_name, **virsh_dargs) libvirt.check_exit_status(ret) ret = virsh.pool_uuid(pool_name, **virsh_dargs) libvirt.check_exit_status(ret) # pool-info pool_info = sp.pool_info(pool_name) if pool_info["Autostart"] != 'no': test.fail("Failed to check pool information") # pool-autostart if not sp.set_pool_autostart(pool_name): test.fail("Failed to set pool autostart") pool_info = sp.pool_info(pool_name) if pool_info["Autostart"] != 'yes': test.fail("Failed to check pool information") # pool-autostart --disable if not sp.set_pool_autostart(pool_name, "--disable"): test.fail("Failed to set pool autostart") # If port is not pre-configured, port value should not be hardcoded in pool information. if "yes" == params.get("rbd_port", "no"): if 'port' in virsh.pool_dumpxml(pool_name): test.fail("port attribute should not be in pool information") # find-storage-pool-sources-as if "yes" == params.get("find_storage_pool_sources_as", "no"): ret = virsh.find_storage_pool_sources_as("rbd", mon_host) libvirt.check_result(ret, skip_if=unsupported_err)
def run_virsh_find_storage_pool_sources_as(test, params, env): """ Test command: virsh find-storage-pool-sources-as 1. Prepare env to provide source storage: 1). For 'netfs' source type, setup nfs server 2). For 'iscsi' source type, setup iscsi server 3). For 'logcial' type pool, setup iscsi storage to create vg 2. Find the pool source by running virsh cmd """ source_type = params.get("source_type", "") source_host = params.get("source_host", "localhost") source_port = params.get("source_port", "") options = params.get("extra_options", "") vg_name = params.get("vg_name", "virttest_vg_0") ro_flag = "yes" == params.get("readonly_mode", "no") status_error = "yes" == params.get("status_error", "no") if not source_type: raise error.TestFail("Command requires <type> value") cleanup_nfs = False cleanup_iscsi = False cleanup_logical = False if source_host == "localhost": if source_type == "netfs": # Set up nfs utils_test.libvirt.setup_or_cleanup_nfs(True) cleanup_nfs = True if source_type in ["iscsi", "logical"]: # Set up iscsi iscsi_device = utils_test.libvirt.setup_or_cleanup_iscsi(True) cleanup_iscsi = True if source_type == "logical": # Create VG by using iscsi device lv_utils.vg_create(vg_name, iscsi_device) cleanup_logical = True # Run virsh cmd options = "%s %s " % (source_host, source_port) + options if ro_flag: logging.debug("Readonly mode test") try: cmd_result = virsh.find_storage_pool_sources_as( source_type, options, ignore_status=True, debug=True, readonly=ro_flag) output = cmd_result.stdout.strip() err = cmd_result.stderr.strip() status = cmd_result.exit_status if not status_error: if status: raise error.TestFail(err) else: logging.debug("Command outout:\n%s", output) elif status_error and status == 0: raise error.TestFail("Expect fail, but run successfully") finally: # Clean up if cleanup_logical: cmd = "pvs |grep %s |awk '{print $1}'" % vg_name pv_name = utils.system_output(cmd) lv_utils.vg_remove(vg_name) utils.run("pvremove %s" % pv_name) if cleanup_iscsi: utils_test.libvirt.setup_or_cleanup_iscsi(False) if cleanup_nfs: utils_test.libvirt.setup_or_cleanup_nfs(False)