示例#1
0
def check_coredump(context, do_report=True):
    coredump_search = "/var/lib/systemd/coredump/*"
    list_of_dumps = list_dumps(coredump_search)

    for dump_dir in list_of_dumps:
        if not dump_dir:
            continue
        print("Examing crash: " + dump_dir)
        dump_dir_split = dump_dir.split('.')
        if len(dump_dir_split) < 6:
            print("Some garbage in %s" % (dump_dir))
            continue
        if not check_dump_package(dump_dir_split[1]):
            continue
        try:
            pid, _ = int(dump_dir_split[4]), int(dump_dir_split[5])
        except Exception as e:
            print("Some garbage in %s: %s" % (dump_dir, str(e)))
            continue
        if not is_dump_reported(dump_dir):
            # 'coredumpctl debug' not available in RHEL7
            if "Maipo" in context.rh_release:
                dump = nmci.command_output(
                    'echo backtrace | coredumpctl gdb %d' % (pid))
            else:
                dump = nmci.command_output(
                    'echo backtrace | coredumpctl debug %d' % (pid))
            embed_dump(context, dump_dir, dump, "COREDUMP", do_report)
示例#2
0
def NM_log(cursor):
    file_name = "/tmp/journal-nm.log"

    with open(file_name, "w") as f:
        nmci.command_output(
            "sudo journalctl -u NetworkManager --no-pager -o cat %s" % cursor,
            stdout=f)

    if os.stat(file_name).st_size > 20000000:
        msg = "WARNING: 20M size exceeded in /tmp/journal-nm.log, skipping"
        print(msg)
        return msg

    return utf_only_open_read("/tmp/journal-nm.log")
示例#3
0
def note_NM_log(context):
    if not hasattr(context, 'noted'):
        context.noted = {}
    # do not use context, as log might be too big to embed
    context.noted['noted-value'] = nmci.command_output(
        "sudo journalctl -all -u NetworkManager --no-pager -o cat %s" %
        context.log_cursor)
示例#4
0
def setup_hostapd(context):
    wait_for_testeth0(context)
    arch = nmci.command_output("uname -p").strip()
    if arch != "s390x":
        # Install under RHEL7 only
        if nmci.command_code("grep -q Maipo /etc/redhat-release") == 0:
            nmci.run(
                "[ -f /etc/yum.repos.d/epel.repo ] || sudo rpm -i http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm"
            )
        nmci.run(
            "[ -x /usr/sbin/hostapd ] || (yum -y install hostapd; sleep 10)")
    if nmci.command_code("sh prepare/hostapd_wired.sh tmp/8021x/certs") != 0:
        nmci.run("sh prepare/hostapd_wired.sh teardown")
        assert False, "hostapd setup failed"
示例#5
0
def setup_hostapd_wireless(context):
    wait_for_testeth0(context)
    arch = nmci.command_output("uname -p").strip()
    if arch != "s390x":
        # Install under RHEL7 only
        if "Maipo" in context.rh_release:
            context.run(
                "[ -f /etc/yum.repos.d/epel.repo ] || sudo rpm -i http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm"
            )
        context.run(
            "[ -x /usr/sbin/hostapd ] || (yum -y install hostapd; sleep 10)")
    if context.command_code(
            "sh prepare/hostapd_wireless.sh tmp/8021x/certs namespace") != 0:
        context.run("sh prepare/hostapd_wireless.sh teardown")
        assert False, "hostapd_wireless setup failed"
    if not os.path.isfile('/tmp/wireless_hostapd_check.txt'):
        wifi_rescan(context)
def before_scenario(context, scenario):
    # set important context attributes
    context.nm_restarted = False
    context.nm_pid = nmci.lib.nm_pid()
    context.crashed_step = False
    context.log_cursor = ""
    context.arch = nmci.command_output("uname -p").strip()
    context.IS_NMTUI = IS_NMTUI
    context.rh_release = nmci.command_output("cat /etc/redhat-release")

    if IS_NMTUI:
        os.environ['TERM'] = 'dumb'
        # Do the cleanup
        if os.path.isfile('/tmp/tui-screen.log'):
            os.remove('/tmp/tui-screen.log')
        fd = open('/tmp/tui-screen.log', 'a+')
        nmci.lib.dump_status_nmtui(fd, 'before')
        fd.write('Screen recordings after each step:' +
                 '\n----------------------------------\n')
        fd.flush()
        fd.close()
        context.log = None
    else:
        if not os.path.isfile('/tmp/nm_wifi_configured') \
                and not os.path.isfile('/tmp/nm_dcb_inf_wol_sriov_configured'):
            if nmci.command_code(
                    "nmcli device |grep testeth0 |grep ' connected'") != 0:
                nmci.run(
                    "sudo nmcli connection modify testeth0 ipv4.may-fail no")
                nmci.run("sudo nmcli connection up id testeth0")
                for attempt in range(0, 10):
                    if nmci.command_code(
                            "nmcli device |grep testeth0 |grep ' connected'"
                    ) == 0:
                        break
                    time.sleep(1)

        os.environ['TERM'] = 'dumb'
        context.log = open('/tmp/log_%s.html' % scenario.name, 'w')

        # dump status before the test preparation starts
        nmci.lib.dump_status_nmcli(context, 'before %s' % scenario.name)
        context.start_timestamp = int(time.time())

    excepts = []
    if 'eth0' in scenario.tags \
            or 'delete_testeth0' in scenario.tags \
            or 'connect_testeth0' in scenario.tags \
            or 'restart' in scenario.tags \
            or 'dummy' in scenario.tags:
        try:
            nmci.tags.skip_restarts_bs(context, scenario)
        except Exception as e:
            excepts.append(str(e))

    for tag in nmci.tags.tag_registry:
        if tag.tag_name in scenario.tags and tag.before_scenario is not None:
            try:
                tag.before_scenario(context, scenario)
            except Exception:
                excepts.append(traceback.format_exc())
    assert not excepts, "Exceptions in before_scenario():\n" + "\n\n".join(
        excepts)

    context.nm_pid = nmci.lib.nm_pid()

    context.crashed_step = False

    print(("NetworkManager process id before: %s" % context.nm_pid))

    if context.nm_pid is not None and context.log is not None:
        context.log.write(
            "NetworkManager memory consumption before: %d KiB\n" %
            nmci.lib.nm_size_kb())
        if os.path.isfile("/etc/systemd/system/NetworkManager.service") \
                and nmci.command_code(
                    "grep -q valgrind /etc/systemd/system/NetworkManager.service") == 0:
            nmci.run(
                "LOGNAME=root HOSTNAME=localhost gdb /usr/sbin/NetworkManager "
                " -ex 'target remote | vgdb' -ex 'monitor leak_check summary' -batch",
                stdout=context.log,
                stderr=context.log)

    context.log_cursor = nmci.lib.new_log_cursor()
