Пример #1
0
    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"))
        process.system(auth_cmd + attr_cmd)

        # Set userid
        userid_cmd = "%s set auth userid=%s" % (auth_cmd, self.chap_user)
        output = decode_to_text(process.system_output(userid_cmd))
        if self.chap_user not in output:
            raise exceptions.TestFail("Failed to set user. (%s)" % output)

        # Set password
        passwd_cmd = "%s set auth password=%s" % (auth_cmd, self.chap_passwd)
        output = decode_to_text(process.system_output(passwd_cmd))
        if self.chap_passwd not in output:
            raise exceptions.TestFail("Failed to set password. (%s)" % output)

        # Save configuration
        process.system("targetcli / saveconfig")
Пример #2
0
    def get_target_id(self):
        """
        Get target id from image name.
        """
        cmd = "targetcli ls /iscsi 1"
        target_info = decode_to_text(process.system_output(cmd))
        target = None
        for line in re.split("\n", target_info)[1:]:
            if re.findall("o-\s\S+\s[\.]+\s\[TPGs:\s\d\]$", line):
                # eg: iqn.2015-05.com.example:iscsi.disk
                try:
                    target = re.findall("iqn[\.]\S+:\S+", line)[0]
                except IndexError:
                    logging.info("No found target in %s", line)
                    continue
            else:
                continue

            cmd = "targetcli ls /iscsi/%s/tpg1/luns" % target
            luns_info = decode_to_text(process.system_output(cmd))
            for lun_line in re.split("\n", luns_info):
                if re.findall("o-\slun\d+", lun_line):
                    if self.emulated_image in lun_line:
                        break
                    else:
                        target = None
        return target
Пример #3
0
    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"))
        process.system(auth_cmd + attr_cmd)

        # Set userid
        userid_cmd = "%s set auth userid=%s" % (auth_cmd, self.chap_user)
        output = decode_to_text(process.system_output(userid_cmd))
        if self.chap_user not in output:
            raise exceptions.TestFail("Failed to set user. (%s)" % output)

        # Set password
        passwd_cmd = "%s set auth password=%s" % (auth_cmd, self.chap_passwd)
        output = decode_to_text(process.system_output(passwd_cmd))
        if self.chap_passwd not in output:
            raise exceptions.TestFail("Failed to set password. (%s)" % output)

        # Save configuration
        process.system("targetcli / saveconfig")
Пример #4
0
    def set_cpu_affinity(pid, mask):
        """
        Set the CPU affinity of all threads of the process with PID pid.
        Do this recursively for all child processes as well.

        :param pid: The process ID.
        :param mask: The CPU affinity mask.
        :return: A dict containing the previous mask for each thread.
        """
        tids = decode_to_text(
            process.system_output("ps -L --pid=%s -o lwp=" % pid,
                                  verbose=False,
                                  ignore_status=True)).split()
        prev_masks = {}
        for tid in tids:
            prev_mask = decode_to_text(
                process.system_output("taskset -p %s" % tid,
                                      verbose=False)).split()[-1]
            prev_masks[tid] = prev_mask
            process.system("taskset -p %s %s" % (mask, tid), verbose=False)
        children = decode_to_text(
            process.system_output("ps --ppid=%s -o pid=" % pid,
                                  verbose=False,
                                  ignore_status=True)).split()
        for child in children:
            prev_masks.update(set_cpu_affinity(child, mask))
        return prev_masks
Пример #5
0
    def get_target_id(self):
        """
        Get target id from image name.
        """
        cmd = "targetcli ls /iscsi 1"
        target_info = decode_to_text(process.system_output(cmd))
        target = None
        for line in re.split("\n", target_info)[1:]:
            if re.findall("o-\s\S+\s[\.]+\s\[TPGs:\s\d\]$", line):
                # eg: iqn.2015-05.com.example:iscsi.disk
                try:
                    target = re.findall("iqn[\.]\S+:\S+", line)[0]
                except IndexError:
                    logging.info("No found target in %s", line)
                    continue
            else:
                continue

            cmd = "targetcli ls /iscsi/%s/tpg1/luns" % target
            luns_info = decode_to_text(process.system_output(cmd))
            for lun_line in re.split("\n", luns_info):
                if re.findall("o-\slun\d+", lun_line):
                    if self.emulated_image in lun_line:
                        break
                    else:
                        target = None
        return target
Пример #6
0
def glusterd_start():
    """
    Check for glusterd status and start it
    """
    cmd = "service glusterd status"
    output = decode_to_text(process.system_output(cmd, ignore_status=True))
    # The blank before 'active' makes a distinction with 'inactive'
    if ' active' not in output or 'running' not in output:
        cmd = "service glusterd start"
        error_context.context("Starting gluster dameon failed")
        output = decode_to_text(process.system_output(cmd))
Пример #7
0
def glusterd_start():
    """
    Check for glusterd status and start it
    """
    cmd = "service glusterd status"
    output = decode_to_text(process.system_output(cmd, ignore_status=True))
    # The blank before 'active' makes a distinction with 'inactive'
    if ' active' not in output or 'running' not in output:
        cmd = "service glusterd start"
        error_context.context("Starting gluster dameon failed")
        output = decode_to_text(process.system_output(cmd))
