Exemple #1
0
def main(args):
    """
    Run cij analyser steps.

    If `preqs` is set, log files in the given TRUN path are searched
    for metric.yml-files and the TRUN will be updated with pass/fail for
    performance requirements.
    """
    trun = cij.runner.trun_from_file(args.trun_fpath)

    # pylint: disable=no-member
    rehome(trun.args.output, args.output, trun)

    try:
        err = 0
        if args.preqs:
            preqs_declr = preqs_from_file(args.preqs)
            preq_err = analyse_prequirements(trun, preqs_declr)
            if preq_err:
                cij.err('Failed to analyse prequirements')
            else:
                cij.info('Successfully analyzed prequirements')

            err += preq_err

        cij.runner.trun_to_file(trun, fpath=cij.runner.yml_fpath(args.output))
    except CIJError as ex:
        cij.err(f"main:FAILED to run analysis: {ex}")

    return err
Exemple #2
0
def wait(timeout=300):
    """Wait util target connected"""

    if env():
        cij.err("cij.ssh.wait: Invalid SSH environment")
        return 1

    timeout_backup = cij.ENV.get("SSH_CMD_TIMEOUT")

    try:
        time_start = time.time()

        cij.ENV["SSH_CMD_TIMEOUT"] = "3"

        while True:
            time_current = time.time()
            if (time_current - time_start) > timeout:
                cij.err("cij.ssh.wait: Timeout")
                return 1

            status, _, _ = command(["exit"], shell=True, echo=False)
            if not status:
                break

        cij.info("cij.ssh.wait: Time elapsed: %d seconds" % (time_current - time_start))

    finally:
        if timeout_backup is None:
            del cij.ENV["SSH_CMD_TIMEOUT"]
        else:
            cij.ENV["SSH_CMD_TIMEOUT"] = timeout_backup

    return 0
Exemple #3
0
def tcase_check_preqs(tcase: TestCase, preqs: dict,
                      tsuite_name: str) -> Tuple[int, bool]:
    """
    Retrieve metrics and check them against the given preqs.
    Logs results to tcase.analysis_log_fpath.
    """
    tc_err = 0

    test_metrics = _get_metrics(tcase.aux_root)
    if not test_metrics:
        cij.info(f"{tsuite_name}/{tcase.name} no measurements found")
        return tc_err, True

    # Check performance requirements against measured metrics
    with open(tcase.analysis_log_fpath, 'w', encoding="UTF-8") as alog:
        for metrics in test_metrics:
            checked_preqs = check_preqs(preqs, metrics)
            for cpreq in checked_preqs:
                cij.emph(f"{cpreq.key}: {cpreq.msg}", rval=int(cpreq.error))
                cij.emph(f"{cpreq.key}: {cpreq.msg} {cpreq.ctx}",
                         rval=int(cpreq.error),
                         file=alog)

            tc_err += sum(cpreq.error for cpreq in checked_preqs)
    return tc_err, False
Exemple #4
0
    def dump(self, offset=0, length=1):
        """Dump item"""

        for i in range(offset, offset + length):
            if "ctypes" in str(self.m_types):
                cij.info("Buff[%s]: %s" % (i, self.m_buf[i]))
            else:
                cij.info("Buff[%s]:" % i)
                dump(self.m_buf[i], 2)
Exemple #5
0
def cmd(command):
    """Send IPMI 'command' via ipmitool"""

    env()

    ipmi = cij.env_to_dict(PREFIX, EXPORTED + REQUIRED)

    command = "ipmitool -U %s -P %s -H %s -p %s %s" % (
        ipmi["USER"], ipmi["PASS"], ipmi["HOST"], ipmi["PORT"], command)
    cij.info("ipmi.command: %s" % command)

    return cij.util.execute(command, shell=True, echo=True)
Exemple #6
0
def dump(buf, indent=0, skip=""):
    """Dump UnionType/StructType to STDOUT"""
    if not isinstance(type(buf), (type(Union), type(Structure))):
        raise RuntimeError("Error type(%s)" % type(buf))

    for field in getattr(buf, '_fields_'):
        name, types = field[0], field[1]
        if name in skip:
            return
        value = getattr(buf, name)

        if isinstance(types, (type(Union), type(Structure))):
            cij.info("%s%s:" % (" " * indent, name))
            dump(value, indent + 2, skip)
        elif isinstance(types, type(Array)):
            for i, item in enumerate(value):
                name_index = "%s[%s]" % (name, i)

                if isinstance(types, (type(Union), type(Structure))):
                    cij.info("%s%s:" % (" " * indent, name_index))
                    dump(item, indent + 2, skip)
                else:
                    cij.info("%s%-12s: 0x%x" %
                             (" " * indent, name_index, item))
        else:
            cij.info("%s%-12s: 0x%x" % (" " * indent, name, value))
