Ejemplo n.º 1
0
        if args.all or all_containers[container_name].required:
            setattr(args, container_name,
                    all_containers[container_name].lkg_image)

if not ("IOTHUB_E2E_REPO_ADDRESS" in os.environ and "IOTHUB_E2E_REPO_USER"
        in os.environ and "IOTHUB_E2E_REPO_PASSWORD" in os.environ):
    print(
        "Error: Docker container repository credentials are not set in IOTHUB_E2E_REPO* environment variables."
    )
    sys.exit(1)

service_connection_string = os.environ["IOTHUB_E2E_CONNECTION_STRING"]
host = connection_string_to_sas_token(service_connection_string)["host"]
edge_hub_device_id = os.environ["IOTHUB_E2E_EDGEHUB_DEVICE_ID"]

print("Operating with device {} on on hub {}".format(edge_hub_device_id, host))
print()
print("Deploying the following containers:")
containers_to_deploy = set()
for container_name in all_containers:
    if hasattr(args, container_name) and getattr(args, container_name):
        container = all_containers[container_name]
        container.image_to_deploy = getattr(args, container_name)
        print("{:>10}: {}".format(container_name, container.image_to_deploy))
        containers_to_deploy.add(container_name)

hub = useExistingHubInstance(service_connection_string, edge_hub_device_id)

containers = ",".join(containers_to_deploy)
hub.deployModules(containers)
Ejemplo n.º 2
0
def setupExecutionEnvironment():
    """
  Finish getting details needed for executing tests. This includes information that comes from the service,
  such as connection strings, and also endpoint URIs that can't be built until after command lines are parsed
  in conftest.py (which happens after all modules are loaded)
  """
    global leaf_device_id, leaf_device_connection_string
    global module_id, test_module_connection_string
    global friend_module_id, friend_module_connection_string
    global test_module_uri, friend_module_uri, leaf_device_uri
    global registry_uri, service_client_uri
    global test_module_connect_from_environment, friend_module_connect_from_environment
    global ca_certificate
    global test_module_transport, friend_module_transport
    global language

    if conftest.language == "ppdirect":
        container_under_test = all_containers["pythonpreview"]
    else:
        container_under_test = all_containers[conftest.language]

    hub = edgehub_factory.useExistingHubInstance(service_connection_string,
                                                 edge_device_id)

    module_id = container_under_test.module_id

    friend_module_id = all_containers["friend"].module_id

    leaf_device_id = hub.leaf_device_id

    test_module_connection_string = container_under_test.connection_string

    friend_module_connection_string = all_containers[
        "friend"].connection_string

    leaf_device_connection_string = hub.leaf_device_connection_string

    if test_module_connection_string is None or test_module_connection_string == "":
        raise Exception(
            "test module has not been deployed.  You need to deploy your langauge module (even if you're testing locally)"
        )
    if friend_module_connection_string is None or friend_module_connection_string == "":
        raise Exception("friend module has not been deployed.")
    if leaf_device_connection_string is None or leaf_device_connection_string == "":
        raise Exception(
            "Leaf device does not appear to have an iothub identity.  You may need to re-run create-new-edgehub-device.sh"
        )

    if conftest.local:
        edge_test_container = "http://localhost:" + str(
            container_under_test.local_port)
    else:
        edge_test_container = ("http://" + host_for_rest_uri + ":" +
                               str(container_under_test.host_port))

    edge_friend_container = ("http://" + host_for_rest_uri + ":" +
                             str(all_containers["friend"].host_port))

    if not conftest.direct_to_iothub:
        # route all of our devices through edgeHub if necessary
        gatewayHostSuffix = ";GatewayHostName=" + gateway_host_name
        test_module_connection_string = (test_module_connection_string +
                                         gatewayHostSuffix)
        friend_module_connection_string = (friend_module_connection_string +
                                           gatewayHostSuffix)
        leaf_device_connection_string = (leaf_device_connection_string +
                                         gatewayHostSuffix)
    else:
        # no certificate if we're going straight to iothub
        ca_certificate = {}
        test_module_connect_from_environment = False
        friend_module_connect_from_environment = False

    test_module_uri = edge_test_container

    friend_module_uri = edge_friend_container

    leaf_device_uri = edge_test_container
    if container_under_test.deviceImpl is False:
        leaf_device_uri = edge_friend_container

    registry_uri = edge_test_container
    if container_under_test.registryImpl is False:
        registry_uri = edge_friend_container

    service_client_uri = edge_test_container
    if container_under_test.serviceImpl is False:
        service_client_uri = edge_friend_container

    if conftest.test_module_use_connection_string:
        test_module_connect_from_environment = False

    test_module_transport = conftest.transport

    #  friend_module_transport = conftest.transport

    def friendly_uri(uri):
        if uri == edge_test_container:
            return uri + " (module under test)"
        elif uri == edge_friend_container:
            return uri + " (friend container)"
        else:
            return uri + " (some other container)"

    language = conftest.language

    if language == "ppdirect":
        adapters.add_direct_iot_sdk_adapter(name="TestModuleClient",
                                            api_surface="ModuleApi")
    else:
        adapters.add_rest_adapter(name="TestModuleClient",
                                  api_surface="ModuleApi",
                                  uri=test_module_uri)
    adapters.add_rest_adapter(name="FriendModuleClient",
                              api_surface="ModuleApi",
                              uri=friend_module_uri)
    adapters.add_rest_adapter(name="LeafDeviceClient",
                              api_surface="DeviceApi",
                              uri=leaf_device_uri)
    adapters.add_rest_adapter(name="RegistryClient",
                              api_surface="RegistryApi",
                              uri=registry_uri)
    adapters.add_rest_adapter(name="ServiceClient",
                              api_surface="ServiceApi",
                              uri=service_client_uri)
    adapters.add_direct_eventhub_adapter()

    print("Run Parameters:")
    print("  language:             {}".format(language))
    print("  module_id:            {}".format(module_id))
    print("  friend_module_id:     {}".format(friend_module_id))
    print("  leaf_device_id:       {}".format(leaf_device_id))
    print("  using environment:    {}".format(
        test_module_connect_from_environment))
    print("  test transport:       {}".format(test_module_transport))
    print("  friend transport:     {}".format(friend_module_transport))
    print("  destination:          {}".format(
        "iothub" if conftest.direct_to_iothub else "edgehub"))