Пример #8
0
def iscsi_logout(target_name=None):
    """
    Logout from a target. If the target name is not set then logout all
    targets.

    :params target_name: Name of the target.
    """
    if target_name:
        cmd = "iscsiadm --mode node --logout -T %s" % target_name
    else:
        cmd = "iscsiadm --mode node --logout all"

    output = ''
    try:
        output = decode_to_text(process.system_output(cmd))
    except process.CmdError as detail:
        # iscsiadm will fail when no matching sessions found
        # This failure makes no sense when target name is not specified
        stderr = results_stderr_52lts(detail.result)
        if not target_name and 'No matching sessions' in stderr:
            logging.info("%s: %s", detail, stderr)
        else:
            raise

    target_logout = ""
    if "successful" in output:
        target_logout = target_name

    return target_logout
Пример #9
0
def gen_lvmap_mpath(session=None):
    """
    Return the name mapping between logical volume and device
    mapper multipathed device.
    :param session: When session is given, it means VM session
                    Otherwise default value means it work for host
    :return: None or a dict like:
            {"lv_name": dm_name}
    """
    names_map = None
    cmd = ("lvdisplay|awk '/LV Name/{n=$3} "
           "/Block device/{d=$3; sub(\".*:\", \"dm-\", d); print n,d;}'")

    if session:
        output = session.cmd_output(cmd).strip()
    else:
        output = decode_to_text(process.system_output(cmd, shell=True))
    lines = output.splitlines()
    if len(lines) >= 1:
        names_map = {}
        for line in lines:
            values = line.split()
            lv_name, mpath_name = values[0], values[1]
            names_map.update({lv_name: mpath_name})
    return names_map
Пример #10
0
def rbd_image_exist(ceph_monitor,
                    rbd_pool_name,
                    rbd_image_name,
                    ceph_conf=None,
                    keyfile=None):
    """
    Check if rbd image is exist
    :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 ceph_conf: The path to the ceph configuration file
    :params keyfile: The path to the ceph keyring configuration file
    """
    cmd = "rbd {opts} ls {pool} {keyring}"
    c_opt = '-c %s' % ceph_conf if ceph_conf else ''
    m_opt = '-m %s' % ceph_monitor if ceph_monitor else ''
    opts = m_opt + ' ' + c_opt
    keyring = '--keyring %s' % keyfile if keyfile else ''
    cmd = cmd.format(opts=opts, pool=rbd_pool_name, keyring=keyring)
    output = decode_to_text(
        process.system_output(cmd, ignore_status=True, verbose=True))

    logging.debug("Response from rbd ls command is: %s" % output)

    return (rbd_image_name.strip() in output.splitlines())
Пример #11
0
def gluster_allow_insecure(vol_name, session=None):
    """
    Allow gluster volume insecure

    :param vol_name: name of gluster volume
    :param session: ShellSession object of remote host
    """

    cmd1 = "gluster volume set %s server.allow-insecure on" % vol_name
    cmd2 = "gluster volume info"
    error_context.context("Volume set server.allow-insecure failed")

    if session:
        session.cmd(cmd1)
        output = session.cmd_output(cmd2)
    else:
        process.system(cmd1)
        output = decode_to_text(process.system_output(cmd2))

    match = re.findall(r'server.allow-insecure: on', output)

    if not match:
        return False
    else:
        return True
Пример #12
0
    def info(self, force_share=False, output="human"):
        """
        Run qemu-img info command on image file and return its output.

        :param output: string of output format(`human`, `json`)
        """
        logging.debug("Run qemu-img info command on %s", self.image_filename)
        backing_chain = self.params.get("backing_chain")
        force_share &= self.cap_force_share
        cmd = self.image_cmd
        cmd += " info"
        if force_share:
            cmd += " -U"
        if backing_chain == "yes":
            if "--backing-chain" in self.help_text:
                cmd += " --backing-chain"
            else:
                logging.warn("'--backing-chain' option is not supported")
        if os.path.exists(self.image_filename) or self.is_remote_image():
            cmd += " %s --output=%s" % (self.image_filename, output)
            output = decode_to_text(process.system_output(cmd, verbose=True))
        else:
            logging.debug("Image file %s not found", self.image_filename)
            output = None
        return output
Пример #13
0
    def get_scratch_pkg_urls(self, pkg, arch=None):
        """
        Gets the urls for the scratch packages specified in pkg

        :type pkg: KojiScratchPkgSpec
        :param pkg: a scratch package specification
        :type arch: string
        :param arch: packages built for this architecture, but also including
                architecture independent (noarch) packages
        """
        rpm_urls = []

        if arch is None:
            arch = os.uname()[4]
        arches = [arch, 'noarch']

        index_url = "%s/%s/task_%s" % (self.get_scratch_base_url(), pkg.user,
                                       pkg.task)
        index_parser = KojiDirIndexParser()
        index_parser.feed(
            decode_to_text(urllib.request.urlopen(index_url).read()))

        if pkg.subpackages:
            for p in pkg.subpackages:
                for pfn in index_parser.package_file_names:
                    r = RPMFileNameInfo(pfn)
                    info = r.get_nvr_info()
                    if (p == info['name'] and r.get_arch() in arches):
                        rpm_urls.append("%s/%s" % (index_url, pfn))
        else:
            for pfn in index_parser.package_file_names:
                if (RPMFileNameInfo(pfn).get_arch() in arches):
                    rpm_urls.append("%s/%s" % (index_url, pfn))

        return rpm_urls
