Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a2f6b6c
Initial updates to use track 2 Hub GA SDK
c-ryan-k Mar 3, 2021
45cadfb
WIP initial user-assigned identity functionality
c-ryan-k Mar 16, 2021
2acf8e6
Added routing endpoint identity and added some preliminary test code
c-ryan-k Mar 17, 2021
b613397
Updated identity code with enums and minor logic updates
c-ryan-k Mar 18, 2021
b3208a4
More identity updates, role and scope assignment
c-ryan-k Mar 18, 2021
ee48812
Minor fixes to identity functions and return values
c-ryan-k Mar 19, 2021
ee807a0
Linting fixes
c-ryan-k Mar 19, 2021
ea84c66
WIP testing updates
c-ryan-k Mar 19, 2021
44117af
Merge branch 'azure-dev' into hub_track2
c-ryan-k Mar 26, 2021
fa2dbb8
Help/Param updates and minor tweaks/fixes
c-ryan-k Mar 30, 2021
691950d
Test updates, help updates, polling updates
c-ryan-k Mar 30, 2021
8fc4f2e
Test recording updates
c-ryan-k Mar 31, 2021
1282c05
test updates
c-ryan-k Apr 6, 2021
0a76443
minor fix in consumer_group_create, test updates
c-ryan-k Apr 6, 2021
5060def
Initial updates to use track 2 Hub GA SDK
c-ryan-k Mar 3, 2021
14fa27d
WIP initial user-assigned identity functionality
c-ryan-k Mar 16, 2021
bc5e641
Added routing endpoint identity and added some preliminary test code
c-ryan-k Mar 17, 2021
8779d9a
Updated identity code with enums and minor logic updates
c-ryan-k Mar 18, 2021
889f42c
More identity updates, role and scope assignment
c-ryan-k Mar 18, 2021
90342f9
Minor fixes to identity functions and return values
c-ryan-k Mar 19, 2021
9b25700
Linting fixes
c-ryan-k Mar 19, 2021
850ab5e
WIP testing updates
c-ryan-k Mar 19, 2021
a65084e
Help/Param updates and minor tweaks/fixes
c-ryan-k Mar 30, 2021
c92c45f
Test updates, help updates, polling updates
c-ryan-k Mar 30, 2021
5f5e1e2
Test recording updates
c-ryan-k Mar 31, 2021
df59fbf
test updates
c-ryan-k Apr 6, 2021
e6308da
minor fix in consumer_group_create, test updates
c-ryan-k Apr 6, 2021
47e700a
Merge branch 'hub_track2' of https://github.com/c-ryan-k/azure-cli in…
c-ryan-k Apr 12, 2021
0214f61
Test updates and new recordings
c-ryan-k Apr 12, 2021
3ea6fc4
Merge branch 'azure-dev' into hub_track2
c-ryan-k Apr 20, 2021
a29fe37
Fix for ARM issue - user identity object must be empty upon removal o…
c-ryan-k Apr 27, 2021
1a0ceeb
Updates to use stable multiapi SDK (2021-03-03) with backfill for dev…
c-ryan-k Apr 28, 2021
d1b5f0d
Merge branch 'dev' into hub_track2
c-ryan-k Apr 28, 2021
ef103b3
Help/Param string updates
c-ryan-k Apr 28, 2021
fb759e6
Version fix for new SDK (2021-03-31)
c-ryan-k Apr 29, 2021
bdc3f5a
Parameter updates
c-ryan-k May 11, 2021
a599f8b
Test and recording updates
c-ryan-k May 11, 2021
cd59e5a
Certificate create/update fixes and test updates
c-ryan-k May 11, 2021
4e8d6a3
Add DeviceConnectionStateEvents as a routing source type
c-ryan-k May 13, 2021
0ab2ae5
RoutingSource test updates
c-ryan-k May 14, 2021
20992a8
SDK version update to 2.0.0
c-ryan-k May 14, 2021
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
Prev Previous commit
Next Next commit
WIP testing updates
  • Loading branch information
c-ryan-k committed Apr 9, 2021
commit 850ab5e1776354937fd0206a0a9f8f0ea111b8af
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from azure.cli.testsdk import ResourceGroupPreparer, ScenarioTest, StorageAccountPreparer
from azure_devtools.scenario_tests import AllowLargeResponse
from azure.cli.command_modules.iot.shared import IdentityType
from .recording_processors import KeyReplacer


Expand Down Expand Up @@ -429,29 +430,27 @@ def test_identity_hub(self, resource_group, resource_group_location, storage_acc
]

# create user-assigned identity
user_identity_1, user_identity_2, user_identity_3 =
self.cmd('identity create -n {0} -g {1}'.format(user_identity_names[0]., rg)).get_output_in_json(),
self.cmd('identity create -n {0} -g {1}'.format(user_identity_names[1], rg)).get_output_in_json(),
self.cmd('identity create -n {0} -g {1}'.format(user_identity_names[2], rg)).get_output_in_json()

