Skip to content

Commit e7bc650

Browse files
revert unintended changes
1 parent 7720cbd commit e7bc650

File tree

1 file changed

+92
-7
lines changed

1 file changed

+92
-7
lines changed

src/azure-cli/azure/cli/command_modules/network/tests/latest/test_private_endpoint_commands.py

Lines changed: 92 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -660,12 +660,6 @@ def test_mysql_private_link_scenario(self, resource_group, server, database_engi
660660
self._test_private_link_resource(resource_group, server, 'Microsoft.DBforMySQL/servers', 'mysqlServer')
661661
self._test_private_endpoint_connection(resource_group, server, database_engine, 'Microsoft.DBforMySQL/servers')
662662

663-
@ResourceGroupPreparer()
664-
@ServerPreparer(engine_type='postgres')
665-
def test_postgres_private_link_scenario(self, resource_group, server, database_engine):
666-
self._test_private_link_resource(resource_group, server, 'Microsoft.DBforPostgreSQL/servers', 'postgresqlServer')
667-
self._test_private_endpoint_connection(resource_group, server, database_engine, 'Microsoft.DBforPostgreSQL/servers')
668-
669663
def _test_private_link_resource(self, resource_group, server, database_engine, group_id):
670664
result = self.cmd('network private-link-resource list -g {} --name {} --type {}'
671665
.format(resource_group, server, database_engine)).get_output_in_json()
@@ -2491,6 +2485,97 @@ def test_private_endpoint_connection_video_indexer(self, resource_group, storage
24912485
vi_name = self.create_random_name(prefix='clitestvideoindexer', length=24)
24922486
self._test_private_endpoint_connection_scenario(resource_group, storage_account, vi_name)
24932487

2488+
class SecurityPrivateLinkNetworkARMTemplateBasedScenarioTest(ScenarioTest):
2489+
def _test_private_endpoint_connection_scenario(self, resource_group, target_resource_name):
2490+
from azure.mgmt.core.tools import resource_id
2491+
resource_type = 'Microsoft.Security/privateLinks'
2492+
self.kwargs.update({
2493+
'target_resource_name': target_resource_name,
2494+
'target_resource_id': resource_id(subscription=self.get_subscription_id(),
2495+
resource_group=resource_group,
2496+
namespace=resource_type.split('/')[0],
2497+
type=resource_type.split('/')[1],
2498+
name=target_resource_name),
2499+
'rg': resource_group,
2500+
'resource_type': resource_type,
2501+
'vnet': self.create_random_name('cli-vnet-', 24),
2502+
'subnet': self.create_random_name('cli-subnet-', 24),
2503+
'pe': self.create_random_name('cli-pe-', 24),
2504+
'pe_connection': self.create_random_name('cli-pec-', 24)
2505+
})
2506+
2507+
split_resource_type = resource_type.split('/')
2508+
resource_type_name = split_resource_type[0].split('.')[1].lower()
2509+
resource_type_kind = split_resource_type[1].lower()
2510+
param_file_name = "{}_{}_parameters.json".format(resource_type_name, resource_type_kind)
2511+
template_file_name = "{}_{}_template.json".format(resource_type_name, resource_type_kind)
2512+
self.kwargs.update({
2513+
'param_path': os.path.join(TEST_DIR, 'private_endpoint_arm_templates', param_file_name),
2514+
'template_path': os.path.join(TEST_DIR, 'private_endpoint_arm_templates', template_file_name)
2515+
})
2516+
self.cmd('az deployment group create -g {rg} -p "@{param_path}" target_resource_name={target_resource_name} -f "{template_path}"')
2517+
2518+
self.cmd('az network vnet create -n {vnet} -g {rg} --subnet-name {subnet} -o json',
2519+
checks=self.check('length(newVNet.subnets)', 1))
2520+
self.cmd('az network vnet subnet update -n {subnet} --vnet-name {vnet} -g {rg} '
2521+
'--disable-private-endpoint-network-policies true -o json',
2522+
checks=self.check('privateEndpointNetworkPolicies', 'Disabled'))
2523+
2524+
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()
2525+
self.kwargs.update({
2526+
'group_id': target_private_link_resource[0]['properties']['groupId']
2527+
})
2528+
# Create a private endpoint connection
2529+
pe = self.cmd(
2530+
'az network private-endpoint create -g {rg} -n {pe} --vnet-name {vnet} --subnet {subnet} '
2531+
'--connection-name {pe_connection} --private-connection-resource-id {target_resource_id} '
2532+
'--group-id {group_id} -o json').get_output_in_json()
2533+
self.kwargs['pe_id'] = pe['id']
2534+
self.kwargs['pe_name'] = self.kwargs['pe_id'].split('/')[-1]
2535+
2536+
# Show the connection at the target resource side
2537+
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()
2538+
self.kwargs.update({
2539+
"pec_id": list_private_endpoint_conn[0]['id']
2540+
})
2541+
2542+
self.kwargs.update({
2543+
"pec_name": self.kwargs['pec_id'].split('/')[-1]
2544+
})
2545+
self.cmd('az network private-endpoint-connection show --id {pec_id} -o json',
2546+
checks=self.check('id', '{pec_id}'))
2547+
self.cmd('az network private-endpoint-connection show --resource-name {target_resource_name} --name {pec_name} --resource-group {rg} --type {resource_type} -o json')
2548+
self.cmd('az network private-endpoint-connection show --resource-name {target_resource_name} -n {pec_name} -g {rg} --type {resource_type} -o json')
2549+
2550+
# Test approval/rejection
2551+
self.kwargs.update({
2552+
'approval_desc': 'You are approved!',
2553+
'rejection_desc': 'You are rejected!'
2554+
})
2555+
self.cmd(
2556+
'az network private-endpoint-connection approve --resource-name {target_resource_name} --resource-group {rg} --name {pec_name} --type {resource_type} '
2557+
'--description "{approval_desc}" -o json', checks=[
2558+
self.check('properties.privateLinkServiceConnectionState.status', 'Approved')
2559+
])
2560+
self.cmd('az network private-endpoint-connection reject --id {pec_id} '
2561+
'--description "{rejection_desc}" -o json',
2562+
checks=[
2563+
self.check('properties.privateLinkServiceConnectionState.status', 'Rejected')
2564+
])
2565+
self.cmd(
2566+
'az network private-endpoint-connection list --name {target_resource_name} --resource-group {rg} --type {resource_type} -o json',
2567+
checks=[
2568+
self.check('length(@)', 1)
2569+
])
2570+
2571+
# Test delete
2572+
self.cmd('az network private-endpoint-connection delete --id {pec_id} -y -o json')
2573+
2574+
@live_only()
2575+
@ResourceGroupPreparer(name_prefix="test_private_endpoint_connection_security_privatelink", location="westus")
2576+
def test_private_endpoint_connection_security_privatelink(self, resource_group):
2577+
name = self.create_random_name(prefix='clitestsecuritypl', length=24)
2578+
self._test_private_endpoint_connection_scenario(resource_group, name)
24942579

24952580
class NetworkPrivateLinkDigitalTwinsScenarioTest(ScenarioTest):
24962581
@ResourceGroupPreparer(
@@ -2883,7 +2968,7 @@ def test_private_endpoint_connection_synapse_workspace(self, resource_group, sto
28832968

28842969
_test_private_endpoint(self)
28852970

2886-
@ResourceGroupPreparer(name_prefix="test_private_endpoint_connection_sql_server", location="westus")
2971+
@ResourceGroupPreparer(name_prefix="test_private_endpoint_connection_sql_server", location="westus2")
28872972
def test_private_endpoint_connection_sql_server(self, resource_group):
28882973
self.kwargs.update({
28892974
'rg': resource_group,

0 commit comments

Comments
 (0)