diff --git a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py index 7ab979c21f9..e736d7fe118 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py +++ b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py @@ -479,99 +479,6 @@ def ensure_container_insights_for_monitoring( else: raise error - else: - # legacy auth with LA workspace solution - unix_time_in_millis = int( - ( - datetime.datetime.utcnow() - - datetime.datetime.utcfromtimestamp(0) - ).total_seconds() * 1000.0 - ) - - solution_deployment_name = "ContainerInsights-{}".format( - unix_time_in_millis - ) - - # pylint: disable=line-too-long - template = { - "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "workspaceResourceId": { - "type": "string", - "metadata": { - "description": "Azure Monitor Log Analytics Resource ID" - }, - }, - "workspaceRegion": { - "type": "string", - "metadata": { - "description": "Azure Monitor Log Analytics workspace region" - }, - }, - "solutionDeploymentName": { - "type": "string", - "metadata": { - "description": "Name of the solution deployment" - }, - }, - }, - "resources": [ - { - "type": "Microsoft.Resources/deployments", - "name": "[parameters('solutionDeploymentName')]", - "apiVersion": "2017-05-10", - "subscriptionId": "[split(parameters('workspaceResourceId'),'/')[2]]", - "resourceGroup": "[split(parameters('workspaceResourceId'),'/')[4]]", - "properties": { - "mode": "Incremental", - "template": { - "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", - "contentVersion": "1.0.0.0", - "parameters": {}, - "variables": {}, - "resources": [ - { - "apiVersion": "2015-11-01-preview", - "type": "Microsoft.OperationsManagement/solutions", - "location": "[parameters('workspaceRegion')]", - "name": "[Concat('ContainerInsights', '(', split(parameters('workspaceResourceId'),'/')[8], ')')]", - "properties": { - "workspaceResourceId": "[parameters('workspaceResourceId')]" - }, - "plan": { - "name": "[Concat('ContainerInsights', '(', split(parameters('workspaceResourceId'),'/')[8], ')')]", - "product": "[Concat('OMSGallery/', 'ContainerInsights')]", - "promotionCode": "", - "publisher": "Microsoft", - }, - } - ], - }, - "parameters": {}, - }, - } - ], - } - - params = { - "workspaceResourceId": {"value": workspace_resource_id}, - "workspaceRegion": {"value": location}, - "solutionDeploymentName": {"value": solution_deployment_name}, - } - - deployment_name = "aks-monitoring-{}".format(unix_time_in_millis) - # publish the Container Insights solution to the Log Analytics workspace - return _invoke_deployment( - cmd, - resource_group, - deployment_name, - template, - params, - validate=False, - no_wait=False, - subscription_id=subscription_id, - ) def _invoke_deployment( diff --git a/src/azure-cli/azure/cli/command_modules/acs/custom.py b/src/azure-cli/azure/cli/command_modules/acs/custom.py index 0667ddb303e..33851382fbd 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/custom.py @@ -2951,128 +2951,6 @@ def _get_or_add_extension(cmd, extension_name, extension_module, update=False): return _install_dev_spaces_extension(cmd, extension_name) return True - -def _ensure_container_insights_for_monitoring(cmd, addon): - # Workaround for this addon key which has been seen lowercased in the wild. - for key in list(addon.config): - if (key.lower() == CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID.lower() and - key != CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID): - addon.config[CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID] = addon.config.pop( - key) - - workspace_resource_id = addon.config[CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID] - - workspace_resource_id = workspace_resource_id.strip() - - if not workspace_resource_id.startswith('/'): - workspace_resource_id = '/' + workspace_resource_id - - if workspace_resource_id.endswith('/'): - workspace_resource_id = workspace_resource_id.rstrip('/') - - # extract subscription ID and resource group from workspace_resource_id URL - try: - subscription_id = workspace_resource_id.split('/')[2] - resource_group = workspace_resource_id.split('/')[4] - except IndexError: - raise CLIError( - 'Could not locate resource group in workspace-resource-id URL.') - - # region of workspace can be different from region of RG so find the location of the workspace_resource_id - resources = cf_resources(cmd.cli_ctx, subscription_id) - try: - resource = resources.get_by_id( - workspace_resource_id, '2015-11-01-preview') - location = resource.location - except CloudError as ex: - raise ex - - unix_time_in_millis = int( - (datetime.datetime.utcnow() - datetime.datetime.utcfromtimestamp(0)).total_seconds() * 1000.0) - - solution_deployment_name = 'ContainerInsights-{}'.format( - unix_time_in_millis) - - # pylint: disable=line-too-long - template = { - "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "workspaceResourceId": { - "type": "string", - "metadata": { - "description": "Azure Monitor Log Analytics Resource ID" - } - }, - "workspaceRegion": { - "type": "string", - "metadata": { - "description": "Azure Monitor Log Analytics workspace region" - } - }, - "solutionDeploymentName": { - "type": "string", - "metadata": { - "description": "Name of the solution deployment" - } - } - }, - "resources": [ - { - "type": "Microsoft.Resources/deployments", - "name": "[parameters('solutionDeploymentName')]", - "apiVersion": "2017-05-10", - "subscriptionId": "[split(parameters('workspaceResourceId'),'/')[2]]", - "resourceGroup": "[split(parameters('workspaceResourceId'),'/')[4]]", - "properties": { - "mode": "Incremental", - "template": { - "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", - "contentVersion": "1.0.0.0", - "parameters": {}, - "variables": {}, - "resources": [ - { - "apiVersion": "2015-11-01-preview", - "type": "Microsoft.OperationsManagement/solutions", - "location": "[parameters('workspaceRegion')]", - "name": "[Concat('ContainerInsights', '(', split(parameters('workspaceResourceId'),'/')[8], ')')]", - "properties": { - "workspaceResourceId": "[parameters('workspaceResourceId')]" - }, - "plan": { - "name": "[Concat('ContainerInsights', '(', split(parameters('workspaceResourceId'),'/')[8], ')')]", - "product": "[Concat('OMSGallery/', 'ContainerInsights')]", - "promotionCode": "", - "publisher": "Microsoft" - } - } - ] - }, - "parameters": {} - } - } - ] - } - - params = { - "workspaceResourceId": { - "value": workspace_resource_id - }, - "workspaceRegion": { - "value": location - }, - "solutionDeploymentName": { - "value": solution_deployment_name - } - } - - deployment_name = 'aks-monitoring-{}'.format(unix_time_in_millis) - # publish the Container Insights solution to the Log Analytics workspace - return _invoke_deployment(cmd, resource_group, deployment_name, template, params, - validate=False, no_wait=False, subscription_id=subscription_id) - - def _ensure_aks_acr(cmd, assignee, acr_name_or_id, diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/hybrid_2020_09_01/test_custom.py b/src/azure-cli/azure/cli/command_modules/acs/tests/hybrid_2020_09_01/test_custom.py index 73e114e9a68..98edbaa8520 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/hybrid_2020_09_01/test_custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/hybrid_2020_09_01/test_custom.py @@ -625,7 +625,7 @@ def test_update_addons(self, rg_def, cf_resource_groups, cf_resources): # http_application_routing enabled instance = mock.MagicMock() instance.addon_profiles = None - + instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'http_application_routing', enable=True) self.assertIn(CONST_HTTP_APPLICATION_ROUTING_ADDON_NAME, instance.addon_profiles) @@ -780,18 +780,12 @@ def test_ensure_container_insights_for_monitoring(self, invoke_def, cf_resources CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID: wsID } self.assertTrue(ensure_container_insights_for_monitoring(cmd, addon, subscription_id, rg_name, cluster_name, location)) - args, kwargs = invoke_def.call_args - self.assertEqual(args[3]['resources'][0]['type'], "Microsoft.Resources/deployments") - self.assertEqual(args[4]['workspaceResourceId']['value'], wsID) - # when addon config key is lower cased addon.config = { CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID: wsID } self.assertTrue(ensure_container_insights_for_monitoring(cmd, addon, subscription_id, rg_name, cluster_name, location)) - args, kwargs = invoke_def.call_args - self.assertEqual(args[3]['resources'][0]['type'], "Microsoft.Resources/deployments") - self.assertEqual(args[4]['workspaceResourceId']['value'], wsID) + @mock.patch('azure.cli.command_modules.acs.custom._urlretrieve') @mock.patch('azure.cli.command_modules.acs.custom.logger') diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_custom.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_custom.py index 1dafb2d9a2f..ba9134b36a5 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_custom.py @@ -625,7 +625,7 @@ def test_update_addons(self, rg_def, cf_resource_groups, cf_resources): # http_application_routing enabled instance = mock.MagicMock() instance.addon_profiles = None - + instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'http_application_routing', enable=True) self.assertIn(CONST_HTTP_APPLICATION_ROUTING_ADDON_NAME, instance.addon_profiles) @@ -780,18 +780,13 @@ def test_ensure_container_insights_for_monitoring(self, invoke_def, cf_resources CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID: wsID } self.assertTrue(ensure_container_insights_for_monitoring(cmd, addon, subscription_id, rg_name, cluster_name, location)) - args, kwargs = invoke_def.call_args - self.assertEqual(args[3]['resources'][0]['type'], "Microsoft.Resources/deployments") - self.assertEqual(args[4]['workspaceResourceId']['value'], wsID) # when addon config key is lower cased addon.config = { CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID: wsID } self.assertTrue(ensure_container_insights_for_monitoring(cmd, addon, subscription_id, rg_name, cluster_name, location)) - args, kwargs = invoke_def.call_args - self.assertEqual(args[3]['resources'][0]['type'], "Microsoft.Resources/deployments") - self.assertEqual(args[4]['workspaceResourceId']['value'], wsID) + @mock.patch('azure.cli.command_modules.acs.custom._urlretrieve') @mock.patch('azure.cli.command_modules.acs.custom.logger')