Ejemplo n.º 3
0
def set_runtime_configuration(scenario, language, transport, local):
    global runtime_config

    if language == "ppdirect":
        runtime_config = runtime_config_templates.get_runtime_config_direct(
            scenario)
    else:
        runtime_config = runtime_config_templates.get_runtime_config(scenario)

    ensure_edge_environment_variables()

    # connection string for the IoTHub instance that is hosting your edgeHub instance.
    service_connection_string = os.environ["IOTHUB_E2E_CONNECTION_STRING"]

    # deviceId for your edgeHub instance
    edge_device_id = os.environ["IOTHUB_E2E_EDGEHUB_DEVICE_ID"]

    # Are we using a gateway?  If so, collect the bits we need
    use_gateway_host = False
    if scenarios.USE_IOTEDGE_GATEWAYHOST in scenario.scenario_flags:
        use_gateway_host = True
        gateway_host_name = os.environ["IOTHUB_E2E_EDGEHUB_DNS_NAME"]
        gateway_host_suffix = ";GatewayHostName=" + gateway_host_name
        if "IOTHUB_E2E_EDGEHUB_CA_CERT" in os.environ:
            runtime_config.ca_certificate = {
                "cert":
                base64.b64decode(
                    os.environ["IOTHUB_E2E_EDGEHUB_CA_CERT"]).decode("utf-8")
            }
        else:
            raise Exception(
                "IOTHUB_E2E_EDGEHUB_CA_CERT missing from environment.  Do you need to run `eval $(../scripts/get-environment.sh)`?"
            )

    # DNS name for host that is running your edge hub instance
    host_for_rest_uri = os.environ["IOTHUB_E2E_EDGEHUB_DNS_NAME"]
    # If we're on the actual machine, just use localhost instead
    config_yaml = Path("/etc/iotedge/config.yaml")
    if config_yaml.is_file():
        host_for_rest_uri = "localhost"

    # set up eventhub, the service client, and the registry client
    runtime_config.service.connection_string = service_connection_string
    runtime_config.registry.connection_string = service_connection_string
    runtime_config.eventhub.connection_string = service_connection_string

    # set up the device and module adapters that we're going to use
    if language == "ppdirect":
        container_under_test = all_containers["pythonpreview"]
    else:
        container_under_test = all_containers[language]

    hub = edgehub_factory.useExistingHubInstance(service_connection_string,
                                                 edge_device_id)
    if getattr(runtime_config, "iotedge", None):
        runtime_config.iotedge.device_id = edge_device_id

    if getattr(runtime_config, "test_module", None):
        runtime_config.test_module.device_id = edge_device_id
        runtime_config.test_module.module_id = container_under_test.module_id
        runtime_config.test_module.connection_string = (
            container_under_test.connection_string)
        if use_gateway_host:
            runtime_config.test_module.connection_string += gateway_host_suffix
        if local:
            runtime_config.test_module.rest_uri = "http://localhost:" + str(
                container_under_test.local_port)
        else:
            runtime_config.test_module.rest_uri = (
                "http://" + host_for_rest_uri + ":" +
                str(container_under_test.host_port))
        runtime_config.test_module.transport = transport
        if not runtime_config.test_module.connection_string:
            raise Exception(
                "test module has not been deployed.  You need to deploy your langauge module (even if you're testing locally)"
            )
        if local:
            runtime_config.test_module.connection_type = (
                runtime_config_templates.CONNECTION_STRING)

    friend_mod_rest_uri = ("http://" + host_for_rest_uri + ":" +
                           str(all_containers["friend"].host_port))
    if getattr(runtime_config, "friend_module", None):
        runtime_config.friend_module.device_id = edge_device_id
        runtime_config.friend_module.module_id = all_containers[
            "friend"].module_id
        runtime_config.friend_module.connection_string = all_containers[
            "friend"].connection_string
        if use_gateway_host:
            runtime_config.friend_module.connection_string += gateway_host_suffix
        runtime_config.friend_module.rest_uri = friend_mod_rest_uri
        if not runtime_config.friend_module.connection_string:
            raise Exception("friend module has not been deployed.")

    if getattr(runtime_config, "leaf_device", None):
        runtime_config.leaf_device.device_id = hub.leaf_device_id
        runtime_config.leaf_device.connection_string = hub.leaf_device_connection_string
        if use_gateway_host:
            runtime_config.leaf_device.connection_string += gateway_host_suffix
        if container_under_test.deviceImpl:
            runtime_config.leaf_device.rest_uri = runtime_config.test_module.rest_uri
        else:
            runtime_config.leaf_device.rest_uri = runtime_config.friend_module.rest_uri
        if not runtime_config.leaf_device.connection_string:
            raise Exception(
                "Leaf device does not appear to have an iothub identity.  You may need to re-run create-new-edgehub-device.sh"
            )

    # use the leaf device identity for our test_device tests for now.  This will change after we
    # update our deployment scripts
    if getattr(runtime_config, "test_device", None):
        runtime_config.test_device.device_id = hub.leaf_device_id
        runtime_config.test_device.connection_string = hub.leaf_device_connection_string
        if use_gateway_host:
            runtime_config.test_device.connection_string += gateway_host_suffix
        runtime_config.test_device.rest_uri = runtime_config.test_module.rest_uri
        if not runtime_config.test_device.connection_string:
            raise Exception(
                "Leaf device does not appear to have an iothub identity.  You may need to re-run create-new-edgehub-device.sh"
            )

    if language != "ppdirect":
        if container_under_test.registryImpl:
            runtime_config.registry.rest_uri = runtime_config.test_module.rest_uri
        else:
            runtime_config.registry.rest_uri = friend_mod_rest_uri

        if container_under_test.serviceImpl:
            runtime_config.service.rest_uri = runtime_config.test_module.rest_uri
        else:
            runtime_config.service.rest_uri = friend_mod_rest_uri

    if language == "ppdirect":
        runtime_config.test_module.connection_type = (
            runtime_config_templates.CONNECTION_STRING)

    for object_name in dir(runtime_config):
        test_obj = getattr(runtime_config, object_name)
        if getattr(test_obj, "test_object_type", None):
            adapter_type = getattr(test_obj, "adapter_type", None)
            if not adapter_type:
                pass
            elif adapter_type == runtime_config_templates.REST_ADAPTER:
                adapters.add_rest_adapter(
                    name=test_obj.api_name,
                    api_surface=test_obj.api_surface,
                    uri=test_obj.rest_uri,
                )
            elif adapter_type == runtime_config_templates.DIRECT_AZURE_ADAPTER:
                adapters.add_direct_azure_rest_adapter(
                    name=test_obj.api_name, api_surface=test_obj.api_surface)
            elif adapter_type == runtime_config_templates.DIRECT_PYTHON_SDK_ADAPTER:
                adapters.add_direct_python_sdk_adapter(
                    name=test_obj.api_name, api_surface=test_obj.api_surface)

    pprint(runtime_config_serializer.obj_to_dict(runtime_config))
