def run_valgrind_memalign(test, params, env): """ This case is from [general operation] Work around valgrind choking on our use of memalign(): 1.download valgrind form valgrind download page: www.valgrind.org. 2.install the valgrind in host. 3.run # valgrind /usr/libexec/qemu-kvm -vnc :0 -S -m 384 -monitor stdio 4.check the status and do continue the VM. 5.quit the VM. @param test: QEMU test object @param params: Dictionary with the test parameters @param env: Dictionary with test environment """ interval = float(params.get("interval_time", "10")) def valgrind_intall(): valgrind_install_cmd = params.get("valgrind_install_cmd") s = utils.system(valgrind_install_cmd, timeout=3600) if s != 0: raise error.TestError("Fail to install valgrind") else: logging.info("Install valgrind successfully.") valgring_support_check_cmd = params.get("valgring_support_check_cmd") try: utils.system(valgring_support_check_cmd,timeout=interval) except Exception: valgrind_intall() params["start_vm"] = "yes" env_process.preprocess_vm(test, params, env, params.get("main_vm")) vm = env.get_vm(params["main_vm"]) time.sleep(interval) vm.verify_status("running")
def iscsi_node_del(target_name=None): """ Delete target node record, if the target name is not set then delete all target node records. :params target_name: Name of the target. """ node_list = iscsi_get_nodes() cmd = '' if target_name: for node_tup in node_list: if target_name in node_tup: cmd = "iscsiadm -m node -o delete -T %s " % target_name cmd += "--portal %s" % node_tup[0] utils.system(cmd, ignore_status=True) break if not cmd: logging.error( "The target '%s' for delete is not in target node" " record", target_name) else: for node_tup in node_list: cmd = "iscsiadm -m node -o delete -T %s " % node_tup[1] cmd += "--portal %s" % node_tup[0] utils.system(cmd, ignore_status=True)
def setup(self, env): if self.ksmtuned_process != 0 and self.disable_ksmtuned: kill_cmd = "kill -1 %s" % self.ksmtuned_process utils.system(kill_cmd) env.data["KSM_default_config"] = self.default_status ksm_cmd = "" if self.interface == "sysfs": if self.run != self.default_status[0]: ksm_cmd += " echo %s > KSM_PATH/run;" % self.run if (self.pages_to_scan and self.pages_to_scan != self.default_status[1]): ksm_cmd += " echo %s > KSM_PATH" % self.pages_to_scan ksm_cmd += "/pages_to_scan;" if (self.sleep_ms and self.sleep_ms != self.default_status[2]): ksm_cmd += " echo %s > KSM_PATH" % self.sleep_ms ksm_cmd += "/sleep_millisecs" ksm_cmd = re.sub("KSM_PATH", self.ksm_path, ksm_cmd) elif self.interface == "ksmctl": if self.run == "1": ksm_cmd += "ksmctl start %s %s" % (self.pages_to_scan, self.sleep_ms) else: ksm_cmd += "ksmctl stop" utils.system(ksm_cmd)
def set_chap_auth_target(self): """ set up authentication information for every single initiator, which provides the capability to define common login information for all Endpoints in a TPG """ auth_cmd = "targetcli /iscsi/%s/tpg1/ " % self.target attr_cmd = ("set attribute %s %s %s" % ("demo_mode_write_protect=0", "generate_node_acls=1", "cache_dynamic_acls=1")) utils.system(auth_cmd + attr_cmd) # Set userid userid_cmd = "%s set auth userid=%s" % (auth_cmd, self.chap_user) output = utils.system_output(userid_cmd) if self.chap_user not in output: raise error.TestFail("Failed to set user. (%s)", output) # Set password passwd_cmd = "%s set auth password=%s" % (auth_cmd, self.chap_passwd) output = utils.system_output(passwd_cmd) if self.chap_passwd not in output: raise error.TestFail("Failed to set password. (%s)", output) # Save configuration utils.system("targetcli / saveconfig")
def rbd_image_create(ceph_monitor, rbd_pool_name, rbd_image_name, rbd_image_size, force_create=False): """ Create a rbd image. :params ceph_monitor: The specified monitor to connect to :params rbd_pool_name: The name of rbd pool :params rbd_image_name: The name of rbd image :params rbd_image_size: The size of rbd image :params force_create: Force create the image or not """ if rbd_image_exist(ceph_monitor, rbd_pool_name, rbd_image_name): create_image = False image_info = rbd_image_info(ceph_monitor, rbd_pool_name, rbd_image_name) try: int(rbd_image_size) compare_str = rbd_image_size except ValueError: compare_str = utils_misc.normalize_data_size(rbd_image_size) if image_info['size'] != compare_str or force_create: rbd_image_rm(ceph_monitor, rbd_pool_name, rbd_image_name) create_image = True if create_image: cmd = "rbd create %s/%s -m %s" % (rbd_pool_name, rbd_image_name, ceph_monitor) utils.system(cmd, verbose=True) else: logging.debug("Image already exist skip the create.")
def unload_module(module_name): """ Removes a module. Handles dependencies. If even then it's not possible to remove one of the modules, it will throw an error.CmdError exception. :param module_name: Name of the module we want to remove. :type module_name: str """ module_info = loaded_module_info(module_name) try: submodules = module_info['submodules'] except KeyError: logging.info("Module %s is already unloaded" % module_name) else: for module in submodules: unload_module(module) module_info = loaded_module_info(module_name) try: module_used = module_info['used'] except KeyError: logging.info("Module %s is already unloaded" % module_name) return if module_used != 0: raise error.TestNAError("Module %s is still in use. " "Can not unload it." % module_name) utils.system("/sbin/modprobe -r %s" % module_name) logging.info("Module %s unloaded" % module_name)
def rbd_image_create(ceph_monitor, rbd_pool_name, rbd_image_name, rbd_image_size, force_create=False): """ Create a rbd image. :params ceph_monitor: The specified monitor to connect to :params rbd_pool_name: The name of rbd pool :params rbd_image_name: The name of rbd image :params rbd_image_size: The size of rbd image :params force_create: Force create the image or not """ if rbd_image_exist(ceph_monitor, rbd_pool_name, rbd_image_name): create_image = False image_info = rbd_image_info(ceph_monitor, rbd_pool_name, rbd_image_name) try: int(rbd_image_size) compare_str = rbd_image_size except ValueError: compare_str = utils_misc.normalize_data_size(rbd_image_size) if image_info['size'] != compare_str or force_create: rbd_image_rm(ceph_monitor, rbd_pool_name, rbd_image_name) create_image = True if create_image: cmd = "rbd create %s/%s -m %s" % (rbd_pool_name, rbd_image_name, ceph_monitor) utils.system(cmd, verbose=True) else: logging.debug("Image already exist skip the create.")
def check_test(cmd): """ Subcommand 'qemu-img check' test. This tests will 'dd' to create a specified size file, and check it. Then convert it to supported image_format in each loop and check again. :param cmd: qemu-img base command. """ test_image = _get_image_filename(params["image_name_dd"], enable_gluster) create_image_cmd = params["create_image_cmd"] create_image_cmd = create_image_cmd % test_image msg = " Create image %s by command %s" % (test_image, create_image_cmd) error.context(msg, logging.info) utils.system(create_image_cmd, verbose=False) status, output = _check(cmd, test_image) if not status: raise error.TestFail("Check image '%s' failed with error: %s" % (test_image, output)) for fmt in params["supported_image_formats"].split(): output_image = test_image + ".%s" % fmt _convert(cmd, fmt, test_image, output_image) status, output = _check(cmd, output_image) if not status: raise error.TestFail("Check image '%s' got error: %s" % (output_image, output)) remove(output_image) remove(test_image)
def load_module(module_name): # Checks if a module has already been loaded if module_is_loaded(module_name): return False utils.system('/sbin/modprobe ' + module_name) return True
def _convert(cmd, output_fmt, img_name, output_filename, fmt=None, compressed="no", encrypted="no"): """ Simple wrapper of 'qemu-img convert' function. :param cmd: qemu-img base command. :param output_fmt: the output format of converted image :param img_name: image name that to be converted :param output_filename: output image name that converted :param fmt: output image format :param compressed: whether output image is compressed :param encrypted: whether output image is encrypted """ cmd += " convert" if compressed == "yes": cmd += " -c" if encrypted == "yes": cmd += " -e" if fmt: cmd += " -f %s" % fmt cmd += " -O %s" % output_fmt options = params.get("qemu_img_options") if options: options = options.split() cmd += " -o " for option in options: value = params.get(option) cmd += "%s=%s," % (option, value) cmd = cmd.rstrip(",") cmd += " %s %s" % (img_name, output_filename) msg = "Converting '%s' from format '%s'" % (img_name, fmt) msg += " to '%s'" % output_fmt error.context(msg, logging.info) utils.system(cmd)
def setup_remote(self): """ Mount sharing directory to remote host. """ ssh_cmd = "ssh %s@%s " % (self.ssh_user, self.nfs_client_ip) check_mount_dir_cmd = ssh_cmd + "'ls -d %s'" % self.mount_dir logging.debug("To check if the %s exists", self.mount_dir) output = commands.getoutput(check_mount_dir_cmd) if re.findall("No such file or directory", output, re.M): mkdir_cmd = ssh_cmd + "'mkdir -p %s'" % self.mount_dir logging.debug("Prepare to create %s", self.mount_dir) s, o = commands.getstatusoutput(mkdir_cmd) if s != 0: raise error.TestFail("Failed to run %s: %s", mkdir_cmd, o) self.mkdir_mount_remote = True self.mount_src = "%s:%s" % (self.nfs_server_ip, self.mount_src) logging.debug("Mount %s to %s" % (self.mount_src, self.mount_dir)) mount_cmd = ssh_cmd + "'mount -t nfs %s %s -o %s'" % ( self.mount_src, self.mount_dir, self.mount_options) try: utils.system(mount_cmd, verbose=True) except error.CmdError: raise error.TestFail("Failed to run: %s", mount_cmd) # Check if the sharing directory is mounted if not self.is_mounted(): raise error.TestFail("Failed to mount from %s to %s", self.mount_src, self.mount_dir)
def setup_remote(self): """ Mount sharing directory to remote host. """ ssh_cmd = "ssh %s@%s " % (self.ssh_user, self.nfs_client_ip) check_mount_dir_cmd = ssh_cmd + "'ls -d %s'" % self.mount_dir logging.debug("To check if the %s exists", self.mount_dir) output = commands.getoutput(check_mount_dir_cmd) if re.findall("No such file or directory", output, re.M): mkdir_cmd = ssh_cmd + "'mkdir -p %s'" % self.mount_dir logging.debug("Prepare to create %s", self.mount_dir) s, o = commands.getstatusoutput(mkdir_cmd) if s != 0: raise error.TestFail("Failed to run %s: %s", mkdir_cmd, o) self.mkdir_mount_remote = True self.mount_src = "%s:%s" % (self.nfs_server_ip, self.mount_src) logging.debug("Mount %s to %s" % (self.mount_src, self.mount_dir)) mount_cmd = ssh_cmd + "'mount -t nfs %s %s -o %s'" % (self.mount_src, self.mount_dir, self.mount_options) try: utils.system(mount_cmd, verbose=True) except error.CmdError: raise error.TestFail("Failed to run: %s", mount_cmd) # Check if the sharing directory is mounted if not self.is_mounted(): raise error.TestFail("Failed to mount from %s to %s", self.mount_src, self.mount_dir)
def _convert(cmd, output_fmt, img_name, output_filename, fmt=None, compressed="no", encrypted="no"): """ Simple wrapper of 'qemu-img convert' function. @param cmd: qemu-img base command. @param output_fmt: the output format of converted image @param img_name: image name that to be converted @param output_filename: output image name that converted @param fmt: output image format @param compressed: whether output image is compressed @param encrypted: whether output image is encrypted """ cmd += " convert" if compressed == "yes": cmd += " -c" if encrypted == "yes": cmd += " -e" if fmt: cmd += " -f %s" % fmt cmd += " -O %s" % output_fmt cmd += " %s %s" % (img_name, output_filename) logging.info("Converting '%s' from format '%s' to '%s'", img_name, fmt, output_fmt) utils.system(cmd)
def set_chap_auth_target(self): """ set up authentication information for every single initiator, which provides the capability to define common login information for all Endpoints in a TPG """ auth_cmd = "targetcli /iscsi/%s/tpg1/ " % self.target attr_cmd = ("set attribute %s %s %s" % ("demo_mode_write_protect=0", "generate_node_acls=1", "cache_dynamic_acls=1")) utils.system(auth_cmd + attr_cmd) # Set userid userid_cmd = "%s set auth userid=%s" % (auth_cmd, self.chap_user) output = utils.system_output(userid_cmd) if self.chap_user not in output: raise error.TestFail("Failed to set user. (%s)" % output) # Set password passwd_cmd = "%s set auth password=%s" % (auth_cmd, self.chap_passwd) output = utils.system_output(passwd_cmd) if self.chap_passwd not in output: raise error.TestFail("Failed to set password. (%s)" % output) # Save configuration utils.system("targetcli / saveconfig")
def cleanup(self): """ Cleanup NFS client. """ ssh_cmd = "ssh %s@%s " % (self.ssh_user, self.nfs_client_ip) logging.debug("Umount %s from %s" % (self.mount_dir, self.nfs_server_ip)) umount_cmd = ssh_cmd + "'umount -l %s'" % self.mount_dir try: utils.system(umount_cmd, verbose=True) except error.CmdError: raise error.TestFail("Failed to run: %s", umount_cmd) if self.mkdir_mount_remote: rmdir_cmd = ssh_cmd + "'rm -rf %s'" % self.mount_dir try: utils.system(rmdir_cmd, verbose=True) except error.CmdError: raise error.TestFail("Failed to run: %s", rmdir_cmd) if self.is_mounted(): raise error.TestFail("Failed to umount %s", self.mount_dir) # Recover SSH connection self.ssh_obj.auto_recover = True del self.ssh_obj
def sr_iov_cleanup(self): """ Clean up the sriov setup Check if the PCI hardware device drive is loaded with the appropriate, parameters (none of VFs), and if it's not, perform cleanup. @return: True, if the setup was completed successfuly, False otherwise. """ # Check if the host support interrupt remapping error.context("Clean up host env after PCI assign test", logging.info) kvm_re_probe = False if self.kvm_params is not None: if (self.auai_path and open(self.auai_path, "r").read().strip() == "Y"): if self.kvm_params and self.kvm_params[self.auai_path] == "N": kvm_re_probe = True else: kvm_re_probe = True # Try to re probe kvm module with interrupt remapping support if kvm_re_probe: kvm_arch = kvm_control.get_kvm_arch() utils.system("modprobe -r %s" % kvm_arch) utils.system("modprobe -r kvm") cmd = "modprobe kvm" if self.kvm_params: for i in self.kvm_params: if self.kvm_params[i] == "Y": params_name = os.path.split(i)[1] cmd += " %s=1" % params_name logging.info("Loading kvm with command: %s" % cmd) try: utils.system(cmd) except Exception: logging.debug("Failed to reload kvm") cmd = "modprobe %s" % kvm_arch logging.info("Loading %s with command: %s" % (kvm_arch, cmd)) utils.system(cmd) re_probe = False s = commands.getstatusoutput('lsmod | grep %s' % self.driver)[0] if s: cmd = "modprobe -r %s" % self.driver logging.info("Running host command: %s" % cmd) os.system(cmd) re_probe = True else: return True # Re-probe driver with proper number of VFs if re_probe: cmd = "modprobe %s" % self.driver msg = "Loading the driver '%s' without option" % self.driver error.context(msg, logging.info) s = commands.getstatusoutput(cmd)[0] utils.system("/etc/init.d/network restart", ignore_status=True) if s: return False return True
def _create(cmd, img_name, fmt, img_size=None, base_img=None, base_img_fmt=None, encrypted="no"): """ Simple wrapper of 'qemu-img create' @param cmd: qemu-img base command. @param img_name: name of the image file @param fmt: image format @param img_size: image size @param base_img: base image if create a snapshot image @param base_img_fmt: base image format if create a snapshot image @param encrypted: indicates whether the created image is encrypted """ cmd += " create" if encrypted == "yes": cmd += " -e" if base_img: cmd += " -b %s" % base_img if base_img_fmt: cmd += " -F %s" % base_img_fmt cmd += " -f %s" % fmt cmd += " %s" % img_name if img_size: cmd += " %s" % img_size utils.system(cmd)
def check_test(cmd): """ Subcommand 'qemu-img check' test. This tests will 'dd' to create a specified size file, and check it. Then convert it to supported image_format in each loop and check again. @param cmd: qemu-img base command. """ test_image = virt_utils.get_path(test.bindir, params.get("image_name_dd")) print "test_image = %s" % test_image create_image_cmd = params.get("create_image_cmd") create_image_cmd = create_image_cmd % test_image print "create_image_cmd = %s" % create_image_cmd utils.system(create_image_cmd) s, o = _check(cmd, test_image) if not s: raise error.TestFail("Check image '%s' failed with error: %s" % (test_image, o)) for fmt in params.get("supported_image_formats").split(): output_image = test_image + ".%s" % fmt _convert(cmd, fmt, test_image, output_image) s, o = _check(cmd, output_image) if not s: raise error.TestFail("Check image '%s' got error: %s" % (output_image, o)) os.remove(output_image) os.remove(test_image)
def _convert(cmd, output_fmt, img_name, output_filename, fmt=None, compressed="no", encrypted="no"): """ Simple wrapper of 'qemu-img convert' function. @param cmd: qemu-img base command. @param output_fmt: the output format of converted image @param img_name: image name that to be converted @param output_filename: output image name that converted @param fmt: output image format @param compressed: whether output image is compressed @param encrypted: whether output image is encrypted """ cmd += " convert" if compressed == "yes": cmd += " -c" if encrypted == "yes": cmd += " -e" if fmt: cmd += " -f %s" % fmt cmd += " -O %s" % output_fmt cmd += " %s %s" % (img_name, output_filename) logging.info("Converting '%s' from format '%s' to '%s'", img_name, fmt, output_fmt) utils.system(cmd)
def export_target(self): """ Export target in localhost for emulated iscsi """ if not os.path.isfile(self.emulated_image): utils.system(self.create_cmd) cmd = "tgtadm --lld iscsi --mode target --op show" try: output = utils.system_output(cmd) except error.CmdError: utils.system("service tgtd restart") output = utils.system_output(cmd) if not re.findall("%s$" % self.target, output, re.M): logging.debug("Need to export target in host") output = utils.system_output(cmd) used_id = re.findall("Target\s+(\d+)", output) emulated_id = 1 while str(emulated_id) in used_id: emulated_id += 1 self.emulated_id = str(emulated_id) cmd = "tgtadm --mode target --op new --tid %s" % self.emulated_id cmd += " --lld iscsi --targetname %s" % self.target utils.system(cmd) cmd = "tgtadm --mode logicalunit --op new " cmd += "--tid %s --lld iscsi --lun 1 " % self.emulated_id cmd += "--backing-store %s" % self.emulated_image utils.system(cmd) cmd = "tgtadm --lld iscsi --op bind --mode target " cmd += "--tid %s -I ALL" % self.emulated_id utils.system(cmd) self.export_flag = True else: self.emulated_id = re.findall("Target\s+(\d+):\s+%s$" % self.target, output)
def check_test(cmd): """ Subcommand 'qemu-img check' test. This tests will 'dd' to create a specified size file, and check it. Then convert it to supported image_format in each loop and check again. @param cmd: qemu-img base command. """ test_image = utils_misc.get_path(test.bindir, params.get("image_name_dd")) print "test_image = %s" % test_image create_image_cmd = params.get("create_image_cmd") create_image_cmd = create_image_cmd % test_image print "create_image_cmd = %s" % create_image_cmd utils.system(create_image_cmd) s, o = _check(cmd, test_image) if not s: raise error.TestFail("Check image '%s' failed with error: %s" % (test_image, o)) for fmt in params.get("supported_image_formats").split(): output_image = test_image + ".%s" % fmt _convert(cmd, fmt, test_image, output_image) s, o = _check(cmd, output_image) if not s: raise error.TestFail("Check image '%s' got error: %s" % (output_image, o)) os.remove(output_image) os.remove(test_image)
def sr_iov_cleanup(self): """ Clean up the sriov setup Check if the PCI hardware device drive is loaded with the appropriate, parameters (none of VFs), and if it's not, perform cleanup. @return: True, if the setup was completed successfuly, False otherwise. """ # Check if the host support interrupt remapping error.context("Clean up host env after PCI assign test", logging.info) kvm_re_probe = False if self.kvm_params is not None: if (self.auai_path and open(self.auai_path, "r").read().strip() == "Y"): if self.kvm_params and self.kvm_params[self.auai_path] == "N": kvm_re_probe = True else: kvm_re_probe = True # Try to re probe kvm module with interrupt remapping support if kvm_re_probe: kvm_arch = kvm_control.get_kvm_arch() utils.system("modprobe -r %s" % kvm_arch) utils.system("modprobe -r kvm") cmd = "modprobe kvm" if self.kvm_params: for i in self.kvm_params: if self.kvm_params[i] == "Y": params_name = os.path.split(i)[1] cmd += " %s=1" % params_name logging.info("Loading kvm with command: %s" % cmd) try: utils.system(cmd) except Exception: logging.debug("Failed to reload kvm") cmd = "modprobe %s" % kvm_arch logging.info("Loading %s with command: %s" % (kvm_arch, cmd)) utils.system(cmd) re_probe = False s = commands.getstatusoutput('lsmod | grep %s' % self.driver)[0] if s: cmd = "modprobe -r %s" % self.driver logging.info("Running host command: %s" % cmd) os.system(cmd) re_probe = True else: return True # Re-probe driver with proper number of VFs if re_probe: cmd = "modprobe %s" % self.driver msg = "Loading the driver '%s' without option" % self.driver error.context(msg, logging.info) s = commands.getstatusoutput(cmd)[0] utils.system("/etc/init.d/network restart", ignore_status=True) if s: return False return True
def load_module(module_name): # Checks if a module has already been loaded if module_is_loaded(module_name): return False utils.system("/sbin/modprobe " + module_name) return True
def cleanup(self): """ Cleanup NFS client. """ ssh_cmd = "ssh %s@%s " % (self.ssh_user, self.nfs_client_ip) logging.debug("Umount %s from %s" % (self.mount_dir, self.nfs_server_ip)) umount_cmd = ssh_cmd + "'umount -l %s'" % self.mount_dir try: utils.system(umount_cmd, verbose=True) except error.CmdError: raise error.TestFail("Failed to run: %s", umount_cmd) if self.mkdir_mount_remote: rmdir_cmd = ssh_cmd + "'rm -rf %s'" % self.mount_dir try: utils.system(rmdir_cmd, verbose=True) except error.CmdError: raise error.TestFail("Failed to run: %s", rmdir_cmd) if self.is_mounted(): raise error.TestFail("Failed to umount %s", self.mount_dir) # Recover SSH connection self.ssh_obj.auto_recover = True del self.ssh_obj
def unload_module(module_name): """ Removes a module. Handles dependencies. If even then it's not possible to remove one of the modules, it will throw an error.CmdError exception. :param module_name: Name of the module we want to remove. :type module_name: str """ module_info = loaded_module_info(module_name) try: submodules = module_info['submodules'] except KeyError: logging.info("Module %s is already unloaded" % module_name) else: for module in submodules: unload_module(module) module_info = loaded_module_info(module_name) try: module_used = module_info['used'] except KeyError: logging.info("Module %s is already unloaded" % module_name) return if module_used != 0: raise error.TestNAError("Module %s is still in use. " "Can not unload it." % module_name) utils.system("/sbin/modprobe -r %s" % module_name) logging.info("Module %s unloaded" % module_name)
def setup(self, env): if self.ksmtuned_process != 0 and self.disable_ksmtuned: kill_cmd = "kill -1 %s" % self.ksmtuned_process utils.system(kill_cmd) env.data["KSM_default_config"] = self.default_status ksm_cmd = "" if self.interface == "sysfs": if self.run != self.default_status[0]: ksm_cmd += " echo %s > KSM_PATH/run;" % self.run if (self.pages_to_scan and self.pages_to_scan != self.default_status[1]): ksm_cmd += " echo %s > KSM_PATH" % self.pages_to_scan ksm_cmd += "/pages_to_scan;" if (self.sleep_ms and self.sleep_ms != self.default_status[2]): ksm_cmd += " echo %s > KSM_PATH" % self.sleep_ms ksm_cmd += "/sleep_millisecs" ksm_cmd = re.sub("KSM_PATH", self.ksm_path, ksm_cmd) elif self.interface == "ksmctl": if self.run == "1": ksm_cmd += "ksmctl start %s %s" % (self.pages_to_scan, self.sleep_ms) else: ksm_cmd += "ksmctl stop" utils.system(ksm_cmd)
def _create(cmd, img_name, fmt, img_size=None, base_img=None, base_img_fmt=None, encrypted="no"): """ Simple wrapper of 'qemu-img create' @param cmd: qemu-img base command. @param img_name: name of the image file @param fmt: image format @param img_size: image size @param base_img: base image if create a snapshot image @param base_img_fmt: base image format if create a snapshot image @param encrypted: indicates whether the created image is encrypted """ cmd += " create" if encrypted == "yes": cmd += " -e" if base_img: cmd += " -b %s" % base_img if base_img_fmt: cmd += " -F %s" % base_img_fmt cmd += " -f %s" % fmt cmd += " %s" % img_name if img_size: cmd += " %s" % img_size utils.system(cmd)
def check_test(cmd): """ Subcommand 'qemu-img check' test. This tests will 'dd' to create a specified size file, and check it. Then convert it to supported image_format in each loop and check again. :param cmd: qemu-img base command. """ test_image = _get_image_filename(params["image_name_dd"], enable_gluster) create_image_cmd = params["create_image_cmd"] create_image_cmd = create_image_cmd % test_image msg = " Create image %s by command %s" % (test_image, create_image_cmd) error.context(msg, logging.info) utils.system(create_image_cmd, verbose=False) status, output = _check(cmd, test_image) if not status: raise error.TestFail("Check image '%s' failed with error: %s" % (test_image, output)) for fmt in params["supported_image_formats"].split(): output_image = test_image + ".%s" % fmt _convert(cmd, fmt, test_image, output_image) status, output = _check(cmd, output_image) if not status: raise error.TestFail("Check image '%s' got error: %s" % (output_image, output)) remove(output_image) remove(test_image)
def delete_chap_account(self): """ Delete the CHAP authentication account """ if self.chap_user in self.get_chap_accounts(): cmd = "tgtadm --lld iscsi --op delete --mode account" cmd += " --user %s" % self.chap_user utils.system(cmd)
def rescan(self): """ Rescan lvm , used before create volume or after remove volumes; """ lvm_reload_cmd = self.params.get("lvm_reload_cmd") if lvm_reload_cmd: utils.system(lvm_reload_cmd, ignore_status=True) logging.info("reload lvm monitor service")
def delete_chap_account(self): """ Delete the CHAP authentication account """ if self.chap_user in self.get_chap_accounts(): cmd = "tgtadm --lld iscsi --op delete --mode account" cmd += " --user %s" % self.chap_user utils.system(cmd)
def display(self): """ Show physical volume detials :raise: CmdError """ cmd = "pvdisplay %s" % self.name utils.system(cmd)
def publish_job(jobdir): cmd = RSYNC_COMMAND % (jobdir, options.dest) utils.system(cmd) # mark the jobdir as published fd = open(os.path.join(jobdir, PUBLISH_FLAGFILE), 'w') fd.close() print 'Published', jobdir
def rescan(self): """ Rescan lvm , used before create volume or after remove volumes; """ lvm_reload_cmd = self.params.get("lvm_reload_cmd") if lvm_reload_cmd: utils.system(lvm_reload_cmd, ignore_status=True) logging.info("reload lvm monitor service")
def display(self): """ Show physical volume detials :raise: CmdError """ cmd = "pvdisplay %s" % self.name utils.system(cmd)
def publish_job(jobdir): cmd = RSYNC_COMMAND % (jobdir, options.dest) utils.system(cmd) # mark the jobdir as published fd = open(os.path.join(jobdir, PUBLISH_FLAGFILE), 'w') fd.close() print 'Published', jobdir
def remove(self, extra_args="-ff --yes"): """ Remove the VolumeGroup; :param extra_args: extra argurments for lvm command; """ cmd = "lvm vgremove %s %s" % (extra_args, self.name) utils.system(cmd) logging.info("logical volume-group(%s) removed", self.name)
def remove(self, extra_args="-ff --yes"): """ Remove the VolumeGroup; :param extra_args: extra argurments for lvm command; """ cmd = "lvm vgremove %s %s" % (extra_args, self.name) utils.system(cmd) logging.info("logical volume-group(%s) removed", self.name)
def cleanup(self): if self.deallocate: error.context("trying to dealocate hugepage memory") try: utils.system("umount %s" % self.hugepage_path) except error.CmdError: return utils.system("echo 0 > %s" % self.kernel_hp_file) logging.debug("Hugepage memory successfully dealocated")
def cleanup(self): if self.deallocate: error.context("trying to dealocate hugepage memory") try: utils.system("umount %s" % self.hugepage_path) except error.CmdError: return utils.system("echo 0 > %s" % self.kernel_hp_file) logging.debug("Hugepage memory successfully dealocated")
def kill_and_check(vm): """ Kill the vm and check vm is dead """ qemu_pid = vm.get_pid() cmd = "kill -9 %s" % qemu_pid utils.system(cmd) if not vm.wait_until_dead(timeout=10): raise error.TestFail("VM is not dead, 10s after '%s' sent." % cmd) logging.info("Vm is dead as expected")
def unexport(self): """ Unexport an entry. """ if self.is_exported(): unexport_cmd = "exportfs -u %s:%s" % (self.client, self.path) utils.system(unexport_cmd) else: logging.warn("Target %s %s is not exported yet." "Can not unexport it." % (self.client, self.path))
def kill_and_check(vm): """ Kill the vm and check vm is dead """ qemu_pid = vm.get_pid() cmd = "kill -9 %s" % qemu_pid utils.system(cmd) if not vm.wait_until_dead(timeout=10): raise error.TestFail("VM is not dead, 10s after '%s' sent." % cmd) logging.info("Vm is dead as expected")
def remove(self, extra_args=" -ff --yes"): """ Remove a physical volume :param extra_args: extra argurments for pvremove command; :raise CmdError """ cmd = "lvm pvremove %s %s" % (extra_args, self.name) utils.system(cmd) logging.info("logical physical volume (%s) removed", self.name)
def remove(self, extra_args="-ff --yes"): """ Remove LogicalVolume device; :param extra_args: extra argurments pass to lvm command; """ self.umount() cmd = "lvm lvremove %s %s/%s" % (extra_args, self.vg.name, self.name) utils.system(cmd) logging.info("logical volume(%s) removed", self.name)
def remove(self, extra_args=" -ff --yes"): """ Remove a physical volume :param extra_args: extra argurments for pvremove command; :raise CmdError """ cmd = "lvm pvremove %s %s" % (extra_args, self.name) utils.system(cmd) logging.info("logical physical volume (%s) removed", self.name)
def remove(self, extra_args="-ff --yes"): """ Remove LogicalVolume device; :param extra_args: extra argurments pass to lvm command; """ self.umount() cmd = "lvm lvremove %s %s/%s" % (extra_args, self.vg.name, self.name) utils.system(cmd) logging.info("logical volume(%s) removed", self.name)
def gluster_vol_create(vol_name, hostname, brick_path): """ Gluster Volume Creation """ # Create a brick gluster_brick_create(brick_path) cmd = "gluster volume create %s %s:/%s" % (vol_name, hostname, brick_path) error.context("Volume creation failed") utils.system(cmd)
def unexport(self): """ Unexport an entry. """ if self.is_exported(): unexport_cmd = "exportfs -u %s:%s" % (self.client, self.path) utils.system(unexport_cmd) else: logging.warn("Target %s %s is not exported yet." "Can not unexport it." % (self.client, self.path))
def nohup(command, stdout="/dev/null", stderr="/dev/null", background=True, env={}): cmd = " ".join(key + "=" + val for key, val in env.iteritems()) cmd += " nohup " + command cmd += " > %s" % stdout if stdout == stderr: cmd += " 2>&1" else: cmd += " 2> %s" % stderr if background: cmd += " &" utils.system(cmd)
def delete_target(self): """ Delete target from host. """ cmd = "tgtadm --lld iscsi --mode target --op show" output = utils.system_output(cmd) if re.findall("%s$" % self.target, output, re.M): if self.emulated_id: cmd = "tgtadm --lld iscsi --mode target --op delete " cmd += "--tid %s" % self.emulated_id utils.system(cmd)
def add_chap_account(self): """ Add CHAP authentication account """ try: cmd = "tgtadm --lld iscsi --op new --mode account" cmd += " --user %s" % self.chap_user cmd += " --password %s" % self.chap_passwd utils.system(cmd) except error.CmdError, err: logging.error("Fail to add account: %s", err)
def gluster_vol_create(vol_name, hostname, brick_path): """ Gluster Volume Creation """ # Create a brick gluster_brick_create(brick_path) cmd = "gluster volume create %s %s:/%s" % (vol_name, hostname, brick_path) error.context("Volume creation failed") utils.system(cmd)
def _create( cmd, img_name, fmt, img_size=None, base_img=None, base_img_fmt=None, encrypted="no", preallocated="off", cluster_size=None, ): """ Simple wrapper of 'qemu-img create' :param cmd: qemu-img base command. :param img_name: name of the image file :param fmt: image format :param img_size: image size :param base_img: base image if create a snapshot image :param base_img_fmt: base image format if create a snapshot image :param encrypted: indicates whether the created image is encrypted :param preallocated: if preallocation when create image, allowed values: off, metadata. Default is "off" :param cluster_size: the cluster size for the image """ cmd += " create" if encrypted == "yes": cmd += " -e" if base_img: cmd += " -b %s" % base_img if base_img_fmt: cmd += " -F %s" % base_img_fmt cmd += " -f %s" % fmt options = [] if preallocated != "off": options.append("preallocation=%s" % preallocated) if cluster_size is not None: options.append("cluster_size=%s" % cluster_size) if options: cmd += " -o %s" % ",".join(options) cmd += " %s" % img_name if img_size: cmd += " %s" % img_size msg = "Creating image %s by command %s" % (img_name, cmd) error.context(msg, logging.info) utils.system(cmd, verbose=False) status, out = _check(qemu_img_binary, img_name) if not status: raise error.TestFail("Check image '%s' got error: %s" % (img_name, out))
def add_chap_account(self): """ Add CHAP authentication account """ try: cmd = "tgtadm --lld iscsi --op new --mode account" cmd += " --user %s" % self.chap_user cmd += " --password %s" % self.chap_passwd utils.system(cmd) except error.CmdError, err: logging.error("Fail to add account: %s", err)
def delete_target(self): """ Delete target from host. """ cmd = "tgtadm --lld iscsi --mode target --op show" output = utils.system_output(cmd) if re.findall("%s$" % self.target, output, re.M): if self.emulated_id: cmd = "tgtadm --lld iscsi --mode target --op delete " cmd += "--tid %s" % self.emulated_id utils.system(cmd)
def clean(self): """ close opening connections and clean trash files; """ while self.sessions: session = self.sessions.pop() if session: session.close() if self.vm.is_alive(): self.vm.destroy() for _tmp in self.trash: utils.system("rm -f %s" % _tmp)
def mount_hugepage_fs(self): """ Verify if there's a hugetlbfs mount set. If there's none, will set up a hugetlbfs mount using the class attribute that defines the mount point. """ error.context("mounting hugepages path") if not os.path.ismount(self.hugepage_path): if not os.path.isdir(self.hugepage_path): os.makedirs(self.hugepage_path) cmd = "mount -t hugetlbfs none %s" % self.hugepage_path utils.system(cmd)