-
Notifications
You must be signed in to change notification settings - Fork 74
Add twin delete all and twin relationship delete all #331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
34a2114
Starting work on delete all
vilit1 80ecfe7
Update unit tests
vilit1 1b40310
Added unit tests for delete twins and relationship
vilit1 c4d6da5
starting int testing
vilit1 d821213
change to have seperate delete all command
vilit1 1cfeb5c
added int test for delete all
vilit1 43efefc
Starting work on delete all
vilit1 984d8c3
Update unit tests
vilit1 3d2ce0d
Added unit tests for delete twins and relationship
vilit1 cf13e44
starting int testing
vilit1 a484738
change to have seperate delete all command
vilit1 a31716e
added int test for delete all
vilit1 4c9e6d4
Starting work on delete all
vilit1 8b4d3b7
Update unit tests
vilit1 04d579e
Added unit tests for delete twins and relationship
vilit1 405b3db
starting int testing
vilit1 4d0bec4
change to have seperate delete all command
vilit1 143cbea
Merge branch 'dev' into twin_delete_all
vilit1 000b192
Merge branch 'twin_delete_all' of https://github.com/vilit1/azure-iot…
vilit1 f678b00
Merge pull request #6 from vilit1/twin_delete_all
vilit1 c7e679e
Add twin delete all and twin relationship delete all
vilit1 3e13b99
pr changes
vilit1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -540,6 +540,16 @@ def load_digitaltwins_help(): | |
| az dt twin delete -n {instance_or_hostname} --twin-id {twin_id} --etag {etag} | ||
| """ | ||
|
|
||
| helps["dt twin delete-all"] = """ | ||
| type: command | ||
| short-summary: Deletes all digital twins within the specified resource, including all relationships for those twins. | ||
|
|
||
| examples: | ||
| - name: Delete all digital twins. Any relationships referencing the twins will also be deleted. | ||
| text: > | ||
| az dt twin delete-all -n {instance_or_hostname} | ||
| """ | ||
|
|
||
| helps["dt twin relationship"] = """ | ||
| type: group | ||
| short-summary: Manage and configure the digital twin relationships of a Digital Twins instance. | ||
|
|
@@ -645,6 +655,16 @@ def load_digitaltwins_help(): | |
| az dt twin relationship delete -n {instance_or_hostname} --twin-id {twin_id} --relationship-id {relationship_id} --etag {etag} | ||
| """ | ||
|
|
||
| helps["dt twin relationship delete-all"] = """ | ||
| type: command | ||
| short-summary: Deletes all digital twin relationships on a Digital Twins instance, including incomming relationships. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small typo for |
||
|
|
||
| examples: | ||
| - name: Delete all digital twin relationships associated with the twin. | ||
| text: > | ||
| az dt twin relationship delete-all -n {instance_or_hostname} --twin-id {twin_id} | ||
|
vilit1 marked this conversation as resolved.
|
||
| """ | ||
|
|
||
| helps["dt twin telemetry"] = """ | ||
| type: group | ||
| short-summary: Test and validate the event routes and endpoints of a Digital Twins instance. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -284,6 +284,7 @@ def test_dt_twin(self): | |
| ).get_output_in_json() | ||
| assert len(twin_query_result["result"]) == 2 | ||
|
|
||
| # Relationship Tests | ||
| relationship_id = "myedge" | ||
| relationship = "contains" | ||
| self.kwargs["relationshipJson"] = json.dumps( | ||
|
|
@@ -500,16 +501,181 @@ def test_dt_twin(self): | |
| ) | ||
| ) | ||
|
|
||
| for twin_tuple in twins_id_list: | ||
| # No output from API for delete twin | ||
| self.cmd( | ||
| "dt twin delete -n {} --twin-id {} {}".format( | ||
| instance_name, | ||
| twin_tuple[0], | ||
| "-g {}".format(self.rg) if twins_id_list[-1] == twin_tuple else "", | ||
| ) | ||
| self.cmd( | ||
| "dt twin delete-all -n {} --yes".format( | ||
| instance_name, | ||
| ) | ||
| ) | ||
| sleep(10) # Wait for API to catch up | ||
|
|
||
| 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 | ||
| assert twin_query_result["cost"] | ||
|
|
||
| def test_dt_twin_delete(self): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit - I think we should label these tests as bulk delete |
||
| self.wait_for_capacity() | ||
| instance_name = generate_resource_id() | ||
| models_directory = "./models" | ||
| floor_dtmi = "dtmi:com:example:Floor;1" | ||
| floor_twin_id = "myfloor" | ||
| room_dtmi = "dtmi:com:example:Room;1" | ||
| room_twin_id = "myroom" | ||
| thermostat_component_id = "Thermostat" | ||
|
|
||
| create_output = self.cmd( | ||
| "dt create -n {} -g {} -l {}".format(instance_name, self.rg, self.region) | ||
| ).get_output_in_json() | ||
| self.track_instance(create_output) | ||
| self.wait_for_hostname(create_output) | ||
|
|
||
| self.cmd( | ||
| "dt role-assignment create -n {} -g {} --assignee {} --role '{}'".format( | ||
| instance_name, self.rg, self.current_user, self.role_map["owner"] | ||
| ) | ||
| ) | ||
| # Wait for RBAC to catch-up | ||
| sleep(60) | ||
|
|
||
| self.cmd( | ||
| "dt model create -n {} --from-directory '{}'".format( | ||
| instance_name, models_directory | ||
| ) | ||
| ) | ||
|
|
||
| self.kwargs["tempAndThermostatComponentJson"] = json.dumps( | ||
| { | ||
| "Temperature": 10.2, | ||
| "Thermostat": { | ||
| "$metadata": {}, | ||
| "setPointTemp": 23.12, | ||
| }, | ||
| } | ||
| ) | ||
|
|
||
| floor_twin = self.cmd( | ||
| "dt twin create -n {} --dtmi {} --twin-id {}".format( | ||
| instance_name, floor_dtmi, floor_twin_id | ||
| ) | ||
| ).get_output_in_json() | ||
|
|
||
| assert_twin_attributes( | ||
| twin=floor_twin, | ||
| expected_twin_id=floor_twin_id, | ||
| expected_dtmi=floor_dtmi, | ||
| ) | ||
|
|
||
| room_twin = self.cmd( | ||
| "dt twin create -n {} -g {} --dtmi {} --twin-id {} --properties '{}'".format( | ||
| instance_name, | ||
| self.rg, | ||
| room_dtmi, | ||
| room_twin_id, | ||
| "{tempAndThermostatComponentJson}", | ||
| ) | ||
| ).get_output_in_json() | ||
|
|
||
| assert_twin_attributes( | ||
| twin=room_twin, | ||
| expected_twin_id=room_twin_id, | ||
| expected_dtmi=room_dtmi, | ||
| properties=self.kwargs["tempAndThermostatComponentJson"], | ||
| component_name=thermostat_component_id, | ||
| ) | ||
|
|
||
| twin_query_result = self.cmd( | ||
| "dt twin query -n {} -g {} -q 'select * from digitaltwins'".format( | ||
| instance_name, self.rg | ||
| ) | ||
| ).get_output_in_json() | ||
| assert len(twin_query_result["result"]) == 2 | ||
|
|
||
| # Relationship Tests | ||
| relationship_id = "myedge" | ||
| relationship = "contains" | ||
| self.kwargs["relationshipJson"] = json.dumps( | ||
| {"ownershipUser": "me", "ownershipDepartment": "mydepartment"} | ||
| ) | ||
|
|
||
| twin_relationship_create_result = self.cmd( | ||
| "dt twin relationship create -n {} -g {} --relationship-id {} --relationship {} --twin-id {} " | ||
| "--target-twin-id {} --properties '{}'".format( | ||
| instance_name, | ||
| self.rg, | ||
| relationship_id, | ||
| relationship, | ||
| floor_twin_id, | ||
| room_twin_id, | ||
| "{relationshipJson}", | ||
| ) | ||
| ).get_output_in_json() | ||
|
|
||
| assert_twin_relationship_attributes( | ||
| twin_relationship_obj=twin_relationship_create_result, | ||
| expected_relationship=relationship, | ||
| relationship_id=relationship_id, | ||
| source_id=floor_twin_id, | ||
| target_id=room_twin_id, | ||
| properties=self.kwargs["relationshipJson"], | ||
| ) | ||
|
|
||
| twin_relationship_list_result = self.cmd( | ||
| "dt twin relationship list -n {} --twin-id {}".format( | ||
| instance_name, | ||
| floor_twin_id, | ||
| ) | ||
| ).get_output_in_json() | ||
| assert len(twin_relationship_list_result) == 1 | ||
|
|
||
| # Delete all relationships | ||
| self.cmd( | ||
| "dt twin relationship delete-all -n {} --twin-id {} --yes".format( | ||
| instance_name, | ||
| floor_twin_id, | ||
| ) | ||
| ) | ||
|
|
||
| twin_relationship_list_result = self.cmd( | ||
| "dt twin relationship list -n {} --twin-id {}".format( | ||
| instance_name, | ||
| floor_twin_id, | ||
| ) | ||
| ).get_output_in_json() | ||
| assert len(twin_relationship_list_result) == 0 | ||
|
|
||
| # Recreate relationship for delete all twins | ||
| twin_relationship_create_result = self.cmd( | ||
| "dt twin relationship create -n {} -g {} --relationship-id {} --relationship {} --twin-id {} " | ||
| "--target-twin-id {} --properties '{}'".format( | ||
| instance_name, | ||
| self.rg, | ||
| relationship_id, | ||
| relationship, | ||
| floor_twin_id, | ||
| room_twin_id, | ||
| "{relationshipJson}", | ||
| ) | ||
| ).get_output_in_json() | ||
|
|
||
| assert_twin_relationship_attributes( | ||
| twin_relationship_obj=twin_relationship_create_result, | ||
| expected_relationship=relationship, | ||
| relationship_id=relationship_id, | ||
| source_id=floor_twin_id, | ||
| target_id=room_twin_id, | ||
| properties=self.kwargs["relationshipJson"], | ||
| ) | ||
|
|
||
| self.cmd( | ||
| "dt twin delete-all -n {} --yes".format( | ||
| instance_name, | ||
| ) | ||
| ) | ||
| sleep(10) # Wait for API to catch up | ||
|
|
||
| twin_query_result = self.cmd( | ||
| "dt twin query -n {} -g {} -q 'select * from digitaltwins' --cost".format( | ||
| instance_name, self.rg | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.