Ejemplo n.º 4
0
def setupExecutionEnvironment():
    """
  Finish getting details needed for executing tests. This includes information that comes from the service,
  such as connection strings, and also endpoint URIs that can't be built until after command lines are parsed
  in conftest.py (which happens after all modules are loaded)
  """
    global runtime_config
    runtime_config.iotedge = config.IotEdgeDevice()
    runtime_config.friend_module = config.EdgeHubModuleRest(
        "FriendModuleClient")
    runtime_config.eventhub = config.EventHubDirect()

    if conftest.language == "ppdirect":
        container_under_test = all_containers["pythonpreview"]
        runtime_config.service = config.IotHubServiceDirect()
        runtime_config.registry = config.IotHubRegistryDirect()
        runtime_config.test_module = config.EdgeHubModuleDirect(
            "TestModuleClient")
        runtime_config.leaf_device = config.EdgeHubLeafDeviceRest(
            "LeafDeviceClient")
    else:
        container_under_test = all_containers[conftest.language]
        runtime_config.service = config.IotHubServiceRest()
        runtime_config.registry = config.IotHubRegistryRest()
        runtime_config.test_module = config.EdgeHubModuleRest(
            "TestModuleClient")
        runtime_config.leaf_device = config.EdgeHubLeafDeviceRest(
            "LeafDeviceClient")

    hub = edgehub_factory.useExistingHubInstance(service_connection_string,
                                                 edge_device_id)

    runtime_config.service.connection_string = service_connection_string
    runtime_config.registry.connection_string = service_connection_string
    runtime_config.eventhub.connection_string = service_connection_string

    runtime_config.iotedge.device_id = edge_device_id

    runtime_config.test_module.device_id = edge_device_id
    runtime_config.test_module.module_id = container_under_test.module_id
    runtime_config.test_module.connection_string = (
        container_under_test.connection_string)
    if conftest.local:
        runtime_config.test_module.rest_uri = "http://localhost:" + str(
            container_under_test.local_port)
    else:
        runtime_config.test_module.rest_uri = (
            "http://" + host_for_rest_uri + ":" +
            str(container_under_test.host_port))
    runtime_config.test_module.transport = conftest.transport
    runtime_config.test_module.language = conftest.language

    runtime_config.friend_module.device_id = edge_device_id
    runtime_config.friend_module.module_id = all_containers["friend"].module_id
    runtime_config.friend_module.connection_string = all_containers[
        "friend"].connection_string
    runtime_config.friend_module.rest_uri = (
        "http://" + host_for_rest_uri + ":" +
        str(all_containers["friend"].host_port))

    runtime_config.leaf_device.device_id = hub.leaf_device_id
    runtime_config.leaf_device.connection_string = hub.leaf_device_connection_string
    if container_under_test.deviceImpl:
        runtime_config.leaf_device.rest_uri = runtime_config.test_module.rest_uri
    else:
        runtime_config.leaf_device.rest_uri = runtime_config.friend_module.rest_uri

    if not runtime_config.test_module.connection_string:
        raise Exception(
            "test module has not been deployed.  You need to deploy your langauge module (even if you're testing locally)"
        )
    if not runtime_config.friend_module.connection_string:
        raise Exception("friend module has not been deployed.")
    if not runtime_config.leaf_device.connection_string:
        raise Exception(
            "Leaf device does not appear to have an iothub identity.  You may need to re-run create-new-edgehub-device.sh"
        )

    if container_under_test.registryImpl:
        runtime_config.registry.rest_uri = runtime_config.test_module.rest_uri
    else:
        runtime_config.registry.rest_uri = runtime_config.friend_module.rest_uri

    if container_under_test.serviceImpl:
        runtime_config.service.rest_uri = runtime_config.test_module.rest_uri
    else:
        runtime_config.service.rest_uri = runtime_config.friend_module.rest_uri

    if not conftest.direct_to_iothub:
        # route all of our devices through edgeHub if necessary
        gatewayHostSuffix = ";GatewayHostName=" + gateway_host_name
        runtime_config.test_module.connection_string += gatewayHostSuffix
        runtime_config.friend_module.connection_string += gatewayHostSuffix
        runtime_config.leaf_device.connection_string += gatewayHostSuffix
    else:
        runtime_config.ca_certificate = {}  # must be an empty dictionary
        runtime_config.test_module.connection_type = config.CONNECTION_STRING
        runtime_config.friend_module.connection_type = config.CONNECTION_STRING

    for object_name in dir(runtime_config):
        test_obj = getattr(runtime_config, object_name)
        if getattr(test_obj, "test_object_type", None):
            adapter_type = getattr(test_obj, "adapter_type", None)
            if not adapter_type:
                pass
            elif adapter_type == config.REST_ADAPTER:
                adapters.add_rest_adapter(
                    name=test_obj.api_name,
                    api_surface=test_obj.api_surface,
                    uri=test_obj.rest_uri,
                )
            elif adapter_type == config.DIRECT_AZURE_ADAPTER:
                adapters.add_direct_azure_rest_adapter(
                    name=test_obj.api_name, api_surface=test_obj.api_surface)
            elif adapter_type == config.DIRECT_PYTHON_SDK_ADAPTER:
                adapters.add_direct_python_sdk_adapter(
                    name=test_obj.api_name, api_surface=test_obj.api_surface)

    pprint(obj_to_dict(runtime_config))