Пример #14
0
    def snapshot_apply(self):
        """
        Apply a snapshot image.

        :note: params should contain:
               snapshot_image_name -- the name of snapshot image file
        """
        cmd = self.image_cmd
        if self.snapshot_tag:
            cmd += " snapshot -a %s %s" % (self.snapshot_image_filename,
                                           self.image_filename)
        else:
            raise exceptions.TestError("Can not find the snapshot image"
                                       " parameters")

        decode_to_text(process.system_output(cmd))
Пример #15
0
    def snapshot_apply(self):
        """
        Apply a snapshot image.

        :note: params should contain:
               snapshot_image_name -- the name of snapshot image file
        """
        cmd = self.image_cmd
        if self.snapshot_tag:
            cmd += " snapshot -a %s %s" % (self.snapshot_image_filename,
                                           self.image_filename)
        else:
            raise exceptions.TestError("Can not find the snapshot image"
                                       " parameters")

        decode_to_text(process.system_output(cmd))
Пример #16
0
    def info(self, force_share=False, output="human"):
        """
        Run qemu-img info command on image file and return its output.

        :param output: string of output format(`human`, `json`)
        """
        logging.debug("Run qemu-img info command on %s", self.image_filename)
        backing_chain = self.params.get("backing_chain")
        force_share &= self.cap_force_share
        cmd = self.image_cmd
        cmd += " info"
        if force_share:
            cmd += " -U"
        if backing_chain == "yes":
            if "--backing-chain" in self.help_text:
                cmd += " --backing-chain"
            else:
                logging.warn("'--backing-chain' option is not supported")
        if os.path.exists(self.image_filename) or self.is_remote_image():
            cmd += " %s --output=%s" % (self.image_filename, output)
            output = decode_to_text(process.system_output(cmd, verbose=True))
        else:
            logging.debug("Image file %s not found", self.image_filename)
            output = None
        return output
Пример #17
0
def gen_lvmap_mpath(session=None):
    """
    Return the name mapping between logical volume and device
    mapper multipathed device.
    :param session: When session is given, it means VM session
                    Otherwise default value means it work for host
    :return: None or a dict like:
            {"lv_name": dm_name}
    """
    names_map = None
    cmd = ("lvdisplay|awk '/LV Name/{n=$3} "
           "/Block device/{d=$3; sub(\".*:\", \"dm-\", d); print n,d;}'")

    if session:
        output = session.cmd_output(cmd).strip()
    else:
        output = decode_to_text(process.system_output(cmd, shell=True))
    lines = output.splitlines()
    if len(lines) >= 1:
        names_map = {}
        for line in lines:
            values = line.split()
            lv_name, mpath_name = values[0], values[1]
            names_map.update({lv_name: mpath_name})
    return names_map
Пример #18
0
 def setup_pv(self, vg):
     """
     Setup physical volume device if exists return it directly;
     """
     pvs = []
     emulate_image_file = self.get_emulate_image_name()
     cmd = "losetup -j %s" % emulate_image_file
     output = decode_to_text(process.system_output(cmd))
     try:
         pv_name = re.findall("(/dev/loop\d+)", output, re.M | re.I)[-1]
         pv = self.get_vol(pv_name, "pvs")
     except IndexError:
         pv = None
     if pv is None:
         img_file = self.make_emulate_image()
         pv_name = self.make_volume(img_file)
         pv_size = self.params["pv_size"]
         pv = PhysicalVolume(pv_name, pv_size)
         pv.create()
         self.register(pv)
     else:
         logging.warn("PhysicalVolume(%s) really exists" % pv_name +
                      "skip to create it")
     pv.set_vg(vg)
     pvs.append(pv)
     return pvs
Пример #19
0
    def cmd_output(self, command, timeout=60):
        """
        Get output from system_output. Add the command to the qemu-io command
        line with -c and record the output in the log file.
        :param command: command to execute in qemu-io
        :param timeout: timeout for execute the command
        """
        qemu_io_cmd = self.qemu_io_cmd
        if command:
            qemu_io_cmd += " -c '%s'" % command

        error_context.context("Running command: %s" % qemu_io_cmd,
                              self.log_func)
        output = decode_to_text(
            process.system_output(qemu_io_cmd, timeout=timeout))

        # Record command line in log file
        if self.output_func:
            params = self.output_params + (qemu_io_cmd, )
            self.output_func(*params)

            params = self.output_params + (output, )
            self.output_func(*params)

        return output
Пример #20
0
def iscsi_logout(target_name=None):
    """
    Logout from a target. If the target name is not set then logout all
    targets.

    :params target_name: Name of the target.
    """
    if target_name:
        cmd = "iscsiadm --mode node --logout -T %s" % target_name
    else:
        cmd = "iscsiadm --mode node --logout all"

    output = ''
    try:
        output = decode_to_text(process.system_output(cmd))
    except process.CmdError as detail:
        # iscsiadm will fail when no matching sessions found
        # This failure makes no sense when target name is not specified
        stderr = results_stderr_52lts(detail.result)
        if not target_name and 'No matching sessions' in stderr:
            logging.info("%s: %s", detail, stderr)
        else:
            raise

    target_logout = ""
    if "successful" in output:
        target_logout = target_name

    return target_logout
