From 3b07ed601c289087f0956b103a28b18a1466d1c4 Mon Sep 17 00:00:00 2001 From: Paymaun Date: Thu, 28 Jan 2021 14:59:47 -0800 Subject: [PATCH] DT Help + test improvement. (#306) * DT Help + test improvement. * Update help example. --- azext_iot/digitaltwins/_help.py | 14 +++++++++++++- azext_iot/tests/digitaltwins/__init__.py | 4 ++-- .../test_dt_privatelinks_lifecycle_int.py | 11 +++++++++++ .../test_dt_resource_lifecycle_int.py | 16 ++++++++++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/azext_iot/digitaltwins/_help.py b/azext_iot/digitaltwins/_help.py index 10dd5c1ae..a581f8d0c 100644 --- a/azext_iot/digitaltwins/_help.py +++ b/azext_iot/digitaltwins/_help.py @@ -19,7 +19,7 @@ def load_digitaltwins_help(): helps["dt create"] = """ type: command - short-summary: Create a new Digital Twins instance. + short-summary: Create or update a Digital Twins instance. examples: - name: Create instance in target resource group using the resource group location. @@ -50,6 +50,18 @@ def load_digitaltwins_help(): "/subscriptions/a12345ea-bb21-994d-2263-c716348e32a1/resourceGroups/ProResourceGroup/providers/Microsoft.EventHub/namespaces/myEventHubNamespace/eventhubs/myEventHub" "/subscriptions/a12345ea-bb21-994d-2263-c716348e32a1/resourceGroups/ProResourceGroup/providers/Microsoft.ServiceBus/namespaces/myServiceBusNamespace/topics/myTopic" --role MyCustomRole + + - name: Update an instance in the target resource group to enable system managed identity. + text: > + az dt create -n {instance_name} -g {resouce_group} --assign-identity + + - name: Update an instance in the target resource group to disable system managed identity. + text: > + az dt create -n {instance_name} -g {resouce_group} --assign-identity false + + - name: Update an instance in the target resource group with new tag values and disable public network access. + text: > + az dt create -n {instance_name} -g {resouce_group} --tags env=prod --public-network-access Disabled """ helps["dt show"] = """ diff --git a/azext_iot/tests/digitaltwins/__init__.py b/azext_iot/tests/digitaltwins/__init__.py index 12f33c47a..6632777ff 100644 --- a/azext_iot/tests/digitaltwins/__init__.py +++ b/azext_iot/tests/digitaltwins/__init__.py @@ -160,7 +160,7 @@ def tearDown(self): # Needed because the DT service will indicate provisioning is finished before it actually is. def wait_for_hostname( - self, instance: dict, wait_in_sec: int = 5, interval: int = 3 + self, instance: dict, wait_in_sec: int = 5, interval: int = 4 ): from time import sleep @@ -176,7 +176,7 @@ def wait_for_hostname( ) ).as_json() - if refereshed_instance.get("hostName"): + if refereshed_instance.get("hostName") and refereshed_instance["provisioningState"] == "Succeeded": return refereshed_instance return instance diff --git a/azext_iot/tests/digitaltwins/test_dt_privatelinks_lifecycle_int.py b/azext_iot/tests/digitaltwins/test_dt_privatelinks_lifecycle_int.py index 714adfc40..706919f40 100644 --- a/azext_iot/tests/digitaltwins/test_dt_privatelinks_lifecycle_int.py +++ b/azext_iot/tests/digitaltwins/test_dt_privatelinks_lifecycle_int.py @@ -28,11 +28,22 @@ def test_dt_privatelinks(self): ) ).get_output_in_json() self.track_instance(create_output) + create_output = self.wait_for_hostname(create_output) # Fail test if hostName missing assert create_output.get( "hostName" ), "Service failed to provision DT instance: {}.".format(instance_name) + assert create_output["publicNetworkAccess"] == "Enabled" + + update_output = self.cmd( + "dt create -n {} -g {} -l {} --public-network-access Disabled".format( + instance_name, + self.rg, + self.region, + ) + ).get_output_in_json() + assert update_output["publicNetworkAccess"] == "Disabled" list_priv_links = self.cmd( "dt network private-link list -n {} -g {}".format( diff --git a/azext_iot/tests/digitaltwins/test_dt_resource_lifecycle_int.py b/azext_iot/tests/digitaltwins/test_dt_resource_lifecycle_int.py index 0734fce04..f282a5cdb 100644 --- a/azext_iot/tests/digitaltwins/test_dt_resource_lifecycle_int.py +++ b/azext_iot/tests/digitaltwins/test_dt_resource_lifecycle_int.py @@ -130,6 +130,22 @@ def test_dt_resource(self): assign_identity=True, ) + # Update tags and disable MSI + updated_tags = "env=test tier=premium" + updated_tags_dict = {"env": "test", "tier": "premium"} + remove_msi_output = self.cmd( + "dt create -n {} -g {} --assign-identity false --tags {}".format(instance_names[1], self.rg, updated_tags) + ).get_output_in_json() + + assert_common_resource_attributes( + self.wait_for_hostname(remove_msi_output), + instance_names[1], + self.rg, + self.rg_region, + tags=updated_tags_dict, + assign_identity=False, + ) + list_output = self.cmd("dt list").get_output_in_json() filtered_list = filter_dt_list(list_output, instance_names) assert len(filtered_list) == len(instance_names)