From 6f5dafc0a66a76ed97b84912d3a3dad766511c2d Mon Sep 17 00:00:00 2001 From: Yael Dekel Date: Mon, 24 Feb 2025 13:04:59 +0200 Subject: [PATCH 1/3] Add VI test --- .../custom.py | 1 + .../videoindexer_accounts_parameters.json | 12 +++ .../videoindexer_accounts_template.json | 31 ++++++ .../latest/test_private_endpoint_commands.py | 96 +++++++++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 src/azure-cli/azure/cli/command_modules/network/tests/latest/private_endpoint_arm_templates/videoindexer_accounts_parameters.json create mode 100644 src/azure-cli/azure/cli/command_modules/network/tests/latest/private_endpoint_arm_templates/videoindexer_accounts_template.json diff --git a/src/azure-cli/azure/cli/command_modules/network/private_link_resource_and_endpoint_connections/custom.py b/src/azure-cli/azure/cli/command_modules/network/private_link_resource_and_endpoint_connections/custom.py index 1bec83c6771..4d18282ed3a 100644 --- a/src/azure-cli/azure/cli/command_modules/network/private_link_resource_and_endpoint_connections/custom.py +++ b/src/azure-cli/azure/cli/command_modules/network/private_link_resource_and_endpoint_connections/custom.py @@ -83,6 +83,7 @@ def register_providers(): _register_one_provider("Microsoft.DocumentDB/mongoClusters", '2023-03-01-preview', True) _register_one_provider('Microsoft.DBforPostgreSQL/flexibleServers', '2023-06-01-preview', False) _register_one_provider('Microsoft.App/managedEnvironments', '2024-02-02-preview', True) + _register_one_provider('Microsoft.VideoIndexer/accounts', '2024-06-01-preview', True) def _register_one_provider(provider, api_version, support_list_or_not, resource_get_api_version=None, support_connection_operation=True): # pylint: disable=line-too-long diff --git a/src/azure-cli/azure/cli/command_modules/network/tests/latest/private_endpoint_arm_templates/videoindexer_accounts_parameters.json b/src/azure-cli/azure/cli/command_modules/network/tests/latest/private_endpoint_arm_templates/videoindexer_accounts_parameters.json new file mode 100644 index 00000000000..82ba6b79d83 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/network/tests/latest/private_endpoint_arm_templates/videoindexer_accounts_parameters.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "target_resource_name": { + "value": "clitestvideoindexer" + }, + "storage_account": { + "value": "clitestvideoindexersa" + } + } +} \ No newline at end of file diff --git a/src/azure-cli/azure/cli/command_modules/network/tests/latest/private_endpoint_arm_templates/videoindexer_accounts_template.json b/src/azure-cli/azure/cli/command_modules/network/tests/latest/private_endpoint_arm_templates/videoindexer_accounts_template.json new file mode 100644 index 00000000000..88f2207f778 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/network/tests/latest/private_endpoint_arm_templates/videoindexer_accounts_template.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "target_resource_name": { + "defaultValue": "videoindexer-privatelink", + "type": "String" + }, + "storage_account": { + "defaultValue": "/subscriptions/24237b72-8546-4da5-b204-8c3cb76dd930/resourceGroups/yaeld-rg/providers/Microsoft.Storage/storageAccounts/yaeldeastussa", + "type": "String" + } + }, + "variables": {}, + "resources": [ + { + "type": "Microsoft.VideoIndexer/accounts", + "apiVersion": "2024-06-01-preview", + "name": "[parameters('target_resource_name')]", + "location": "eastus", + "identity": { + "type": "SystemAssigned" + }, + "properties": { + "storageServices": { + "resourceId": "[parameters('storage_account')]" + } + } + } + ] +} \ No newline at end of file diff --git a/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_private_endpoint_commands.py b/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_private_endpoint_commands.py index e0efb9a6678..5246b16ad1c 100644 --- a/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_private_endpoint_commands.py +++ b/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_private_endpoint_commands.py @@ -2236,6 +2236,102 @@ def test_private_endpoint_connection_app_configuration(self, resource_group): self._test_private_endpoint_connection_scenario(resource_group, 'clitestappconfig', 'Microsoft.AppConfiguration/configurationStores') +class VideoIndexerNetworkARMTemplateBasedScenarioTest(ScenarioTest): + def _test_private_endpoint_connection_scenario(self, resource_group, storage_account, target_resource_name): + from azure.mgmt.core.tools import resource_id + resource_type = 'Microsoft.VideoIndexer/accounts' + self.kwargs.update({ + 'target_resource_name': target_resource_name, + 'storage_account': resource_id(subscription=self.get_subscription_id(), + resource_group=resource_group, + namespace='Microsoft.Storage', + type='storageAccounts', + name=storage_account), + 'target_resource_id': resource_id(subscription=self.get_subscription_id(), + resource_group=resource_group, + namespace=resource_type.split('/')[0], + type=resource_type.split('/')[1], + name=target_resource_name), + 'rg': resource_group, + 'resource_type': resource_type, + 'vnet': self.create_random_name('cli-vnet-', 24), + 'subnet': self.create_random_name('cli-subnet-', 24), + 'pe': self.create_random_name('cli-pe-', 24), + 'pe_connection': self.create_random_name('cli-pec-', 24) + }) + + param_file_name = "{}_{}_parameters.json".format(resource_type.split('/')[0].split('.')[1].lower(), resource_type.split('/')[1].lower()) + template_file_name = "{}_{}_template.json".format(resource_type.split('/')[0].split('.')[1].lower(), resource_type.split('/')[1].lower()) + self.kwargs.update({ + 'param_path': os.path.join(TEST_DIR, 'private_endpoint_arm_templates', param_file_name), + 'template_path': os.path.join(TEST_DIR, 'private_endpoint_arm_templates', template_file_name) + }) + self.cmd('az deployment group create -g {rg} -p "@{param_path}" target_resource_name={target_resource_name} storage_account={storage_account} -f "{template_path}"') + + self.cmd('az network vnet create -n {vnet} -g {rg} --subnet-name {subnet} -o json', + checks=self.check('length(newVNet.subnets)', 1)) + self.cmd('az network vnet subnet update -n {subnet} --vnet-name {vnet} -g {rg} ' + '--disable-private-endpoint-network-policies true -o json', + checks=self.check('privateEndpointNetworkPolicies', 'Disabled')) + + target_private_link_resource = self.cmd('az network private-link-resource list --name {target_resource_name} --resource-group {rg} --type {resource_type} -o json').get_output_in_json() + self.kwargs.update({ + 'group_id': target_private_link_resource[0]['properties']['groupId'] + }) + # Create a private endpoint connection + pe = self.cmd( + 'az network private-endpoint create -g {rg} -n {pe} --vnet-name {vnet} --subnet {subnet} ' + '--connection-name {pe_connection} --private-connection-resource-id {target_resource_id} ' + '--group-id {group_id} -o json').get_output_in_json() + self.kwargs['pe_id'] = pe['id'] + self.kwargs['pe_name'] = self.kwargs['pe_id'].split('/')[-1] + + # Show the connection at cosmos db side + list_private_endpoint_conn = self.cmd('az network private-endpoint-connection list --name {target_resource_name} --resource-group {rg} --type {resource_type} -o json').get_output_in_json() + self.kwargs.update({ + "pec_id": list_private_endpoint_conn[0]['id'] + }) + + self.kwargs.update({ + "pec_name": self.kwargs['pec_id'].split('/')[-1] + }) + self.cmd('az network private-endpoint-connection show --id {pec_id} -o json', + checks=self.check('id', '{pec_id}')) + self.cmd('az network private-endpoint-connection show --resource-name {target_resource_name} --name {pec_name} --resource-group {rg} --type {resource_type} -o json') + self.cmd('az network private-endpoint-connection show --resource-name {target_resource_name} -n {pec_name} -g {rg} --type {resource_type} -o json') + + # Test approval/rejection + self.kwargs.update({ + 'approval_desc': 'You are approved!', + 'rejection_desc': 'You are rejected!' + }) + self.cmd( + 'az network private-endpoint-connection approve --resource-name {target_resource_name} --resource-group {rg} --name {pec_name} --type {resource_type} ' + '--description "{approval_desc}" -o json', checks=[ + self.check('properties.privateLinkServiceConnectionState.status', 'Approved') + ]) + self.cmd('az network private-endpoint-connection reject --id {pec_id} ' + '--description "{rejection_desc}" -o json', + checks=[ + self.check('properties.privateLinkServiceConnectionState.status', 'Rejected') + ]) + self.cmd( + 'az network private-endpoint-connection list --name {target_resource_name} --resource-group {rg} --type {resource_type} -o json', + checks=[ + self.check('length(@)', 1) + ]) + + # Test delete + self.cmd('az network private-endpoint-connection delete --id {pec_id} -y -o json') + + @ResourceGroupPreparer(name_prefix="test_private_endpoint_connection_video_indexer", location="westus") + @StorageAccountPreparer(name_prefix="testpevi", allow_shared_key_access=False) + def test_private_endpoint_connection_video_indexer(self, resource_group, storage_account): + from azure.cli.testsdk.scenario_tests.utilities import create_random_name + vi_name = create_random_name(prefix='clitestvideoindexer') + self._test_private_endpoint_connection_scenario(resource_group, storage_account, vi_name) + + class NetworkPrivateLinkDigitalTwinsScenarioTest(ScenarioTest): @ResourceGroupPreparer( name_prefix="test_digital_twin_private_endpoint_", location="eastus" From 203d2a31a39b03e5f673b604953132bc6400e159 Mon Sep 17 00:00:00 2001 From: Yael Dekel Date: Mon, 26 May 2025 12:30:26 +0300 Subject: [PATCH 2/3] Code review comments --- .../custom.py | 2 +- .../tests/latest/test_private_endpoint_commands.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/network/private_link_resource_and_endpoint_connections/custom.py b/src/azure-cli/azure/cli/command_modules/network/private_link_resource_and_endpoint_connections/custom.py index acb3ed56bd3..3457037e4e9 100644 --- a/src/azure-cli/azure/cli/command_modules/network/private_link_resource_and_endpoint_connections/custom.py +++ b/src/azure-cli/azure/cli/command_modules/network/private_link_resource_and_endpoint_connections/custom.py @@ -85,7 +85,7 @@ def register_providers(): _register_one_provider('Microsoft.DBforPostgreSQL/flexibleServers', '2023-06-01-preview', False) _register_one_provider('Microsoft.App/managedEnvironments', '2024-02-02-preview', True) _register_one_provider('Microsoft.FluidRelay/fluidRelayServers', '2025-03-10-preview', True) - _register_one_provider('Microsoft.VideoIndexer/accounts', '2024-06-01-preview', True) + _register_one_provider('Microsoft.VideoIndexer/accounts', '2024-04-01', True) def _register_one_provider(provider, api_version, support_list_or_not, resource_get_api_version=None, support_connection_operation=True): # pylint: disable=line-too-long diff --git a/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_private_endpoint_commands.py b/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_private_endpoint_commands.py index 7397270a832..f796fb57f2d 100644 --- a/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_private_endpoint_commands.py +++ b/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_private_endpoint_commands.py @@ -2189,8 +2189,11 @@ def _test_private_endpoint_connection_scenario(self, resource_group, storage_acc 'pe_connection': self.create_random_name('cli-pec-', 24) }) - param_file_name = "{}_{}_parameters.json".format(resource_type.split('/')[0].split('.')[1].lower(), resource_type.split('/')[1].lower()) - template_file_name = "{}_{}_template.json".format(resource_type.split('/')[0].split('.')[1].lower(), resource_type.split('/')[1].lower()) + split_resource_type = resource_type.split('/') + resource_type_name = split_resource_type[0].split('.')[1].lower() + resource_type_kind = split_resource_type[1].lower() + param_file_name = "{}_{}_parameters.json".format(resource_type_name, resource_type_kind) + template_file_name = "{}_{}_template.json".format(resource_type_name, resource_type_kind) self.kwargs.update({ 'param_path': os.path.join(TEST_DIR, 'private_endpoint_arm_templates', param_file_name), 'template_path': os.path.join(TEST_DIR, 'private_endpoint_arm_templates', template_file_name) @@ -2253,11 +2256,11 @@ def _test_private_endpoint_connection_scenario(self, resource_group, storage_acc # Test delete self.cmd('az network private-endpoint-connection delete --id {pec_id} -y -o json') + @live_only() @ResourceGroupPreparer(name_prefix="test_private_endpoint_connection_video_indexer", location="westus") @StorageAccountPreparer(name_prefix="testpevi", allow_shared_key_access=False) def test_private_endpoint_connection_video_indexer(self, resource_group, storage_account): - from azure.cli.testsdk.scenario_tests.utilities import create_random_name - vi_name = create_random_name(prefix='clitestvideoindexer') + vi_name = self.create_random_name(prefix='clitestvideoindexer', length=24) self._test_private_endpoint_connection_scenario(resource_group, storage_account, vi_name) From 112a5ecb51a2c8e67c15164a5867628bffa71ed2 Mon Sep 17 00:00:00 2001 From: Yael Dekel Date: Mon, 26 May 2025 14:45:23 +0300 Subject: [PATCH 3/3] Fix api version --- .../private_link_resource_and_endpoint_connections/custom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/network/private_link_resource_and_endpoint_connections/custom.py b/src/azure-cli/azure/cli/command_modules/network/private_link_resource_and_endpoint_connections/custom.py index 3457037e4e9..a035c589247 100644 --- a/src/azure-cli/azure/cli/command_modules/network/private_link_resource_and_endpoint_connections/custom.py +++ b/src/azure-cli/azure/cli/command_modules/network/private_link_resource_and_endpoint_connections/custom.py @@ -85,7 +85,7 @@ def register_providers(): _register_one_provider('Microsoft.DBforPostgreSQL/flexibleServers', '2023-06-01-preview', False) _register_one_provider('Microsoft.App/managedEnvironments', '2024-02-02-preview', True) _register_one_provider('Microsoft.FluidRelay/fluidRelayServers', '2025-03-10-preview', True) - _register_one_provider('Microsoft.VideoIndexer/accounts', '2024-04-01', True) + _register_one_provider('Microsoft.VideoIndexer/accounts', '2025-04-01', True) def _register_one_provider(provider, api_version, support_list_or_not, resource_get_api_version=None, support_connection_operation=True): # pylint: disable=line-too-long