Skip to content

Commit

Permalink
[Network] az network private-endpoint-connection: Enable private li…
Browse files Browse the repository at this point in the history
…nk support for provider `Microsoft.Dashboard/grafana` (#22298)

* Register Azure Managed Grafana Service

* Add test for Grafana service

* Fix typo

* Update
  • Loading branch information
MSGaryWang authored Jul 13, 2022
1 parent c0aa8c4 commit b6b5cbf
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def register_providers():
_register_one_provider('Microsoft.CognitiveServices/accounts', '2022-03-01', True)
_register_one_provider('Microsoft.Compute/diskAccesses', '2020-09-30', True)
_register_one_provider('Microsoft.ContainerRegistry/registries', '2019-12-01-preview', True)
_register_one_provider('Microsoft.Dashboard/grafana', '2022-05-01-preview', True)
_register_one_provider('Microsoft.DBforMySQL/servers', '2018-06-01', False, '2017-12-01-preview')
_register_one_provider('Microsoft.DBforMariaDB/servers', '2018-06-01', False)
_register_one_provider('Microsoft.DBforPostgreSQL/servers', '2018-06-01', False, '2017-12-01-preview')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3323,5 +3323,71 @@ def test_kubernetesconfiguration_private_endpoint(self, resource_group):



class NetworkPrivateLinkManagedGrafanaScenarioTest(ScenarioTest):
@live_only()
@ResourceGroupPreparer(name_prefix='test_grafana_private_endpoint_', random_name_length=40)
def test_private_endpoint_connection_grafana(self, resource_group):
self.kwargs.update({
'resource_group': resource_group,
'service_name': self.create_random_name('cli-test-srv-', 22),
'vnet_name': self.create_random_name('cli-test-vnet-', 22),
'subnet_name': self.create_random_name('cli-test-subnet-', 22),
'endpoint_name': self.create_random_name('cli-test-pe-', 22),
'endpoint_conn_name': self.create_random_name('cli-test-pec-', 22),
'location': "eastus2euap",
})

# Install extension for Azure Managed Grafana Service
self.cmd('extension add -n amg')

# Create Azure Managed Grafana Service
service_created = self.cmd(
'grafana create -g {resource_group} -n {service_name} --l {location}').get_output_in_json()
self.kwargs['service_id'] = service_created['id']

# Check private link resource is available
self.cmd('network private-link-resource list --id {service_id}', checks=[
self.check('length(@)', 1),
])

# Prepare network
self.cmd('network vnet create -n {vnet_name} -g {resource_group} --subnet-name {subnet_name}',
checks=self.check('length(newVNet.subnets)', 1))
self.cmd('network vnet subnet update -n {subnet_name} --vnet-name {vnet_name} -g {resource_group} '
'--disable-private-endpoint-network-policies true',
checks=self.check('privateEndpointNetworkPolicies', 'Disabled'))

result = self.cmd(
'network vnet subnet show -n {subnet_name} --vnet-name {vnet_name} -g {resource_group} ').get_output_in_json()

# Create private endpoint
result = self.cmd(
'network private-endpoint create -g {resource_group} -n {endpoint_name} --vnet-name {vnet_name} --subnet {subnet_name} '
'--connection-name {endpoint_conn_name} --private-connection-resource-id {service_id} '
'--group-id Gateway').get_output_in_json()
self.assertTrue(
self.kwargs['endpoint_name'].lower() in result['name'].lower())

result = self.cmd(
'network private-endpoint-connection list -g {resource_group} -n {service_name} --type Microsoft.Dashboard/grafana',
checks=[self.check('length(@)', 1), ]).get_output_in_json()
self.kwargs.update({
"endpoint_request": result[0]['name'],
"pec_id": result[0]['id'],
"pec_name": result[0]['id'].split('/')[-1]
})

# Show the private endpoint connection
self.cmd('az network private-endpoint-connection show --id {pec_id}',
checks=self.check('id', '{pec_id}'))

self.cmd('az network private-endpoint-connection show --resource-name {service_name} -n {pec_name} -g {resource_group} --type Microsoft.Dashboard/grafana',
checks=self.check('id', '{pec_id}'))

# Remove private endpoint
self.cmd(
'network private-endpoint-connection delete -g {resource_group} --resource-name {service_name} -n {endpoint_request} --type Microsoft.Dashboard/grafana -y')


if __name__ == '__main__':
unittest.main()

0 comments on commit b6b5cbf

Please sign in to comment.