Ejemplo n.º 1
0
    def _next_entry(self):
        """Generator which yields entries from IPMI log files."""

        time_regex = re.compile(r"^(timestamp) \| (\d+_\d+_\d+_\d+:\d+:\d+)$")
        entry_regex = re.compile(r"^(.+)\|(.+)\|(.+)$")

        for line in self._lines:
            # Example of the string:
            # timestamp | 2017_01_04_11:02:46
            match = re.match(time_regex, line.strip())
            if match:
                timestamp = datetime.datetime.strptime(
                    match.group(2).strip(), '%Y_%m_%d_%H:%M:%S')
                yield (match.group(1).strip(), timestamp, "")
            else:
                # Example of the string:
                # System Fan 4     | 2491 RPM          | ok
                match = re.match(entry_regex, line.strip())
                if match:
                    val = match.group(2).strip()
                    data = val.split(' ', 1)
                    if val not in ["no reading", "disabled"] and len(data) > 1:
                        yield (match.group(1).strip(),
                               Trivial.str_to_num(data[0]), data[1])
                    else:
                        yield (match.group(1).strip(), None, None)
Ejemplo n.º 2
0
def _get_percentile(funcname):
    """
    Parses and validates the percentile statistics function name (e.g., "99%") and returns the
    percent value (99).
    """

    percent = Trivial.str_to_num(funcname[:-1])
    if percent <= 0 or percent >= 100:
        raise Error(
            f"bad percentile number in '{funcname}', should be in range of "
            f"(0, 100)")
    return percent
Ejemplo n.º 3
0
    def get_resolution(self):
        """Returns resolution of the delayed event devices in nanoseconds."""

        try:
            path = self._basedir / "resolution_nsec"
            with self._proc.open(path, "r") as fobj:
                resolution = fobj.read().strip()
        except Error as err:
            raise Error(
                f"failed to read the delayed event resolution from '{path}'"
                f"{self._proc.hostmsg}:\n{err}") from err

        return Trivial.str_to_num(resolution)
Ejemplo n.º 4
0
    def _set_launch_distance(self):
        """Set launch distance limits to driver."""

        try:
            limit_path = self._basedir / "ldist_max_nsec"
            with self._proc.open(limit_path, "r") as fobj:
                ldist_max = fobj.read().strip()

            limit_path = self._basedir / "ldist_min_nsec"
            with self._proc.open(limit_path, "r") as fobj:
                ldist_min = fobj.read().strip()
        except Error as err:
            raise Error(
                f"failed to read launch distance limit from '{limit_path}'"
                f"{self._proc.hostmsg}:\n{err}") from err

        ldist_min = Trivial.str_to_num(ldist_min)
        ldist_max = Trivial.str_to_num(ldist_max)
        from_path = self._basedir / "ldist_from_nsec"
        to_path = self._basedir / "ldist_to_nsec"

        for idx, ldist in enumerate(self._ldist):
            if not ldist:
                # Special case: 0 means "use the minimum possible value".
                self._ldist[idx] = ldist_min

        for ldist, ldist_path in zip(self._ldist, [from_path, to_path]):
            if ldist < ldist_min or ldist > ldist_max:
                raise Error(
                    f"launch distance '{ldist}' is out of range, it should be in range of "
                    f"[{ldist_min},{ldist_max}]")
            try:
                with self._proc.open(ldist_path, "w") as fobj:
                    fobj.write(str(ldist))
            except Error as err:
                raise Error(
                    f"can't to change launch disatance range\nfailed to open '{ldist_path}'"
                    f"{self._proc.hostmsg} and write {ldist} to it:\n\t{err}"
                ) from err
Ejemplo n.º 5
0
def deploy_command(args):
    """Implements the 'deploy' command for the 'wult' and 'ndl' tools."""

    args.stmpdir = None # Temporary directory on the SUT.
    args.ctmpdir = None # Temporary directory on the controller (local host).

    if not FSHelpers.which("rsync", default=None):
        raise Error("please, install the 'rsync' tool")

    if not args.timeout:
        args.timeout = 8
    else:
        args.timeout = Trivial.str_to_num(args.timeout)
    if not args.username:
        args.username = "******"

    if args.privkey and not args.privkey.is_file():
        raise Error(f"path '{args.privkey}' does not exist or it is not a file")

    if args.pyhelpers:
        # Local temporary directory is only needed for creating stand-alone version of python
        # helpers.
        args.ctmpdir = FSHelpers.mktemp(prefix=f"{args.toolname}-")

    with contextlib.closing(ToolsCommon.get_proc(args, args.hostname)) as proc:
        if not FSHelpers.which("make", default=None, proc=proc):
            raise Error(f"please, install the 'make' tool{proc.hostmsg}")

        if proc.is_remote or not args.ctmpdir:
            args.stmpdir = FSHelpers.mktemp(prefix=f"{args.toolname}-", proc=proc)
        else:
            args.stmpdir = args.ctmpdir

        success = True
        try:
            _deploy_drivers(args, proc)
            _deploy_helpers(args, proc)
        except:
            success = False
            raise
        finally:
            _remove_deploy_tmpdir(args, proc, success=success)