Beispiel #1
0
def _analyze_vlogs(fnames):
    """Analyze log file(s)."""

    # initialize
    if isinstance(fnames, str):
        fnames = [fnames]
    select_menu_option("analyze_vlog")
    dlg = wait_for_elem(2, ".ui-dialog.lfa-upload")

    # add each log file
    for fno, fname in enumerate(fnames):
        fname = os.path.join(
            os.path.split(__file__)[0], "fixtures/analyze-vlog/" + fname)
        with open(fname, "rb") as fp:
            vlog_data = fp.read()
        set_stored_msg(
            "_vlog-persistence_", "{}|{}".format(
                os.path.split(fname)[1],
                base64.b64encode(vlog_data).decode("utf-8")))
        find_child("#lfa-upload .{}".format("hint" if fno == 0 else "files"),
                   dlg).click()
        wait_for(2, lambda: get_stored_msg("_vlog-persistence_") == "")

    # start the analysis
    find_child("button.ok", dlg).click()
    wait_for_elem(30, "#lfa")
Beispiel #2
0
def load_scenario(scenario, webdriver=None):
    """Load a scenario into the UI."""
    set_stored_msg("_scenario-persistence_", json.dumps(scenario), webdriver)
    _ = set_stored_msg_marker("_last-info_", webdriver)
    select_menu_option("load_scenario", webdriver)
    wait_for(
        2, lambda: get_stored_msg("_last-info_", webdriver) ==
        "The scenario was loaded.")
 def prep_upload2(dlg):
     """Prepare the upload."""
     assert asa_upload["user"] == user_name
     assert asa_upload["token"] == api_token
     # send the VSAV data to the front-end
     fname = os.path.join(os.path.dirname(__file__),
                          "fixtures/update-vsav/full.vsav")
     with open(fname, "rb") as fp:
         vsav_data = fp.read()
     set_stored_msg("_vsav-persistence_",
                    base64.b64encode(vsav_data).decode("utf-8"))
     find_child(".vsav-container", dlg).click()
     # wait for the files to be prepared
     wait_for(
         60, lambda: "loader.gif" not in find_child(
             ".screenshot-container .preview img").get_attribute("src"))
def _update_vsav(fname, expected):
    """Update a VASL scenario."""

    # read the VSAV data
    with open(fname, "rb") as fp:
        vsav_data = fp.read()

    # send the VSAV data to the front-end to be updated
    set_stored_msg("_vsav-persistence_",
                   base64.b64encode(vsav_data).decode("utf-8"))
    _ = set_stored_msg_marker("_last-info_")
    _ = set_stored_msg_marker("_last-warning_")
    select_menu_option("update_vsav")

    # wait for the front-end to receive the data
    def check_response():
        # NOTE: If something is misconfigured, the error response can get stored in the persistence buffer
        # really quickly i.e. before we get a chance to detect it here being cleared first.
        resp = get_stored_msg("_vsav-persistence_")
        return resp == "" or resp.startswith("ERROR:")

    wait_for(2, check_response)

    # wait for the updated data to come back
    timeout = 120 if os.name == "nt" else 60
    wait_for(timeout, lambda: get_stored_msg("_vsav-persistence_") != "")
    updated_vsav_data = get_stored_msg("_vsav-persistence_")
    if updated_vsav_data.startswith("ERROR: "):
        raise RuntimeError(updated_vsav_data)
    updated_vsav_data = base64.b64decode(updated_vsav_data)

    # parse the VASSAL shim report
    if expected:
        report = {}
        msg = get_stored_msg("_last-warning_" if "deleted" in
                             expected else "_last-info_")
        assert "The VASL scenario was updated:" in msg
        for mo2 in re.finditer("<li>([^<]+)", msg):
            mo3 = re.search(r"^(\d+) labels? (were|was) ([a-z]+)",
                            mo2.group(1))
            report[mo3.group(3)] = int(mo3.group(1))
        assert report == expected
    else:
        assert "No changes were made" in get_stored_msg("_last-info_")

    return updated_vsav_data