Пример #21
0
def nfs_exported(session=None):
    """
    Get the list for nfs file system already exported

    :param session: ShellSessionObject of remote/guest

    :return: a list of nfs that is already exported in system
    :rtype: a lit of nfs file system exported
    """
    func = process.system_output
    if session:
        func = session.cmd_output
    exportfs = decode_to_text(func("exportfs -v"))
    if not exportfs:
        return {}

    nfs_exported_dict = {}
    for fs_info in re.findall("[/\w+]+.*?\(.*?\)", exportfs, re.S):
        fs_info = fs_info.strip().split()
        if len(fs_info) == 2:
            nfs_src = fs_info[0]
            access_ip = re.findall(r"(.*)\(", fs_info[1])[0]
            if "world" in access_ip:
                access_ip = "*"
            nfs_tag = "%s_%s" % (nfs_src, access_ip)
            permission = re.findall(r"\((.*)\)", fs_info[1])[0]
            nfs_exported_dict[nfs_tag] = permission

    return nfs_exported_dict
Пример #22
0
 def setup_pv(self, vg):
     """
     Setup physical volume device if exists return it directly;
     """
     pvs = []
     emulate_image_file = self.get_emulate_image_name()
     cmd = "losetup -j %s" % emulate_image_file
     output = decode_to_text(process.system_output(cmd))
     try:
         pv_name = re.findall("(/dev/loop\d+)", output, re.M | re.I)[-1]
         pv = self.get_vol(pv_name, "pvs")
     except IndexError:
         pv = None
     if pv is None:
         img_file = self.make_emulate_image()
         pv_name = self.make_volume(img_file)
         pv_size = self.params["pv_size"]
         pv = PhysicalVolume(pv_name, pv_size)
         pv.create()
         self.register(pv)
     else:
         logging.warn("PhysicalVolume(%s) really exists" % pv_name +
                      "skip to create it")
     pv.set_vg(vg)
     pvs.append(pv)
     return pvs
Пример #23
0
    def snapshot_list(self):
        """
        List all snapshots in the given image
        """
        cmd = self.image_cmd
        cmd += " snapshot -l %s" % self.image_filename

        return decode_to_text(process.system_output(cmd))
Пример #24
0
    def snapshot_list(self):
        """
        List all snapshots in the given image
        """
        cmd = self.image_cmd
        cmd += " snapshot -l %s" % self.image_filename

        return decode_to_text(process.system_output(cmd))
Пример #25
0
 def get_chap_accounts(self):
     """
     Get all CHAP authentication accounts
     """
     cmd = "tgtadm --lld iscsi --op show --mode account"
     all_accounts = decode_to_text(process.system_output(cmd))
     if all_accounts:
         all_accounts = list(map(str.strip, all_accounts.splitlines()[1:]))
     return all_accounts
Пример #26
0
 def get_chap_accounts(self):
     """
     Get all CHAP authentication accounts
     """
     cmd = "tgtadm --lld iscsi --op show --mode account"
     all_accounts = decode_to_text(process.system_output(cmd))
     if all_accounts:
         all_accounts = list(map(str.strip, all_accounts.splitlines()[1:]))
     return all_accounts
Пример #27
0
def rbd_image_unmap(rbd_pool_name, rbd_image_name):
    """
    Unmaps the block device that was mapped via the rbd kernel module
    :params rbd_pool_name: The name of rbd pool
    :params rbd_image_name: The name of rbd image
    """
    cmd = "rbd unmap /dev/rbd/%s/%s" % (rbd_pool_name, rbd_image_name)
    output = decode_to_text(process.system_output(cmd, verbose=True))
    if os.path.exist(os.path.join("/dev/rbd", rbd_pool_name, rbd_image_name)):
        logging.debug("Failed to unmap image from local: %s" % output)
Пример #28
0
def is_gluster_vol_avail(vol_name):
    """
    Check if the volume already available
    """
    cmd = "gluster volume info"
    error_context.context("Gluster volume info failed")
    output = decode_to_text(process.system_output(cmd))
    volume_name = re.findall(r'Volume Name: (%s)\n' % vol_name, output)
    if volume_name:
        return gluster_vol_start(vol_name)
Пример #29
0
def rbd_image_unmap(rbd_pool_name, rbd_image_name):
    """
    Unmaps the block device that was mapped via the rbd kernel module
    :params rbd_pool_name: The name of rbd pool
    :params rbd_image_name: The name of rbd image
    """
    cmd = "rbd unmap /dev/rbd/%s/%s" % (rbd_pool_name, rbd_image_name)
    output = decode_to_text(process.system_output(cmd, verbose=True))
    if os.path.exist(os.path.join("/dev/rbd", rbd_pool_name, rbd_image_name)):
        logging.debug("Failed to unmap image from local: %s" % output)
Пример #30
0
    def snapshot_create(self):
        """
        Create a snapshot image.

        :note: params should contain:
               snapshot_image_name -- the name of snapshot image file
        """

        cmd = self.image_cmd
        if self.snapshot_tag:
            cmd += " snapshot -c %s" % self.snapshot_image_filename
        else:
            raise exceptions.TestError("Can not find the snapshot image"
                                       " parameters")
        cmd += " %s" % self.image_filename

        decode_to_text(process.system_output(cmd))

        return self.snapshot_tag
Пример #31
0
def is_gluster_vol_avail(vol_name):
    """
    Check if the volume already available
    """
    cmd = "gluster volume info"
    error_context.context("Gluster volume info failed")
    output = decode_to_text(process.system_output(cmd))
    volume_name = re.findall(r'Volume Name: (%s)\n' % vol_name, output)
    if volume_name:
        return gluster_vol_start(vol_name)
