def connect(self, service_connection_string):
     self.config = connection_string_to_dictionary(service_connection_string)
     self.endpoint = _build_iothub_amqp_endpoint(self.config)
     operation = "/messages/devicebound"
     target = "amqps://" + self.endpoint + operation
     logger.info("Target: {}".format(target))
     self.send_client = uamqp.SendClient(target, debug=True)
예제 #2
0
    async def test_regression_send_message_fails_with_corrupt_connection_string(
        self, client, field_name, new_field_value
    ):
        limitations.only_run_test_for(client, ["node", "pythonv2"])

        if not limitations.uses_shared_key_auth(client):
            pytest.skip("client is not using shared key auth")

        payload = sample_content.make_message_payload()

        cs_fields = connection_string.connection_string_to_dictionary(
            client.settings.connection_string
        )
        cs_fields[field_name] = new_field_value

        await client.destroy()
        await client.create_from_connection_string(
            client.settings.transport,
            connection_string.dictionary_to_connection_string(cs_fields),
            connections.get_ca_cert(client.settings),
        )

        with pytest.raises(Exception) as e:
            await client.send_event(payload)
        assert is_api_failure_exception(e._excinfo[1])
예제 #3
0
def remove_edgehub_device():
    print("Removing edgehub device")
    if "IOTHUB_E2E_CONNECTION_STRING" not in os.environ:
        print(
            "ERROR: Iothub connection string not set in IOTHUB_E2E_CONNECTION_STRING environment variable."
        )
        sys.exit(1)
    service_connection_string = os.environ["IOTHUB_E2E_CONNECTION_STRING"]

    config_file = ConfigFile()
    device_connection_string = config_file.contents["provisioning"][
        "device_connection_string"]

    if device_connection_string:
        cn = connection_string_to_dictionary(device_connection_string)
        old_edgehub_device_id = cn["DeviceId"]
        old_edgehub_leaf_device = "{}_leaf_device".format(
            old_edgehub_device_id)
        helper = Helper(service_connection_string)
        if helper.try_delete_device(old_edgehub_device_id):
            print("deleted {}".format(old_edgehub_device_id))
        if helper.try_delete_device(old_edgehub_leaf_device):
            print("deleted {}".format(old_edgehub_leaf_device))

        print("updating config.yaml to remove strings")
        config_file.contents["provisioning"]["device_connection_string"] = ""

        config_file.save()
        print("config.yaml updated")

        print("edgehub test devices removed")
    else:
        print("no devices to remove")
예제 #4
0
def get_edge_device_id():
    config_file = ConfigFile()
    device_connection_string = config_file.contents["provisioning"][
        "device_connection_string"]

    if device_connection_string:
        return connection_string_to_dictionary(
            device_connection_string)["DeviceId"]
    async def connect(self, service_connection_string):
        self.config = connection_string_to_dictionary(service_connection_string)
        self.endpoint = _build_iothub_amqp_endpoint(self.config)

        send_operation = "/messages/devicebound"
        send_target = "amqps://" + self.endpoint + send_operation
        logger.info("send target: {}".format(send_target))
        self.send_client = uamqp.async_ops.client_async.SendClientAsync(
            send_target, debug=True
        )

        self.blob_status_receive_client = None
        self.blob_status_receive_iter = None

        adapter_config.logger("AMQP service client connected")
예제 #6
0
def ensure_edge_environment_variables():
    get_service_connection_string()

    if not ("IOTHUB_E2E_EDGEHUB_DEVICE_ID" in os.environ
            and "IOTHUB_E2E_EDGEHUB_DNS_NAME" in os.environ):
        os.environ["IOTHUB_E2E_EDGEHUB_DNS_NAME"] = get_computer_name()
        try:
            config_file = ConfigFile()
            device_connection_string = config_file.contents["provisioning"][
                "device_connection_string"]
            if "DeviceId=" in device_connection_string:
                os.environ[
                    "IOTHUB_E2E_EDGEHUB_DEVICE_ID"] = connection_string_to_dictionary(
                        device_connection_string)["DeviceId"]

        except FileNotFoundError:
            raise Exception(
                "config.yaml not found.  You need to set IOTHUB_E2E_EDGEHUB_DEVICE_ID and IOTHUB_E2E_EDGEHUB_DNS_NAME if you're not running on your edgeHub host"
            )
예제 #7
0
 def connect_sync(self, service_connection_string):
     self.service_connection_string = service_connection_string
     host = connection_string.connection_string_to_dictionary(
         service_connection_string)["HostName"]
     self.service = IotHubGatewayServiceAPIs("https://" + host).service