Esempio n. 1
0
def pytest_collection_modifyitems(config, items):
    print("")

    set_transport(config.getoption("--transport"))
    if config.getoption("--local"):
        set_local()
    if config.getoption("--direct-python"):
        set_python_direct()
    set_logger()
    runtime_capabilities.collect_capabilities()
    if config.getoption("--async"):
        set_async()
    add_service_settings()
    adjust_surfaces_for_missing_implementations()
    only_include_scenario_tests(items, config.getoption("--scenario"))
    skip_unsupported_tests(items)

    # make sure the network is connected before starting (this can happen with interrupted runs)
    if settings.test_module.capabilities.v2_connect_group:
        settings.test_module.wrapper_api.network_reconnect_sync()

    if getattr(config, "_origargs", None):
        adapter_config.logger("HORTON: starting run: {}".format(
            config._origargs))
    elif getattr(config, "invocation_params", None):
        adapter_config.logger("HORTON: starting run: {}".format(
            config.invocation_params.args))

    if config.getoption("--debug-container"):
        print("Debugging the container.  Removing all timeouts")
        adapter_config.default_api_timeout = 3600
        config._env_timeout = 0

    dump_object(settings)
Esempio n. 2
0
def function_log_fixture(request):
    adapter_config.logger(separator)
    adapter_config.logger("HORTON: Entering function '{}.{}' '{}'".format(
        request.module.__name__, request.cls.__name__, request.node.name))

    def fin():
        adapter_config.logger(separator)
        if hasattr(request.node, "rep_setup"):
            adapter_config.logger("setup:      " +
                                  str(request.node.rep_setup.outcome))
        if hasattr(request.node, "rep_call"):
            adapter_config.logger("call:       " +
                                  str(request.node.rep_call.outcome))
        if hasattr(request.node, "rep_teardown"):
            adapter_config.logger("teardown:   " +
                                  str(request.node.rep_teardown.outcome))
        adapter_config.logger(separator)
        adapter_config.logger("HORTON: Cleaning up after function {}".format(
            request.function.__name__))

        try:
            adapters.cleanup_test_objects()
        except Exception:
            adapter_config.logger("Exception in cleanup")
            adapter_config.logger(traceback.format_exc())
            raise
        finally:
            adapter_config.logger(
                "HORTON: Exiting function '{}.{}' '{}'".format(
                    request.module.__name__, request.cls.__name__,
                    request.node.name))

    request.addfinalizer(fin)
Esempio n. 3
0
def module_log_fixture(request):
    adapter_config.logger("HORTON: Entering module {}".format(
        request.module.__name__))

    def fin():
        adapter_config.logger("HORTON: Exiting module {}".format(
            request.module.__name__))

    request.addfinalizer(fin)
Esempio n. 4
0
def session_log_fixture(request):
    adapter_config.logger("HORTON: Preforming pre-session cleanup")
    adapters.cleanup_test_objects()
    adapter_config.logger("HORTON: pre-session cleanup complete")

    def fin():
        adapter_config.logger("Preforming post-session cleanup")
        try:
            adapters.cleanup_test_objects()
        except Exception:
            adapter_config.logger("Exception in cleanup")
            adapter_config.logger(traceback.format_exc())
            raise
        finally:
            adapter_config.logger("HORTON: post-session cleanup complete")

    request.addfinalizer(fin)
Esempio n. 5
0
 def fin():
     adapter_config.logger("Preforming post-session cleanup")
     try:
         adapters.cleanup_test_objects()
     except Exception:
         adapter_config.logger("Exception in cleanup")
         adapter_config.logger(traceback.format_exc())
         raise
     finally:
         adapter_config.logger("HORTON: post-session cleanup complete")