Пример #32
0
    def snapshot_create(self):
        """
        Create a snapshot image.

        :note: params should contain:
               snapshot_image_name -- the name of snapshot image file
        """

        cmd = self.image_cmd
        if self.snapshot_tag:
            cmd += " snapshot -c %s" % self.snapshot_image_filename
        else:
            raise exceptions.TestError("Can not find the snapshot image"
                                       " parameters")
        cmd += " %s" % self.image_filename

        decode_to_text(process.system_output(cmd))

        return self.snapshot_tag
Пример #33
0
def check_exit_status(result, expect_error=False, error_flag='strict'):
    """
    Check the exit status of virt-v2v/libguestfs commands

    :param result: Virsh command result object
    :param expect_error: Boolean value, expect command success or fail
    :param error_flag: same as errors argument in str.decode
    """
    if not expect_error:
        if result.exit_status != 0:
            raise exceptions.TestFail(
                decode_to_text(result.stderr, errors=error_flag))
        else:
            logging.debug(
                "Command output:\n%s",
                decode_to_text(result.stdout, errors=error_flag).strip())
    elif expect_error and result.exit_status == 0:
        raise exceptions.TestFail("Run '%s' expect fail, but run "
                                  "successfully." % result.command)
Пример #34
0
    def make_volume(self, img_file, extra_args=""):
        """
        Map a file to loop back device;

        :param img_file: image file path;
        :return: loop back device name;
        """
        cmd = "losetup %s --show --find %s" % (extra_args, img_file)
        pv_name = decode_to_text(process.system_output(cmd))
        self.params["pv_name"] = pv_name.strip()
        return pv_name
Пример #35
0
    def make_volume(self, img_file, extra_args=""):
        """
        Map a file to loop back device;

        :param img_file: image file path;
        :return: loop back device name;
        """
        cmd = "losetup %s --show --find %s" % (extra_args, img_file)
        pv_name = decode_to_text(process.system_output(cmd))
        self.params["pv_name"] = pv_name.strip()
        return pv_name
Пример #36
0
def check_memory_in_procfs(test, params, vm):
    """
    Check memory info in procfs

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param vm: VM object
    """
    qemu_pid = vm.get_pid()
    policy = params['policy_mem']
    if policy == 'preferred':
        policy = 'prefer'
    for mem_dev in params['mem_devs'].split():
        memdev_params = params.object_params(mem_dev)
        mem_size = memdev_params['size']
        mem_size = int(float(utils_misc.normalize_data_size(mem_size, "K")))
        smaps = process.system_output("grep -1 %d /proc/%d/smaps"
                                      % (mem_size, qemu_pid))
        smaps = decode_to_text(smaps).strip()
        mem_path = memdev_params.get("mem-path")
        if mem_path and (mem_path not in smaps):
            test.fail("memdev = %s: mem-path '%s' is not in smaps '%s'!"
                      % (mem_dev, mem_path, smaps))
        mem_start = smaps.split('-')[0]
        numa_maps = process.system_output("grep %s /proc/%d/numa_maps"
                                          % (mem_start, qemu_pid))
        numa_maps = decode_to_text(numa_maps).strip()
        if mem_path and (mem_path not in numa_maps):
            test.fail("memdev = %s: mem-path '%s' is not in numa_maps '%s'!"
                      % (mem_dev, mem_path, numa_maps))
        policy_numa = numa_maps.split()[1].split(':')
        if policy != policy_numa[0]:
            test.fail("memdev = %s:"
                      " 'policy' in numa_maps is '%s', but not '%s'!"
                      % (mem_dev, policy_numa[0], policy))
        elif (policy != 'default'):
            host_node = memdev_params['host-nodes']
            if (policy_numa[1] != host_node):
                test.fail("memdev = %s:"
                          " 'host-nodes' in numa_maps is '%s', but not '%s'!"
                          % (mem_dev, policy_numa[1], host_node))
Пример #37
0
def iscsi_get_nodes():
    """
    Get the iscsi nodes
    """
    cmd = "iscsiadm --mode node"

    output = decode_to_text(process.system_output(cmd, ignore_status=True))
    pattern = r"(\d+\.\d+\.\d+\.\d+|\[.+\]):\d+,\d+\s+([\w\.\-:\d]+)"
    nodes = []
    if "No records found" not in output:
        nodes = re.findall(pattern, output)
    return nodes
Пример #38
0
def run(test, params, env):
    """
    check time jumps in guest (only for Linux guest):

    1) boot guest with '-rtc base=utc,clock=host,driftfix=slew'
    2) check current clocksource in guest
    3) pin all vcpus to specfic host CPUs
    4) verify time jump

    :param test: QEMU test object.
    :param params: Dictionary with test parameters.
    :param env: Dictionary with the test environment.
    """
    vm = env.get_vm(params["main_vm"])
    session = vm.wait_for_login()

    error_context.context("Check the clock source currently used on guest",
                          logging.info)
    cmd = "cat /sys/devices/system/clocksource/"
    cmd += "clocksource0/current_clocksource"
    logging.info("%s is current clocksource." % session.cmd_output(cmd))

    error_context.context("Pin every vcpu to physical cpu", logging.info)
    host_cpu_cnt_cmd = params["host_cpu_cnt_cmd"]
    host_cpu_num = decode_to_text(process.system_output(host_cpu_cnt_cmd,
                                                        shell=True)).strip()
    host_cpu_list = (_ for _ in range(int(host_cpu_num)))
    if len(vm.vcpu_threads) > int(host_cpu_num):
        host_cpu_list = []
        for _ in range(len(vm.vcpu_threads)):
            host_cpu_list.append(_ % int(host_cpu_num))
    cpu_pin_list = list(zip(vm.vcpu_threads, host_cpu_list))

    for vcpu, pcpu in cpu_pin_list:
        process.system("taskset -p -c %s %s" % (pcpu, vcpu))

    check_cmd = params["check_cmd"]
    output = str(session.cmd_output(check_cmd)).splitlines()
    session.close()
    time_pattern = "%y-%m-%d %H:%M:%S"
    time_list = []
    for str_time in output:
        time_struct = time.strptime(str_time, time_pattern)
        etime = time.mktime(time_struct)
        time_list.append(etime)
    for idx, _ in enumerate(time_list):
        if idx < len(time_list) - 1:
            if _ == time_list[idx+1] or (_ + 1) == time_list[idx+1]:
                continue
            else:
                test.fail("Test fail, time jumps backward or forward on guest")
        else:
            break
