Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions azext_iot/digitaltwins/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ def load_digitaltwins_help():
az dt delete -n {instance_name} -y --no-wait
"""

helps["dt reset"] = """
type: command
short-summary: Reset an existing Digital Twins instance by deleting associated
assets. Currently only supports deleting models and twins.

examples:
- name: Reset all assets for a Digital Twins instance.
text: >
az dt reset -n {instance_name}
"""

helps["dt endpoint"] = """
type: group
short-summary: Manage and configure Digital Twins instance endpoints.
Expand Down
1 change: 1 addition & 0 deletions azext_iot/digitaltwins/command_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def load_digitaltwins_commands(self, _):
cmd_group.show_command("show", "show_instance")
cmd_group.command("list", "list_instances")
cmd_group.command("delete", "delete_instance", confirmation=True, supports_no_wait=True)
cmd_group.command("reset", "reset_instance", confirmation=True, is_preview=True)

with self.command_group(
"dt endpoint", command_type=digitaltwins_resource_ops
Expand Down
7 changes: 7 additions & 0 deletions azext_iot/digitaltwins/commands_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azext_iot.digitaltwins.commands_twins import delete_all_twin
from azext_iot.digitaltwins.commands_models import delete_all_models
from azext_iot.digitaltwins.providers.resource import ResourceProvider
from azext_iot.digitaltwins.common import (
ADTEndpointType,
Expand Down Expand Up @@ -57,6 +59,11 @@ def delete_instance(cmd, name, resource_group_name=None):
return rp.delete(name=name, resource_group_name=resource_group_name)


def reset_instance(cmd, name, resource_group_name=None):
delete_all_models(cmd, name, resource_group_name)
delete_all_twin(cmd, name, resource_group_name)


def list_endpoints(cmd, name, resource_group_name=None):
rp = ResourceProvider(cmd)
return rp.list_endpoints(name=name, resource_group_name=resource_group_name)
Expand Down
40 changes: 40 additions & 0 deletions azext_iot/tests/digitaltwins/test_dt_twin_lifecycle_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,17 @@ def test_dt_twin(self):
assert len(twin_query_result["result"]) == 0
assert twin_query_result["cost"]

self.cmd(
"dt reset -n {} --yes".format(
instance_name,
)
)

model_query_result = self.cmd(
"dt model list -n {} -g {}".format(instance_name, self.rg)
).get_output_in_json()
assert len(model_query_result) == 0

def test_dt_twin_bulk_delete(self):
self.wait_for_capacity()
instance_name = generate_resource_id()
Expand Down Expand Up @@ -685,6 +696,35 @@ def test_dt_twin_bulk_delete(self):
assert len(twin_query_result["result"]) == 0
assert twin_query_result["cost"]

model_query_result = self.cmd(
"dt model list -n {} -g {}".format(instance_name, self.rg)
).get_output_in_json()
assert len(model_query_result) > 0

self.cmd(
"dt twin create -n {} --dtmi {} --twin-id {}".format(
instance_name, floor_dtmi, floor_twin_id
)
)

self.cmd(
"dt reset -n {} --yes".format(
instance_name,
)
)

model_query_result = self.cmd(
"dt model list -n {} -g {}".format(instance_name, self.rg)
).get_output_in_json()
assert len(model_query_result) == 0

twin_query_result = self.cmd(
"dt twin query -n {} -g {} -q 'select * from digitaltwins' --cost".format(
instance_name, self.rg
)
).get_output_in_json()
assert len(twin_query_result["result"]) == 0


# TODO: Refactor - limited interface
def assert_twin_attributes(
Expand Down