# identity hub creation
import os
templateFile = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.path.pardir, 'templates', 'identity.json')
self.cmd('deployment group create --name {0} -g {1} --template-file "{2}" --parameters name={3} --parameters location={4}'
.format("identity-hub-deployment", resource_group, templateFile, identity_hub, location))
with mock.patch('azure.cli.command_modules.role.custom._gen_guid', side_effect=self.create_guid):
user_identity_1 = self.cmd('identity create -n {0} -g {1}'.format(user_identity_names[0], rg)).get_output_in_json()
user_identity_2 = self.cmd('identity create -n {0} -g {1}'.format(user_identity_names[1], rg)).get_output_in_json()
user_identity_3 = self.cmd('identity create -n {0} -g {1}'.format(user_identity_names[2], rg)).get_output_in_json()
# identity hub creation, assign role to storage container
self.cmd('iot hub create -n {0} -g {1} --sku s1 --location {2} --assign-identity {3} --role {4} --scopes {5}'
.format(identity_hub, rg, location, system_identity, identity_storage_role, storage_account_id))

hub_props = self.cmd('iot hub show --name {0}'.format(identity_hub), checks=[
self.check('properties.minTlsVersion', '1.2'),
self.check('identity.type', 'SystemAssigned')]).get_output_in_json()

hub_object_id = hub_props['identity']['principalId']
assert hub_object_id

# Add RBAC role for hub to storage container
with mock.patch('azure.cli.command_modules.role.custom._gen_guid', side_effect=self.create_guid):
role_assignment = self.cmd('az role assignment create --role "{0}" --assignee "{1}" --scope "{2}"'
.format(identity_storage_role, hub_object_id, storage_account_id)).get_output_in_json()
# # Add RBAC role for hub to storage container
# with mock.patch('azure.cli.command_modules.role.custom._gen_guid', side_effect=self.create_guid):
# role_assignment = self.cmd('az role assignment create --role "{0}" --assignee "{1}" --scope "{2}"'
# .format(identity_storage_role, hub_object_id, storage_account_id)).get_output_in_json()

assert role_assignment['principalId'] == hub_object_id
# assert role_assignment['principalId'] == hub_object_id

# Allow time for RBAC
from time import sleep
Expand Down Expand Up @@ -573,27 +572,46 @@ def test_identity_hub(self, resource_group, resource_group_location, storage_acc

# testing new identity namespace

# add multiple user-assigned identities (2, 3)
self.cmd('iot hub identity assign -n {0} -g {1} --identities {2} {3}'.format(identity_hub, rg, user_identity_2.id, user_identity_3.id))

# show identity
self.cmd('iot hub identity show -n {0} -g {0}'.format(identity_hub, rg))
self.cmd('iot hub identity show -n {0} -g {1}'.format(identity_hub, rg),
checks=[
self.check('length(userAssignedIdentities)', 1),
self.check('type', IdentityType.system_assigned_user_assigned.value),
self.exists('userAssignedIdentities[{0}]'.format(user_identity_1.id))])

# remove single identity (system)
self.cmd('iot hub identity remove -n {0} -g {1} --identities {2}'.format(identity_hub, rg, system_identity))
# add multiple user-assigned identities (2, 3)
self.cmd('iot hub identity assign -n {0} -g {1} --identities {2} {3}'
.format(identity_hub, rg, user_identity_2.id, user_identity_3.id),
checks=[
self.check('length(userAssignedIdentities)', 3),
self.check('type', IdentityType.system_assigned_user_assigned.value),
self.exists('userAssignedIdentities[{0}]'.format(user_identity_1.id)),
self.exists('userAssignedIdentities[{0}]'.format(user_identity_2.id)),
self.exists('userAssignedIdentities[{0}]'.format(user_identity_3.id))])

# remove all remaining identities (2, 3)
self.cmd('iot hub identity remove -n {0} -g {1} --identities {2} {3} {4}'.format(identity_hub, rg, user_identity_2.id, user_identity_3.id))
# remove single identity (system)
self.cmd('iot hub identity remove -n {0} -g {1} --identities {2}'.format(identity_hub, rg, system_identity),
checks=[
self.check('length(userAssignedIdentities)', 3),
self.check('type', IdentityType.user_assigned.value),
self.exists('userAssignedIdentities[{0}]'.format(user_identity_1.id)),
self.exists('userAssignedIdentities[{0}]'.format(user_identity_2.id)),
self.exists('userAssignedIdentities[{0}]'.format(user_identity_3.id))])

# remove all remaining user identities (1, 2, 3)
self.cmd('iot hub identity remove -n {0} -g {1} --identities {2} {3} {4}'
.format(identity_hub, rg, user_identity_1.id, user_identity_2.id, user_identity_3.id),
checks=[
self.check('length(userAssignedIdentities)', 0),
self.check('type', IdentityType.none.value)])

# re-add system identity
self.cmd('iot hub identity assign -n {0} -g {1} --identities {3}'.format(identity_hub, rg, system_identity))


hub = self.cmd('iot hub identity remove --identities {0} -n {1} -g {2}'.format(system_identity, identity_hub, rg)).get_output_in_json()
assert hub.identity.type == None

self.cmd('iot hub identity assign -n {0} -g {1} --identities {2}'.format(identity_hub, rg, system_identity),
checks=[
self.check('length(userAssignedIdentities)', 0),
self.check('type', IdentityType.system_assigned.value)])


assert hub.identity.type is None

def _get_eventhub_connectionstring(self, rg):
ehNamespace = self.create_random_name(prefix='ehNamespaceiothubfortest1', length=32)
Expand Down