Пример #39
0
def iscsi_get_nodes():
    """
    Get the iscsi nodes
    """
    cmd = "iscsiadm --mode node"

    output = decode_to_text(process.system_output(cmd, ignore_status=True))
    pattern = r"(\d+\.\d+\.\d+\.\d+|\[.+\]):\d+,\d+\s+([\w\.\-:\d]+)"
    nodes = []
    if "No records found" not in output:
        nodes = re.findall(pattern, output)
    return nodes
Пример #40
0
def run(test, params, env):
    """
    check time jumps in guest (only for Linux guest):

    1) boot guest with '-rtc base=utc,clock=host,driftfix=slew'
    2) check current clocksource in guest
    3) pin all vcpus to specfic host CPUs
    4) verify time jump

    :param test: QEMU test object.
    :param params: Dictionary with test parameters.
    :param env: Dictionary with the test environment.
    """
    vm = env.get_vm(params["main_vm"])
    session = vm.wait_for_login()

    error_context.context("Check the clock source currently used on guest",
                          logging.info)
    cmd = "cat /sys/devices/system/clocksource/"
    cmd += "clocksource0/current_clocksource"
    logging.info("%s is current clocksource." % session.cmd_output(cmd))

    error_context.context("Pin every vcpu to physical cpu", logging.info)
    host_cpu_cnt_cmd = params["host_cpu_cnt_cmd"]
    host_cpu_num = decode_to_text(
        process.system_output(host_cpu_cnt_cmd, shell=True)).strip()
    host_cpu_list = (_ for _ in range(int(host_cpu_num)))
    if len(vm.vcpu_threads) > int(host_cpu_num):
        host_cpu_list = []
        for _ in range(len(vm.vcpu_threads)):
            host_cpu_list.append(_ % int(host_cpu_num))
    cpu_pin_list = list(zip(vm.vcpu_threads, host_cpu_list))

    for vcpu, pcpu in cpu_pin_list:
        process.system("taskset -p -c %s %s" % (pcpu, vcpu))

    check_cmd = params["check_cmd"]
    output = str(session.cmd_output(check_cmd)).splitlines()
    session.close()
    time_pattern = "%y-%m-%d %H:%M:%S"
    time_list = []
    for str_time in output:
        time_struct = time.strptime(str_time, time_pattern)
        etime = time.mktime(time_struct)
        time_list.append(etime)
    for idx, _ in enumerate(time_list):
        if idx < len(time_list) - 1:
            if _ == time_list[idx + 1] or (_ + 1) == time_list[idx + 1]:
                continue
            else:
                test.fail("Test fail, time jumps backward or forward on guest")
        else:
            break
Пример #41
0
    def snapshot_del(self, blkdebug_cfg=""):
        """
        Delete a snapshot image.

        :param blkdebug_cfg: The configure file of blkdebug

        :note: params should contain:
               snapshot_image_name -- the name of snapshot image file
        """

        cmd = self.image_cmd
        if self.snapshot_tag:
            cmd += " snapshot -d %s" % self.snapshot_image_filename
        else:
            raise exceptions.TestError("Can not find the snapshot image"
                                       " parameters")
        if blkdebug_cfg:
            cmd += " blkdebug:%s:%s" % (blkdebug_cfg, self.image_filename)
        else:
            cmd += " %s" % self.image_filename

        decode_to_text(process.system_output(cmd))
Пример #42
0
def is_gluster_vol_started(vol_name):
    """
    Return true if the volume is started, if not send false
    """
    cmd = "gluster volume info %s" % vol_name
    error_context.context(
        "Gluster volume info failed for volume: %s" % vol_name)
    vol_info = decode_to_text(process.system_output(cmd))
    volume_status = re.findall(r'Status: (\S+)', vol_info)
    if 'Started' in volume_status:
        return True
    else:
        return False