Exemple #7
0
def env():
    """Verify IPMI environment"""

    ipmi = cij.env_to_dict(PREFIX, REQUIRED)

    if ipmi is None:
        ipmi["USER"] = "******"
        ipmi["PASS"] = "******"
        ipmi["HOST"] = "localhost"
        ipmi["PORT"] = "623"
        cij.info("ipmi.env: USER: %s, PASS: %s, HOST: %s, PORT: %s" %
                 (ipmi["USER"], ipmi["PASS"], ipmi["HOST"], ipmi["PORT"]))

    cij.env_export(PREFIX, EXPORTED, ipmi)

    return 0
Exemple #8
0
def analyse_prequirements(trun: TestRun, preqs_declr) -> int:
    """
    Analyse trun and enforce test pass/fail based on the given performance
    requirements declaration.

    NOTE: updates relevant trun fields.
    """

    global_conf = preqs_declr.get("global", {})
    global_preqs = global_conf.get("metrics", {})
    global_tcase_preqs = global_conf.get("testcases", {})

    tr_err = 0

    for tplan in trun.testplans:
        tp_err = 0

        for tsuite in tplan.testsuites:
            ts_err = 0
            tsuite_preqs = preqs_declr.get(tsuite.name, {})

            for tcase in tsuite.testcases:
                tc_err = 0
                tcase_preqs = copy.deepcopy(global_preqs)
                tcase_preqs.update(global_tcase_preqs.get(tcase.name, {}))
                tcase_preqs.update(tsuite_preqs.get(tcase.name, {}))
                if not tcase_preqs:
                    continue

                cij.info(
                    f"{tsuite.name}/{tcase.name} checking {set(tcase_preqs)}")
                tc_err, skip = tcase_check_preqs(tcase, tcase_preqs,
                                                 tsuite.name)
                if skip:
                    continue

                tcase.status_preq = Status.Fail if tc_err else Status.Pass
                ts_err += tc_err

            tsuite.status_preq = Status.Fail if ts_err else Status.Pass
            tp_err += ts_err

        tplan.status_preq = Status.Fail if tp_err else Status.Pass
        tr_err += tp_err

    trun.status_preq = Status.Fail if tr_err else Status.Pass
    return 0
Exemple #9
0
    def __refresh(self):
        status, stdout, _ = cij.util.execute(["usbrelay"])
        if status:
            cij.err("cij.usb.relay: Error run usbrelay")
            return 1

        for line in stdout.strip().split("\n"):
            name, value = line.split("=")
            self.__field[name] = value

            if self.__device is None:
                self.__device = name.split("_")[0]
                cij.info("Device: %s" % self.__device)

            cij.info("%s: %s" % (name, value))

        if self.__field is None:
            cij.err("cij.usb.relay: Error usbrelay field")
            return 1

        return 0
Exemple #10
0
def reboot(timeout=300, extra=""):
    """Reboot target"""

    if env():
        cij.err("cij.ssh.reboot: Invalid SSH environment")
        return 1

    timeout_backup = cij.ENV.get("SSH_CMD_TIMEOUT")

    try:
        time_start = time.time()
        status, last_uptime, _ = command(["/usr/bin/uptime -s"], shell=True, echo=False)
        if status:
            return 1

        cij.ENV["SSH_CMD_TIMEOUT"] = "3"
        cij.info("cij.ssh.reboot: Target: %s" % cij.ENV.get("SSH_HOST"))
        command(["reboot %s" % extra], shell=True, echo=False)

        while True:
            time_current = time.time()
            if (time_current - time_start) > timeout:
                cij.err("cij.ssh.reboot: Timeout")
                return 1

            status, current_uptime, _ = command(["/usr/bin/uptime -s"], shell=True, echo=False)
            if not status and current_uptime != last_uptime:
                break

        cij.info("cij.ssh.reboot: Time elapsed: %d seconds" % (time_current - time_start))

    finally:
        if timeout_backup is None:
            del cij.ENV["SSH_CMD_TIMEOUT"]
        else:
            cij.ENV["SSH_CMD_TIMEOUT"] = timeout_backup

    return 0