def pytest_collection_modifyitems(config, items):
    print("")

    if not settings.test_module.connection_string:
        raise Exception(
            "settings are missing credentials.  Please run `horton get_credentials` and try again"
        )

    set_transport(config.getoption("--transport"))
    if config.getoption("--local"):
        set_local()
    if config.getoption("--python_inproc"):
        set_python_inproc()
    set_logger()
    runtime_capabilities.collect_all_capabilities()
    if config.getoption("--async"):
        set_async()
    add_service_settings()
    adjust_surfaces_for_missing_implementations()
    only_include_scenario_tests(items, config.getoption("--scenario"))

    if "stress" in config.getoption("--scenario"):
        set_sas_renewal()

    if getattr(config, "_origargs", None):
        adapter_config.logger("HORTON: starting run: {}".format(
            config._origargs))
    elif getattr(config, "invocation_params", None):
        adapter_config.logger("HORTON: starting run: {}".format(
            config.invocation_params.args))

    if config.getoption("--debug-container"):
        print("Debugging the container.  Removing all timeouts")
        adapter_config.default_api_timeout = 3600
        config._env_timeout = 0

    dump_object(settings)
Esempio n. 7
0
async def do_module_method_call(
    source_module,
    destination_module,
    destination_device_id,
    destination_module_id,
    registration_sleep=time_for_method_to_fully_register,
):
    """
    Helper function which invokes a method call on one module and responds to it from another module
    """
    adapter_config.logger("enabling methods on the destination")
    await destination_module.enable_methods()

    # start listening for method calls on the destination side
    adapter_config.logger("starting to listen from destination module")
    receiver_future = asyncio.ensure_future(
        destination_module.wait_for_method_and_return_response(
            method_name, status_code, method_invoke_parameters,
            method_response_body))
    adapter_config.logger(
        "sleeping for {} seconds to make sure all registration is complete".
        format(registration_sleep))
    await asyncio.sleep(registration_sleep)

    disconnect_edgehub()  # One point that could be good to disconnect edgeHub
    # await asyncio.sleep(1)
    connect_edgehub()
    adapter_config.logger("Sleeping")
    await asyncio.sleep(30)
    adapter_config.logger(" Done Sleeping")

    # invoking the call from caller side
    adapter_config.logger("invoking method call")
    response = await source_module.call_module_method(
        destination_device_id, destination_module_id, method_invoke_parameters)
    adapter_config.logger("method call complete.  Response is:")
    adapter_config.logger(str(response))

    # wait for that response to arrive back at the source and verify that it's all good.
    assert response["status"] == status_code
    # edge bug: the response that edge returns is stringified.  The same response that comes back from an iothub service call is not stringified
    if isinstance(response["payload"], str):
        response["payload"] = json.loads(response["payload"])
    assert response["payload"] == method_response_body

    await receiver_future
async def do_device_method_call(source_module, destination_module,
                                destination_device_id):
    """
    Helper function which invokes a method call on one module and responds to it from another module
    """
    try:
        adapter_config.logger("enabling methods on the destination")
        await destination_module.enable_methods()

        # start listening for method calls on the destination side
        adapter_config.logger("starting to listen from destination module")
        receiver_future = asyncio.ensure_future(
            destination_module.wait_for_method_and_return_response(
                method_name, status_code, method_invoke_parameters,
                method_response_body))
        await asyncio.sleep(time_for_method_to_fully_register)

        disconnect_edgehub()
        # invoking the call from caller side
        await asyncio.sleep(5)
        connect_edgehub()
        adapter_config.logger("invoking method call")
        response = await source_module.call_device_method(
            destination_device_id, method_invoke_parameters)
        adapter_config.logger("method call complete.  Response is:")
        adapter_config.logger(str(response))

        # wait for that response to arrive back at the source and verify that it's all good.
        adapter_config.logger("response = " + str(response) + "\n")
        assert response["status"] == status_code
        # edge bug: the response that edge returns is stringified.  The same response that comes back from an iothub service call is not stringified
        if isinstance(response["payload"], str):
            response["payload"] = json.loads(response["payload"])
        assert response["payload"] == method_response_body

        await receiver_future
    finally:
        connect_edgehub()
        restart_edgehub(hard=False)
Esempio n. 9
0
 def fin():
     adapter_config.logger("HORTON: Exiting module {}".format(
         request.module.__name__))