Пример #43
0
 def delete_target(self):
     """
     Delete target from host.
     """
     cmd = "tgtadm --lld iscsi --mode target --op show"
     output = decode_to_text(process.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
             process.system(cmd)
     if self.restart_tgtd:
         restart_tgtd()
Пример #44
0
 def list_users(self, remote=True, sasldb_path="/etc/libvirt/passwd.db"):
     """
     List users in sasldb
     """
     cmd = "%s -f %s" % (self.sasl_user_cmd, sasldb_path)
     try:
         if remote:
             self.session = self.get_session()
             return self.session.cmd_output(cmd)
         else:
             return decode_to_text(process.system_output(cmd))
     except process.CmdError:
         logging.error("Failed to set a user's sasl password %s", cmd)
Пример #45
0
    def snapshot_del(self, blkdebug_cfg=""):
        """
        Delete a snapshot image.

        :param blkdebug_cfg: The configure file of blkdebug

        :note: params should contain:
               snapshot_image_name -- the name of snapshot image file
        """

        cmd = self.image_cmd
        if self.snapshot_tag:
            cmd += " snapshot -d %s" % self.snapshot_image_filename
        else:
            raise exceptions.TestError("Can not find the snapshot image"
                                       " parameters")
        if blkdebug_cfg:
            cmd += " blkdebug:%s:%s" % (blkdebug_cfg, self.image_filename)
        else:
            cmd += " %s" % self.image_filename

        decode_to_text(process.system_output(cmd))
Пример #46
0
 def list_users(self, remote=True, sasldb_path="/etc/libvirt/passwd.db"):
     """
     List users in sasldb
     """
     cmd = "%s -f %s" % (self.sasl_user_cmd, sasldb_path)
     try:
         if remote:
             self.session = self.get_session()
             return self.session.cmd_output(cmd)
         else:
             return decode_to_text(process.system_output(cmd))
     except process.CmdError:
         logging.error("Failed to set a user's sasl password %s", cmd)
Пример #47
0
def is_gluster_vol_started(vol_name):
    """
    Return true if the volume is started, if not send false
    """
    cmd = "gluster volume info %s" % vol_name
    error_context.context("Gluster volume info failed for volume: %s" %
                          vol_name)
    vol_info = decode_to_text(process.system_output(cmd))
    volume_status = re.findall(r'Status: (\S+)', vol_info)
    if 'Started' in volume_status:
        return True
    else:
        return False
Пример #48
0
 def delete_target(self):
     """
     Delete target from host.
     """
     cmd = "tgtadm --lld iscsi --mode target --op show"
     output = decode_to_text(process.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
             process.system(cmd)
     if self.restart_tgtd:
         restart_tgtd()
Пример #49
0
    def set_chap_acls_target(self):
        """
        set CHAP(acls) authentication on a target.
        it will require authentication
        before an initiator is allowed to log in and access devices.

        notice:
            Individual ACL entries override common TPG Authentication,
            which can be set by set_chap_auth_target().
        """
        # Enable ACL nodes
        acls_cmd = "targetcli /iscsi/%s/tpg1/ " % self.target
        attr_cmd = "set attribute generate_node_acls=0"
        process.system(acls_cmd + attr_cmd)

        # Create user and allow access
        acls_cmd = ("targetcli /iscsi/%s/tpg1/acls/ create %s:client" %
                    (self.target, self.target.split(":")[0]))
        output = decode_to_text(process.system_output(acls_cmd))
        if "Created Node ACL" not in output:
            raise exceptions.TestFail("Failed to create ACL. (%s)" % output)

        comm_cmd = ("targetcli /iscsi/%s/tpg1/acls/%s:client/" %
                    (self.target, self.target.split(":")[0]))
        # Set userid
        userid_cmd = "%s set auth userid=%s" % (comm_cmd, self.chap_user)
        output = decode_to_text(process.system_output(userid_cmd))
        if self.chap_user not in output:
            raise exceptions.TestFail("Failed to set user. (%s)" % output)

        # Set password
        passwd_cmd = "%s set auth password=%s" % (comm_cmd, self.chap_passwd)
        output = decode_to_text(process.system_output(passwd_cmd))
        if self.chap_passwd not in output:
            raise exceptions.TestFail("Failed to set password. (%s)" % output)

        # Save configuration
        process.system("targetcli / saveconfig")
Пример #50
0
    def set_chap_acls_target(self):
        """
        set CHAP(acls) authentication on a target.
        it will require authentication
        before an initiator is allowed to log in and access devices.

        notice:
            Individual ACL entries override common TPG Authentication,
            which can be set by set_chap_auth_target().
        """
        # Enable ACL nodes
        acls_cmd = "targetcli /iscsi/%s/tpg1/ " % self.target
        attr_cmd = "set attribute generate_node_acls=0"
        process.system(acls_cmd + attr_cmd)

        # Create user and allow access
        acls_cmd = ("targetcli /iscsi/%s/tpg1/acls/ create %s:client"
                    % (self.target, self.target.split(":")[0]))
        output = decode_to_text(process.system_output(acls_cmd))
        if "Created Node ACL" not in output:
            raise exceptions.TestFail("Failed to create ACL. (%s)" % output)

        comm_cmd = ("targetcli /iscsi/%s/tpg1/acls/%s:client/"
                    % (self.target, self.target.split(":")[0]))
        # Set userid
        userid_cmd = "%s set auth userid=%s" % (comm_cmd, self.chap_user)
        output = decode_to_text(process.system_output(userid_cmd))
        if self.chap_user not in output:
            raise exceptions.TestFail("Failed to set user. (%s)" % output)

        # Set password
        passwd_cmd = "%s set auth password=%s" % (comm_cmd, self.chap_passwd)
        output = decode_to_text(process.system_output(passwd_cmd))
        if self.chap_passwd not in output:
            raise exceptions.TestFail("Failed to set password. (%s)" % output)

        # Save configuration
        process.system("targetcli / saveconfig")
Пример #51
0
    def set_user_password(self, password, crypted=False, username="******"):
        """
        Set the new password for the user
        """
        cmd = "guest-set-user-password"
        self.check_has_command(cmd)

        if crypted:
            openssl_cmd = "openssl passwd -crypt %s" % password
            password = decode_to_text(process.system_output(openssl_cmd)).strip('\n')

        args = {"crypted": crypted, "username": username,
                "password": base64.b64encode(password.encode()).decode()}
        return self.cmd(cmd=cmd, args=args)
Пример #52
0
    def __reload_pvs(self):
        """
        Create PhysicalVolume objects for exist physical volumes;

        :return: list of Volume object
        """
        pvs = []
        cmd = "lvm pvs -opv_name,pv_size %s" % COMMON_OPTS
        output = decode_to_text(process.system_output(cmd))
        for line in output.splitlines():
            pv_name, pv_size = line.split()
            pv = PhysicalVolume(pv_name, pv_size)
            pvs.append(pv)
        return pvs
Пример #53
0
 def get_target_account_info(self):
     """
     Get the target account information
     """
     cmd = "tgtadm --lld iscsi --mode target --op show"
     target_info = decode_to_text(process.system_output(cmd))
     pattern = r"Target\s+\d:\s+%s" % self.target
     pattern += ".*Account information:\s(.*)ACL information"
     try:
         target_account = re.findall(pattern, target_info,
                                     re.S)[0].strip().splitlines()
     except IndexError:
         target_account = []
     return list(map(str.strip, target_account))
Пример #54
0
def iscsi_get_sessions():
    """
    Get the iscsi sessions activated
    """
    cmd = "iscsiadm --mode session"

    output = decode_to_text(process.system_output(cmd, ignore_status=True))
    sessions = []
    if "No active sessions" not in output:
        for session in output.splitlines():
            ip_addr = session.split()[2].split(',')[0]
            target = session.split()[3]
            sessions.append((ip_addr, target))
    return sessions
Пример #55
0
def rbd_image_exist(ceph_monitor, rbd_pool_name, rbd_image_name):
    """
    Check if rbd image is exist
    :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
    """
    cmd = "rbd ls %s -m %s" % (rbd_pool_name, ceph_monitor)
    output = decode_to_text(process.system_output(cmd, ignore_status=True,
                                                  verbose=True))

    logging.debug("Resopense from rbd ls command is: %s" % output)

    return (rbd_image_name.strip() in output.splitlines())
Пример #56
0
    def delete_target(self):
        """
        Delete target from host.
        """
        # Delete block
        if self.device is not None:
            cmd = "targetcli /backstores/fileio ls"
            output = decode_to_text(process.system_output(cmd))
            if re.findall("%s" % self.device, output, re.M):
                dev_del = ("targetcli /backstores/fileio/ delete %s"
                           % self.device)
                process.system(dev_del)

        # Delete IQN
        cmd = "targetcli ls /iscsi 1"
        output = decode_to_text(process.system_output(cmd))
        if re.findall("%s" % self.target, output, re.M):
            del_cmd = "targetcli /iscsi delete %s" % self.target
            process.system(del_cmd)

        # Save deleted configuration to avoid restoring
        cmd = "targetcli / saveconfig"
        process.system(cmd)
Пример #57
0
def add_rpc_insecure(filepath):
    """
    Allow glusterd RPC authority insecure
    """

    cmd = "cat %s" % filepath
    content = decode_to_text(process.system_output(cmd))
    match = re.findall(r'rpc-auth-allow-insecure on', content)
    logging.info("match is %s", match)
    if not match:
        logging.info("not match")
        cmd = "sed -i '/end-volume/i \ \ \ \ option rpc-auth-allow-insecure on' %s" % filepath
        process.system(cmd, shell=True)
        process.system("service glusterd restart; sleep 2", shell=True)
Пример #58
0
    def delete_target(self):
        """
        Delete target from host.
        """
        # Delete block
        if self.device is not None:
            cmd = "targetcli /backstores/fileio ls"
            output = decode_to_text(process.system_output(cmd))
            if re.findall("%s" % self.device, output, re.M):
                dev_del = ("targetcli /backstores/fileio/ delete %s" %
                           self.device)
                process.system(dev_del)

        # Delete IQN
        cmd = "targetcli ls /iscsi 1"
        output = decode_to_text(process.system_output(cmd))
        if re.findall("%s" % self.target, output, re.M):
            del_cmd = "targetcli /iscsi delete %s" % self.target
            process.system(del_cmd)

        # Save deleted configuration to avoid restoring
        cmd = "targetcli / saveconfig"
        process.system(cmd)
Пример #59
0
def check_exit_status(result, expect_error=False, error_flag='strict'):
    """
    Check the exit status of virt-v2v/libguestfs commands

    :param result: Virsh command result object
    :param expect_error: Boolean value, expect command success or fail
    :param error_flag: same as errors argument in str.decode
    """
    if not expect_error:
        if result.exit_status != 0:
            raise exceptions.TestFail(
                decode_to_text(
                    result.stderr,
                    errors=error_flag))
        else:
            logging.debug(
                "Command output:\n%s",
                decode_to_text(
                    result.stdout,
                    errors=error_flag).strip())
    elif expect_error and result.exit_status == 0:
        raise exceptions.TestFail("Run '%s' expect fail, but run "
                                  "successfully." % result.command)