示例#7
0
def _before_scenario(context, scenario):
    time_begin = time.time()
    context.before_scenario_step_el = ET.Element("li", {
        "class": "step passed",
        "style": "margin-bottom:1rem;"
    })
    ET.SubElement(context.before_scenario_step_el,
                  "b").text = "Before scenario"
    duration_el = ET.SubElement(context.before_scenario_step_el, "small",
                                {"class": "step_duration"})
    embed_el = ET.SubElement(context.before_scenario_step_el, "div")
    context.html_formatter.actual["act_step_embed_span"] = embed_el

    # set important context attributes
    context.nm_restarted = False
    context.nm_pid = nmci.lib.nm_pid()
    context.crashed_step = False
    context.log_cursor = ""
    context.log_cursor_before_tags = nmci.lib.new_log_cursor()
    context.arch = nmci.command_output("uname -p").strip()
    context.IS_NMTUI = "nmtui" in scenario.effective_tags
    context.rh_release = nmci.command_output("cat /etc/redhat-release")
    release_i = context.rh_release.find("release ")
    if release_i >= 0:
        context.rh_release_num = float(
            context.rh_release[release_i:].split(" ")[1])
    else:
        context.rh_release_num = 0
    context.hypervisor = nmci.run("systemd-detect-virt")[0].strip()

    os.environ['TERM'] = 'dumb'

    # dump status before the test preparation starts
    nmci.lib.dump_status(context, 'Before Scenario', fail_only=True)

    if context.IS_NMTUI:
        nmci.run("sudo pkill nmtui")
        # Do the cleanup
        if os.path.isfile('/tmp/tui-screen.log'):
            os.remove('/tmp/tui-screen.log')
        fd = open('/tmp/tui-screen.log', 'a+')
        fd.write('Screen recordings after each step:' +
                 '\n----------------------------------\n')
        fd.flush()
        fd.close()
    else:
        if not os.path.isfile('/tmp/nm_wifi_configured') \
                and not os.path.isfile('/tmp/nm_dcb_inf_wol_sriov_configured'):
            if nmci.command_code(
                    "nmcli device |grep testeth0 |grep ' connected'") != 0:
                nmci.run(
                    "sudo nmcli connection modify testeth0 ipv4.may-fail no")
                nmci.run("sudo nmcli connection up id testeth0")
                for attempt in range(0, 10):
                    if nmci.command_code(
                            "nmcli device |grep testeth0 |grep ' connected'"
                    ) == 0:
                        break
                    time.sleep(1)
        context.start_timestamp = int(time.time())

    excepts = []
    if 'eth0' in scenario.tags \
            or 'delete_testeth0' in scenario.tags \
            or 'connect_testeth0' in scenario.tags \
            or 'restart' in scenario.tags \
            or 'dummy' in scenario.tags:
        try:
            nmci.tags.skip_restarts_bs(context, scenario)
        except Exception as e:
            excepts.append(str(e))

    for tag_name in scenario.tags:
        tag = nmci.tags.tag_registry.get(tag_name, None)
        if tag is not None and tag.before_scenario is not None:
            print("Executing @" + tag_name)
            t_start = time.time()
            t_status = "passed"
            try:
                tag.before_scenario(context, scenario)
            except Exception:
                t_status = "failed"
                excepts.append(traceback.format_exc())
            print(
                f"  @{tag_name} ... {t_status} in {time.time() - t_start:.3f}s"
            )

    context.nm_pid = nmci.lib.nm_pid()

    context.crashed_step = False

    print(("NetworkManager process id before: %s" % context.nm_pid))

    context.log_cursor = nmci.lib.new_log_cursor()

    nmci.lib.process_commands(context, "before_scenario")

    duration = time.time() - time_begin
    status = "failed" if excepts else "passed"
    print(f"before_scenario ... {status} in {duration:.3f}s")
    duration_el.text = f"({duration:.3f}s)"

    if excepts:
        context.before_scenario_step_el.set("class", "step failed")
        context.embed("text/plain", "\n\n".join(excepts),
                      "Exception in before scenario tags")
        assert False, "Exception in before scenario tags"
示例#8
0
def note_the_output_of(context, command):
    if not hasattr(context, 'noted'):
        context.noted = {}
    # use nmci as embed might be big in general
    context.noted['noted-value'] = nmci.command_output(command).strip()
示例#9
0
def new_log_cursor():
    return '"--after-cursor=%s"' % nmci.command_output(
        "journalctl --lines=0 --quiet --show-cursor").replace(
            "-- cursor: ", "").strip()