def populate_credentials(): iothub_service_helper = IoTHubServiceHelper( settings.iothub.connection_string) if settings.iotedge.device_id: settings.iotedge.ca_cert_base64 = get_edge_ca_cert_base64() for device in (settings.leaf_device, settings.test_device): if device.device_id: if device.connection_type.startswith("connection_string"): device.connection_string = iothub_service_helper.get_device_connection_string( device.device_id) if device.connection_type.endswith("_with_edge_gateway"): device.connection_string += ";GatewayHostName={}".format( settings.iotedge.hostname) print("Added connection string for {} device {}".format( device.name, device.device_id)) for module in (settings.test_module, settings.friend_module): if module.device_id and module.module_id: if (module.connection_type.startswith("connection_string") or module.connection_type == "environment"): module.connection_string = iothub_service_helper.get_module_connection_string( module.device_id, module.module_id) if (module.connection_type.endswith("_with_edge_gateway") or module.connection_type == "environment"): module.connection_string += ";GatewayHostName={}".format( settings.iotedge.hostname) print("Added connection string for {} module {},{}".format( module.name, module.device_id, module.module_id)) settings.save()
def set_config_yaml(): iothub_service_helper = IoTHubServiceHelper( settings.iothub.connection_string) settings.iotedge.connection_string = iothub_service_helper.get_device_connection_string( settings.iotedge.device_id) print("updating config.yaml to insert connection string") config_file = ConfigFile() config_file.contents["provisioning"][ "device_connection_string"] = settings.iotedge.connection_string if ("IOTEDGE_DEBUG_LOG" in os.environ and os.environ["IOTEDGE_DEBUG_LOG"].lower() == "true"): print( "IOTEDGE_DEBUG_LOG is set. setting edgeAgent RuntimeLogLevel to debug" ) config_file.contents["agent"]["env"]["RuntimeLogLevel"] = "debug" else: print( "IOTEDGE_DEBUG_LOG is not set. clearing edgeAgent RuntimeLogLevel") if "RuntimeLogLevel" in config_file.contents["agent"]["env"]: del config_file.contents["agent"]["env"]["RuntimeLogLevel"] config_file.save() settings.save() print("config.yaml updated")
def remove_instance(settings_object): iothub_service_helper = IoTHubServiceHelper( settings.iothub.connection_string) if hasattr(settings_object, "device_id") and settings_object.device_id: iothub_service_helper.try_delete_device(settings_object.device_id) print("Removed {} device with id {}".format(settings_object.name, settings_object.device_id)) settings.clear_object(settings_object) settings.save()
def set_edge_configuration(): edge_config = EdgeConfiguration() iothub_service_helper = IoTHubServiceHelper( settings.iothub.connection_string) for obj in (settings.test_module, settings.friend_module): edge_config.add_module_container(obj.module_id, obj.image, obj.container_port, obj.host_port) edge_config.add_routes_for_module("testMod") # apply the configuraiton iothub_service_helper.apply_configuration(settings.iotedge.device_id, edge_config.get_module_config()) settings.save()
def deploy_for_iotedge(testMod_image): remove_old_instances() settings.iotedge.hostname = get_computer_name() host = connection_string_to_sas_token( settings.iothub.connection_string)["host"] print("Creating new device on hub {}".format(host)) iothub_service_helper = IoTHubServiceHelper( settings.iothub.connection_string) settings.iotedge.device_id = device_id_base + "_iotedge" iothub_service_helper.create_device(settings.iotedge.device_id, True) set_edge_configuration(testMod_image) settings.leaf_device.device_id = device_id_base + "_leaf_device" iothub_service_helper.create_device(settings.leaf_device.device_id, False) # default leaf device to use test_module connection. Fix this in conftest.py if we need to use friend_module settings.leaf_device.connection_type = "connection_string_with_edge_gateway" settings.leaf_device.adapter_address = settings.test_module.adapter_address settings.leaf_device.language = settings.test_module.language settings.leaf_device.host_port = settings.test_module.host_port settings.leaf_device.container_port = settings.test_module.container_port set_config_yaml() restart_iotedge() print("New IotEdge device created with device_id={}".format( settings.iotedge.device_id))
def deploy_for_iothub(testMod_image): utilities.pull_docker_image(testMod_image) utilities.remove_old_instances() settings.horton.image = testMod_image settings.horton.language = utilities.get_language_from_image_name( testMod_image) settings.horton.is_windows = utilities.is_windows() device_id_base = utilities.get_random_device_name() host = connection_string_to_sas_token( settings.iothub.connection_string)["host"] print("Creating new device on hub {}".format(host)) iothub_service_helper = IoTHubServiceHelper( settings.iothub.connection_string) settings.test_device.device_id = device_id_base + "_test_device" settings.test_device.connection_type = "connection_string" settings.test_device.host_port = testMod_host_port settings.test_device.container_name = "testMod" settings.test_device.object_type = "iothub_device" utilities.set_args_from_image(settings.test_device, testMod_image) iothub_service_helper.create_device(settings.test_device.device_id) settings.test_module.device_id = settings.test_device.device_id settings.test_module.module_id = "testMod" settings.test_module.connection_type = "connection_string" settings.test_module.host_port = testMod_host_port settings.test_module.container_name = "testMod" settings.test_module.object_type = "iothub_module" utilities.set_args_from_image(settings.test_module, testMod_image) iothub_service_helper.create_device_module(settings.test_module.device_id, settings.test_module.module_id) if settings.horton.is_windows: settings.net_control.adapter_address = None else: settings.net_control.test_destination = host if settings.horton.image == utilities.PYTHON_INPROC: settings.net_control.adapter_address = "http://localhost:{}".format( settings.net_control.container_port) else: settings.net_control.adapter_address = "http://localhost:{}".format( settings.net_control.host_port) if testMod_image != utilities.PYTHON_INPROC: utilities.create_docker_container(settings.test_module) settings.save()
def deploy_for_iotedge(testMod_image): utilities.pull_docker_image(testMod_image) utilities.remove_old_instances() settings.horton.image = testMod_image settings.horton.language = utilities.get_language_from_image_name( testMod_image) settings.horton.is_windows = utilities.is_windows() settings.iotedge.hostname = utilities.get_computer_name() device_id_base = utilities.get_random_device_name() host = connection_string_to_sas_token( settings.iothub.connection_string)["host"] print("Creating new device on hub {}".format(host)) iothub_service_helper = IoTHubServiceHelper( settings.iothub.connection_string) settings.iotedge.device_id = device_id_base + "_iotedge" iothub_service_helper.create_device(settings.iotedge.device_id, True) edge_deployment.add_edge_modules(testMod_image) edge_deployment.set_edge_configuration() # default leaf device to use test_module connection. Fix this in conftest.py if we need to use friend_module settings.leaf_device.device_id = device_id_base + "_leaf_device" iothub_service_helper.create_device(settings.leaf_device.device_id, False) settings.leaf_device.connection_type = "connection_string_with_edge_gateway" settings.leaf_device.adapter_address = settings.test_module.adapter_address settings.leaf_device.language = settings.test_module.language settings.leaf_device.host_port = settings.test_module.host_port settings.leaf_device.container_port = settings.test_module.container_port settings.leaf_device.container_name = settings.test_module.container_name settings.leaf_device.object_type = "leaf_device" if settings.horton.is_windows: settings.net_control.adapter_address = None else: settings.net_control.test_destination = host settings.net_control.adapter_address = "http://localhost:{}".format( settings.net_control.host_port) edge_deployment.set_config_yaml() edge_deployment.restart_iotedge() print("New IotEdge device created with device_id={}".format( settings.iotedge.device_id))
def deploy_for_iotedge(test_image): _deploy_common(test_image) settings.iotedge.iotedge_host_name = utilities.get_computer_name() iothub_host_name = connection_string_to_sas_token( settings.iothub.connection_string)["host"] settings.iothub.iothub_host_name = iothub_host_name print("Creating new device on hub {}".format(iothub_host_name)) iothub_service_helper = IoTHubServiceHelper( settings.iothub.connection_string) settings.iotedge.device_id = settings.horton.id_base + "_iotedge" iothub_service_helper.create_device(settings.iotedge.device_id, True) edge_deployment.add_edge_modules(test_image) edge_deployment.set_edge_configuration() # default leaf device to use test_module connection. Fix this in conftest.py if we need to use friend_module settings.leaf_device.device_id = settings.horton.id_base + "_leaf_device" iothub_service_helper.create_device(settings.leaf_device.device_id, False) settings.leaf_device.connection_type = "connection_string_with_edge_gateway" settings.leaf_device.adapter_address = settings.test_module.adapter_address settings.leaf_device.language = settings.test_module.language settings.leaf_device.host_port = settings.test_module.host_port settings.leaf_device.container_port = settings.test_module.container_port settings.leaf_device.container_name = settings.test_module.container_name settings.leaf_device.iothub_host_name = iothub_host_name settings.leaf_device.object_type = "leaf_device" _deploy_system_control(settings.iotedge.iotedge_host_name) edge_deployment.set_config_yaml() edge_deployment.restart_iotedge() print("New IotEdge device created with device_id={}".format( settings.iotedge.device_id)) add_longhaul_settings() settings.save()
def deploy_for_iothub(test_image): _deploy_common(test_image) iothub_host_name = connection_string_to_sas_token( settings.iothub.connection_string)["host"] print("Creating new device on hub {}".format(iothub_host_name)) settings.iothub.iothub_host_name = iothub_host_name iothub_service_helper = IoTHubServiceHelper( settings.iothub.connection_string) settings.test_device.device_id = settings.horton.id_base + "_test_device" settings.test_device.connection_type = "connection_string" settings.test_device.host_port = testMod_host_port settings.test_device.container_name = "testMod" settings.test_device.object_type = "iothub_device" settings.test_device.iothub_host_name = iothub_host_name utilities.set_args_from_image(settings.test_device, test_image) iothub_service_helper.create_device(settings.test_device.device_id) settings.test_module.device_id = settings.test_device.device_id settings.test_module.module_id = "testMod" settings.test_module.connection_type = "connection_string" settings.test_module.host_port = testMod_host_port settings.test_module.container_name = "testMod" settings.test_module.object_type = "iothub_module" settings.test_module.iothub_host_name = iothub_host_name utilities.set_args_from_image(settings.test_module, test_image) iothub_service_helper.create_device_module(settings.test_module.device_id, settings.test_module.module_id) _deploy_system_control(iothub_host_name) if test_image != utilities.PYTHON_INPROC_IMAGE: utilities.create_docker_container(settings.test_module) add_longhaul_settings() settings.save()
def deploy_for_iothub(testMod_image): utilities.remove_old_instances() settings.horton.image = testMod_image settings.horton.language = utilities.get_language_from_image_name( testMod_image) device_id_base = utilities.get_random_device_name() host = connection_string_to_sas_token( settings.iothub.connection_string)["host"] print("Creating new device on hub {}".format(host)) iothub_service_helper = IoTHubServiceHelper( settings.iothub.connection_string) settings.test_device.device_id = device_id_base + "_test_device" settings.test_device.connection_type = "connection_string" settings.test_device.host_port = testMod_host_port settings.test_device.container_name = "testMod" utilities.set_args_from_image(settings.test_device, testMod_image) iothub_service_helper.create_device(settings.test_device.device_id) settings.test_module.device_id = settings.test_device.device_id settings.test_module.module_id = "testMod" settings.test_module.connection_type = "connection_string" settings.test_module.host_port = testMod_host_port settings.test_module.container_name = "testMod" utilities.set_args_from_image(settings.test_module, testMod_image) iothub_service_helper.create_device_module(settings.test_module.device_id, settings.test_module.module_id) settings.net_control.test_destination = host utilities.create_docker_container(settings.test_module) settings.save()
# Copyright (c) Microsoft. All rights reserved. # Licensed under the MIT license. See LICENSE file in the project root for # full license information. from iothub_service_helper import IoTHubServiceHelper from horton_settings import settings import base64 import glob import utilities iothub_service_helper = IoTHubServiceHelper(settings.iothub.connection_string) def get_edge_ca_cert_base64(): filename = glob.glob("/var/lib/iotedge/hsm/certs/edge_owner_ca*.pem")[0] cert = utilities.run_shell_command("sudo -n cat {}".format(filename)) return base64.b64encode("\n".join(cert).encode("ascii")).decode("ascii") def populate_credentials(): if settings.iotedge.device_id: settings.iotedge.ca_cert_base64 = get_edge_ca_cert_base64() for device in (settings.leaf_device, settings.test_device): if device.device_id: if device.connection_type.startswith("connection_string"): device.connection_string = iothub_service_helper.get_device_connection_string( device.device_id) if device.connection_type.endswith("_with_edge_gateway"): device.connection_string += ";GatewayHostName={}".format(