Beispiel #5
0
def _do_upload_template_pack(data, error_expected):
    """Upload a template pack."""

    # upload the template pack
    set_stored_msg("_template-pack-persistence_", data)
    info_marker = set_stored_msg_marker("_last-info_")
    error_marker = set_stored_msg_marker("_last-error_")
    select_menu_option("template_pack")

    # wait for the front-end to finish
    if error_expected:
        func = lambda: get_stored_msg("_last-error_") != error_marker
    else:
        func = lambda: "was loaded" in get_stored_msg("_last-info_")
    wait_for(2, func)

    return info_marker, error_marker
def analyze_vsav(fname, expected_ob1, expected_ob2, expected_report):
    """Analyze a VASL scenario."""

    # read the VSAV data
    fname = os.path.join(
        os.path.split(__file__)[0], "fixtures/analyze-vsav/" + fname)
    with open(fname, "rb") as fp:
        vsav_data = fp.read()

    # send the VSAV data to the front-end to be analyzed
    set_stored_msg("_vsav-persistence_",
                   base64.b64encode(vsav_data).decode("utf-8"))
    prev_info_msg = set_stored_msg_marker("_last-info_")
    set_stored_msg_marker("_last-warning_")
    select_menu_option("analyze_vsav")

    # wait for the analysis to finish
    wait_for(2, lambda: find_child("#please-wait").is_displayed())
    wait_for(60, lambda: not find_child("#please-wait").is_displayed())

    # check the results
    saved_scenario = save_scenario()

    def get_ids(key):  #pylint: disable=missing-docstring
        return set(
            (v["id"], v.get("image_id")) for v in saved_scenario.get(key, []))

    def adjust_expected(vals):  #pylint: disable=missing-docstring
        return set(v if isinstance(v, tuple) else (v, None) for v in vals)

    assert get_ids("OB_VEHICLES_1") == adjust_expected(expected_ob1[0])
    assert get_ids("OB_ORDNANCE_1") == adjust_expected(expected_ob1[1])
    assert get_ids("OB_VEHICLES_2") == adjust_expected(expected_ob2[0])
    assert get_ids("OB_ORDNANCE_2") == adjust_expected(expected_ob2[1])

    # check the report
    msg = get_stored_msg("_last-info_")
    if msg == prev_info_msg:
        msg = get_stored_msg("_last-warning_")
    assert all(e in msg for e in expected_report)
def update_vsav_thread(webapp_url, vsav_fname, vsav_data):
    """Test updating VASL scenario files."""

    # initialize
    vsav_data_b64 = base64.b64encode(vsav_data).decode("utf-8")

    with WebDriver() as webdriver:

        # initialize
        webdriver = webdriver.driver
        init_webapp(webdriver, webapp_url,
                    ["vsav_persistence", "scenario_persistence"])

        # load a test scenario
        fname = os.path.join(
            os.path.split(__file__)[0],
            "../webapp/tests/fixtures/update-vsav/full.json")
        with open(fname, "r", encoding="utf-8") as fp:
            saved_scenario = json.load(fp)
        load_scenario(saved_scenario, webdriver)

        while not shutdown_event.is_set():

            try:

                # send the VSAV data to the front-end to be updated
                log("Updating VSAV: {}", vsav_fname)
                set_stored_msg("_vsav-persistence_", vsav_data_b64, webdriver)
                select_menu_option("update_vsav", webdriver)
                start_time = time.time()

                # wait for the front-end to receive the data
                wait_for(
                    2 * thread_count, lambda: get_stored_msg(
                        "_vsav-persistence_", webdriver) == "")

                # wait for the updated data to arrive
                wait_for(
                    60 * thread_count, lambda: get_stored_msg(
                        "_vsav-persistence_", webdriver) != "")
                elapsed_time = time.time() - start_time

                # get the updated VSAV data
                updated_vsav_data = get_stored_msg("_vsav-persistence_",
                                                   webdriver)
                if updated_vsav_data.startswith("ERROR: "):
                    raise RuntimeError(updated_vsav_data)
                updated_vsav_data = base64.b64decode(updated_vsav_data)

                # check the updated VSAV
                log("Received updated VSAV data: #bytes={}",
                    len(updated_vsav_data))
                assert updated_vsav_data[:2] == b"PK"

                # update the stats
                with stats_lock:
                    stats["update vsav"][0] += 1
                    stats["update vsav"][1] += elapsed_time

            except (ConnectionRefusedError, ConnectionResetError,
                    http.client.RemoteDisconnected):
                if shutdown_event.is_set():
                    break
                raise