From 78e954cf954c20fd6e6143d0c27cb71806be58eb Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Tue, 18 May 2021 00:47:31 -0700 Subject: [PATCH 01/29] Adding ACR and AKS for azurestack hybrid profile --- .../azure/cli/core/profiles/_shared.py | 22 +++++++++++++++---- .../command_modules/acs/_client_factory.py | 4 +--- .../azure/cli/command_modules/acs/commands.py | 10 +++++++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/profiles/_shared.py b/src/azure-cli-core/azure/cli/core/profiles/_shared.py index 5d96dfa5795..86f81c74e49 100644 --- a/src/azure-cli-core/azure/cli/core/profiles/_shared.py +++ b/src/azure-cli-core/azure/cli/core/profiles/_shared.py @@ -59,12 +59,12 @@ class ResourceType(Enum): # pylint: disable=too-few-public-methods MGMT_IOTHUB = ('azure.mgmt.iothub', 'IotHubClient') MGMT_ARO = ('azure.mgmt.redhatopenshift', 'AzureRedHatOpenShiftClient') MGMT_DATABOXEDGE = ('azure.mgmt.databoxedge', 'DataBoxEdgeManagementClient') + MGMT_CONTAINERSERVICE = ('azure.mgmt.containerservice', 'ContainerServiceClient') # the "None" below will stay till a command module fills in the type so "get_mgmt_service_client" # can be provided with "ResourceType.XXX" to initialize the client object. This usually happens # when related commands start to support Multi-API DATA_COSMOS_TABLE = ('azure.multiapi.cosmosdb', None) - MGMT_CONTAINERSERVICE = ('azure.mgmt.containerservice', None) MGMT_ADVISOR = ('azure.mgmt.advisor', None) MGMT_MEDIA = ('azure.mgmt.media', None) MGMT_BACKUP = ('azure.mgmt.recoveryservicesbackup', None) @@ -210,7 +210,11 @@ def default_api_version(self): ResourceType.MGMT_APPSERVICE: '2020-09-01', ResourceType.MGMT_IOTHUB: '2020-03-01', ResourceType.MGMT_ARO: '2020-04-30', - ResourceType.MGMT_DATABOXEDGE: '2019-08-01' + ResourceType.MGMT_DATABOXEDGE: '2019-08-01', + ResourceType.MGMT_CONTAINERSERVICE: SDKProfile('2020-03-01', { + 'container_services': '2017-07-01', + 'open_shift_managed_clusters': '2019-10-27-preview' + }) }, '2020-09-01-hybrid': { ResourceType.MGMT_STORAGE: '2019-06-01', @@ -250,7 +254,12 @@ def default_api_version(self): ResourceType.MGMT_APPSERVICE: '2018-02-01', ResourceType.MGMT_EVENTHUB: '2018-01-01-preview', ResourceType.MGMT_IOTHUB: '2019-07-01-preview', - ResourceType.MGMT_DATABOXEDGE: '2019-08-01' + ResourceType.MGMT_DATABOXEDGE: '2019-08-01', + ResourceType.MGMT_CONTAINERREGISTRY: '2019-05-01', + ResourceType.MGMT_CONTAINERSERVICE: SDKProfile('2020-03-01', { + 'container_services': '2017-07-01', + 'open_shift_managed_clusters': '2019-10-27-preview' + }) }, '2019-03-01-hybrid': { ResourceType.MGMT_STORAGE: '2017-10-01', @@ -286,7 +295,12 @@ def default_api_version(self): ResourceType.MGMT_APPSERVICE: '2018-02-01', ResourceType.MGMT_EVENTHUB: '2018-01-01-preview', ResourceType.MGMT_IOTHUB: '2019-03-22', - ResourceType.MGMT_DATABOXEDGE: '2019-08-01' + ResourceType.MGMT_DATABOXEDGE: '2019-08-01', + ResourceType.MGMT_CONTAINERREGISTRY: '2019-05-01', + ResourceType.MGMT_CONTAINERSERVICE: SDKProfile('2020-03-01', { + 'container_services': '2017-07-01', + 'open_shift_managed_clusters': '2019-10-27-preview' + }) }, '2018-03-01-hybrid': { ResourceType.MGMT_STORAGE: '2016-01-01', diff --git a/src/azure-cli/azure/cli/command_modules/acs/_client_factory.py b/src/azure-cli/azure/cli/command_modules/acs/_client_factory.py index be65ecde7a4..fde7325d37c 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_client_factory.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_client_factory.py @@ -59,9 +59,7 @@ def get_auth_management_client(cli_ctx, scope=None, **_): def get_container_service_client(cli_ctx, **_): - from azure.mgmt.containerservice import ContainerServiceClient - - return get_mgmt_service_client(cli_ctx, ContainerServiceClient) + return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_CONTAINERSERVICE) def get_osa_container_service_client(cli_ctx, **_): diff --git a/src/azure-cli/azure/cli/command_modules/acs/commands.py b/src/azure-cli/azure/cli/command_modules/acs/commands.py index 756f1d9bf9e..9923ce65c6e 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/commands.py +++ b/src/azure-cli/azure/cli/command_modules/acs/commands.py @@ -6,6 +6,7 @@ # pylint: disable=no-name-in-module,import-error from azure.cli.core.commands import CliCommandType from azure.cli.core.commands.arm import deployment_validate_table_format +from azure.cli.core.profiles import ResourceType from ._client_factory import cf_container_services from ._client_factory import cf_managed_clusters @@ -25,8 +26,10 @@ def load_command_table(self, _): container_services_sdk = CliCommandType( - operations_tmpl='azure.mgmt.containerservice.v2017_07_01.operations.' + operations_tmpl='azure.mgmt.containerservice.operations.' '_container_services_operations#ContainerServicesOperations.{}', + operation_group='container_services', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, client_factory=cf_container_services ) @@ -39,12 +42,15 @@ def load_command_table(self, _): agent_pools_sdk = CliCommandType( operations_tmpl='azext_aks_preview.vendored_sdks.azure_mgmt_preview_aks.' 'operations._agent_pools_operations#AgentPoolsOperations.{}', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, client_factory=cf_managed_clusters ) openshift_managed_clusters_sdk = CliCommandType( - operations_tmpl='azure.mgmt.containerservice.v2018_09_30_preview.operations.' + operations_tmpl='azure.mgmt.containerservice.operations.' '_open_shift_managed_clusters_operations#OpenShiftManagedClustersOperations.{}', + operation_group='open_shift_managed_clusters', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, client_factory=cf_openshift_managed_clusters ) From 65fd82aa6da0be5295cc41325359879d212d627e Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Wed, 19 May 2021 15:50:15 -0700 Subject: [PATCH 02/29] Change managed cluster SDK profile for acs --- src/azure-cli-core/azure/cli/core/profiles/_shared.py | 9 ++------- src/azure-cli/azure/cli/command_modules/acs/commands.py | 3 ++- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/profiles/_shared.py b/src/azure-cli-core/azure/cli/core/profiles/_shared.py index 86f81c74e49..a30e083d74e 100644 --- a/src/azure-cli-core/azure/cli/core/profiles/_shared.py +++ b/src/azure-cli-core/azure/cli/core/profiles/_shared.py @@ -211,7 +211,7 @@ def default_api_version(self): ResourceType.MGMT_IOTHUB: '2020-03-01', ResourceType.MGMT_ARO: '2020-04-30', ResourceType.MGMT_DATABOXEDGE: '2019-08-01', - ResourceType.MGMT_CONTAINERSERVICE: SDKProfile('2020-03-01', { + ResourceType.MGMT_CONTAINERSERVICE: SDKProfile('2021-03-01', { 'container_services': '2017-07-01', 'open_shift_managed_clusters': '2019-10-27-preview' }) @@ -295,12 +295,7 @@ def default_api_version(self): ResourceType.MGMT_APPSERVICE: '2018-02-01', ResourceType.MGMT_EVENTHUB: '2018-01-01-preview', ResourceType.MGMT_IOTHUB: '2019-03-22', - ResourceType.MGMT_DATABOXEDGE: '2019-08-01', - ResourceType.MGMT_CONTAINERREGISTRY: '2019-05-01', - ResourceType.MGMT_CONTAINERSERVICE: SDKProfile('2020-03-01', { - 'container_services': '2017-07-01', - 'open_shift_managed_clusters': '2019-10-27-preview' - }) + ResourceType.MGMT_DATABOXEDGE: '2019-08-01' }, '2018-03-01-hybrid': { ResourceType.MGMT_STORAGE: '2016-01-01', diff --git a/src/azure-cli/azure/cli/command_modules/acs/commands.py b/src/azure-cli/azure/cli/command_modules/acs/commands.py index 9923ce65c6e..cae50c84c68 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/commands.py +++ b/src/azure-cli/azure/cli/command_modules/acs/commands.py @@ -34,8 +34,9 @@ def load_command_table(self, _): ) managed_clusters_sdk = CliCommandType( - operations_tmpl='azure.mgmt.containerservice.v2021_03_01.operations.' + operations_tmpl='azure.mgmt.containerservice.operations.' '_managed_clusters_operations#ManagedClustersOperations.{}', + operation_group='managed_clusters', client_factory=cf_managed_clusters ) From e31c68f9cd240b2f9ce0a6bcb3f473aea2b5ef57 Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Fri, 21 May 2021 02:04:52 -0700 Subject: [PATCH 03/29] Container service resource type to managed cluster sdk --- src/azure-cli/azure/cli/command_modules/acs/commands.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/azure-cli/azure/cli/command_modules/acs/commands.py b/src/azure-cli/azure/cli/command_modules/acs/commands.py index cae50c84c68..daa0ea031f6 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/commands.py +++ b/src/azure-cli/azure/cli/command_modules/acs/commands.py @@ -37,6 +37,7 @@ def load_command_table(self, _): operations_tmpl='azure.mgmt.containerservice.operations.' '_managed_clusters_operations#ManagedClustersOperations.{}', operation_group='managed_clusters', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, client_factory=cf_managed_clusters ) From c1d3fdca55618f516c3d4ccfa17a8a3df7310632 Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Fri, 21 May 2021 15:50:29 -0700 Subject: [PATCH 04/29] Removing hardcoded api-version to import models --- .../azure/cli/command_modules/acs/custom.py | 77 +++++++++++-------- 1 file changed, 43 insertions(+), 34 deletions(-) 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 d0f051a5fe1..66d68d9e066 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/custom.py @@ -53,6 +53,7 @@ MutuallyExclusiveArgumentError, ValidationError) from azure.cli.core._profile import Profile +from azure.cli.core.profiles import ResourceType from azure.cli.core.commands.client_factory import get_mgmt_service_client, get_subscription_id from azure.cli.core.keys import is_valid_ssh_rsa_public_key from azure.cli.core.util import in_cloud_console, shell_safe_json_parse, truncate_text, sdk_no_wait @@ -67,33 +68,6 @@ from azure.mgmt.containerservice.models import ContainerServiceOrchestratorTypes -from azure.mgmt.containerservice.v2021_03_01.models import ContainerServiceNetworkProfile -from azure.mgmt.containerservice.v2021_03_01.models import ContainerServiceLinuxProfile -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterServicePrincipalProfile -from azure.mgmt.containerservice.v2021_03_01.models import ContainerServiceSshConfiguration -from azure.mgmt.containerservice.v2021_03_01.models import ContainerServiceSshPublicKey -from azure.mgmt.containerservice.v2021_03_01.models import ManagedCluster -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterAADProfile -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterAddonProfile -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterAgentPoolProfile -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterIdentity -from azure.mgmt.containerservice.v2021_03_01.models import AgentPool -from azure.mgmt.containerservice.v2021_03_01.models import AgentPoolUpgradeSettings -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterSKU -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterWindowsProfile -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterIdentityUserAssignedIdentitiesValue -from azure.mgmt.containerservice.v2021_03_01.models import RunCommandRequest - -from azure.mgmt.containerservice.v2019_09_30_preview.models import OpenShiftManagedClusterAgentPoolProfile -from azure.mgmt.containerservice.v2019_09_30_preview.models import OpenShiftAgentPoolProfileRole -from azure.mgmt.containerservice.v2019_09_30_preview.models import OpenShiftManagedClusterIdentityProvider -from azure.mgmt.containerservice.v2019_09_30_preview.models import OpenShiftManagedClusterAADIdentityProvider -from azure.mgmt.containerservice.v2019_09_30_preview.models import OpenShiftManagedCluster -from azure.mgmt.containerservice.v2019_09_30_preview.models import OpenShiftRouterProfile -from azure.mgmt.containerservice.v2019_09_30_preview.models import OpenShiftManagedClusterAuthProfile -from azure.mgmt.containerservice.v2019_09_30_preview.models import NetworkProfile -from azure.mgmt.containerservice.v2019_09_30_preview.models import OpenShiftManagedClusterMonitorProfile - from ._client_factory import cf_container_services from ._client_factory import cf_resource_groups from ._client_factory import get_auth_management_client @@ -129,10 +103,8 @@ logger = get_logger(__name__) - # pylint:disable=too-many-lines,unused-argument - def which(binary): path_var = os.getenv('PATH') if platform.system() == 'Windows': @@ -1652,6 +1624,7 @@ def aks_check_acr(cmd, client, resource_group_name, name, acr): # pylint: disable=too-many-statements,too-many-branches def aks_browse(cmd, client, resource_group_name, name, disable_browser=False, listen_address='127.0.0.1', listen_port='8001'): + ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) # verify the kube-dashboard addon was not disabled instance = client.get(resource_group_name, name) addon_profiles = instance.addon_profiles or {} @@ -1986,6 +1959,19 @@ def aks_create(cmd, client, resource_group_name, name, ssh_key_value, # pylint: no_wait=False, yes=False, enable_azure_rbac=False): + ManagedClusterIdentityUserAssignedIdentitiesValue = cmd.get_models('ManagedClusterIdentityUserAssignedIdentitiesValue',resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterWindowsProfile = cmd.get_models('ManagedClusterWindowsProfile',resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterSKU = cmd.get_models('ManagedClusterSKU', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ContainerServiceNetworkProfile = cmd.get_models('ContainerServiceNetworkProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ContainerServiceLinuxProfile = cmd.get_models('ContainerServiceLinuxProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterServicePrincipalProfile = cmd.get_models('ManagedClusterServicePrincipalProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ContainerServiceSshConfiguration = cmd.get_models('ContainerServiceSshConfiguration', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ContainerServiceSshPublicKey = cmd.get_models('ContainerServiceSshPublicKey', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterAADProfile = cmd.get_models('ManagedClusterAADProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterAgentPoolProfile = cmd.get_models('ManagedClusterAgentPoolProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterIdentity = cmd.get_models('ManagedClusterIdentity', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedCluster = cmd.get_models('ManagedCluster', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + _validate_ssh_key(no_ssh_key, ssh_key_value) subscription_id = get_subscription_id(cmd.cli_ctx) if dns_name_prefix and fqdn_subdomain: @@ -2578,6 +2564,10 @@ def aks_update(cmd, client, resource_group_name, name, no_wait=False, enable_azure_rbac=False, disable_azure_rbac=False): + ManagedClusterIdentityUserAssignedIdentitiesValue = cmd.get_models('ManagedClusterIdentityUserAssignedIdentitiesValue',resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterSKU = cmd.get_models('ManagedClusterSKU', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterAADProfile = cmd.get_models('ManagedClusterAADProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterIdentity = cmd.get_models('ManagedClusterIdentity', resource_type=ResourceType.MGMT_CONTAINERSERVICE) update_autoscaler = enable_cluster_autoscaler + \ disable_cluster_autoscaler + update_cluster_autoscaler update_lb_profile = is_load_balancer_profile_provided(load_balancer_managed_outbound_ip_count, @@ -2940,7 +2930,7 @@ def aks_runcommand(cmd, client, resource_group_name, name, command_string="", co if not command_string: raise ValidationError('Command cannot be empty.') - + RunCommandRequest = cmd.get_models('RunCommandRequest',resource_type=ResourceType.MGMT_CONTAINERSERVICE) request_payload = RunCommandRequest(command=command_string) request_payload.context = _get_command_context(command_files) @@ -3128,6 +3118,7 @@ def _update_addons(cmd, instance, subscription_id, resource_group_name, name, ad appgw_watch_namespace=None, enable_sgxquotehelper=False, no_wait=False): + ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) # parse the comma-separated addons argument addon_args = addons.split(',') @@ -3254,6 +3245,7 @@ def _handle_addons_args(cmd, addons_str, subscription_id, resource_group_name, a appgw_subnet_id=None, appgw_watch_namespace=None, enable_sgxquotehelper=False): + ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) if not addon_profiles: addon_profiles = {} addons = addons_str.split(',') if addons_str else [] @@ -3750,6 +3742,8 @@ def aks_agentpool_add(cmd, client, resource_group_name, cluster_name, nodepool_n mode="User", enable_encryption_at_host=False, no_wait=False): + AgentPool = cmd.get_models('AgentPool', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings', resource_type=ResourceType.MGMT_CONTAINERSERVICE) instances = client.list(resource_group_name, cluster_name) for agentpool_profile in instances: if agentpool_profile.name == nodepool_name: @@ -3838,6 +3832,7 @@ def aks_agentpool_upgrade(cmd, client, resource_group_name, cluster_name, node_image_only=False, max_surge=None, no_wait=False): + AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings', resource_type=ResourceType.MGMT_CONTAINERSERVICE) if kubernetes_version != '' and node_image_only: raise CLIError('Conflicting flags. Upgrading the Kubernetes version will also upgrade node image version.' 'If you only want to upgrade the node version please use the "--node-image-only" option only.') @@ -3870,7 +3865,7 @@ def aks_agentpool_update(cmd, client, resource_group_name, cluster_name, nodepoo max_surge=None, mode=None, no_wait=False): - + AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings', resource_type=ResourceType.MGMT_CONTAINERSERVICE) update_autoscaler = enable_cluster_autoscaler + \ disable_cluster_autoscaler + update_cluster_autoscaler @@ -4016,13 +4011,15 @@ def _ensure_aks_service_principal(cli_ctx, } -def _ensure_osa_aad(cli_ctx, +def _ensure_osa_aad(cmd, + cli_ctx, aad_client_app_id=None, aad_client_app_secret=None, aad_tenant_id=None, identifier=None, name=None, create=False, customer_admin_group_id=None): + OpenShiftManagedClusterAADIdentityProvider = cmd.get_models('OpenShiftManagedClusterAADIdentityProvider',resource_type=ResourceType.MGMT_CONTAINERSERVICE) rbac_client = get_graph_rbac_management_client(cli_ctx) if create: # This reply_url is temporary set since Azure need one to create the AAD. @@ -4320,6 +4317,14 @@ def openshift_create(cmd, client, resource_group_name, name, # pylint: disable= no_wait=False, workspace_id=None, customer_admin_group_id=None): + OpenShiftManagedClusterAgentPoolProfile = cmd.get_models('OpenShiftManagedClusterAgentPoolProfile',resource_type=ResourceType.MGMT_CONTAINERSERVICE) + OpenShiftAgentPoolProfileRole = cmd.get_models('OpenShiftAgentPoolProfileRole',resource_type=ResourceType.MGMT_CONTAINERSERVICE) + OpenShiftManagedClusterIdentityProvider = cmd.get_models('OpenShiftManagedClusterIdentityProvider',resource_type=ResourceType.MGMT_CONTAINERSERVICE) + OpenShiftManagedCluster = cmd.get_models('OpenShiftManagedCluster',resource_type=ResourceType.MGMT_CONTAINERSERVICE) + OpenShiftRouterProfile = cmd.get_models('OpenShiftRouterProfile',resource_type=ResourceType.MGMT_CONTAINERSERVICE) + NetworkProfile = cmd.get_models('NetworkProfile',resource_type=ResourceType.MGMT_CONTAINERSERVICE) + OpenShiftManagedClusterAuthProfile = cmd.get_models('OpenShiftManagedClusterAuthProfile',resource_type=ResourceType.MGMT_CONTAINERSERVICE) + OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile',resource_type=ResourceType.MGMT_CONTAINERSERVICE) logger.warning('Support for the creation of ARO 3.11 clusters ends 30 Nov 2020. Please see aka.ms/aro/4 for information on switching to ARO 4.') # pylint: disable=line-too-long if location is None: @@ -4365,7 +4370,8 @@ def openshift_create(cmd, client, resource_group_name, name, # pylint: disable= if aad_client_app_id is None and aad_client_app_secret is None and aad_tenant_id is None: create_aad = True - osa_aad_identity = _ensure_osa_aad(cmd.cli_ctx, + osa_aad_identity = _ensure_osa_aad(cmd, + cmd.cli_ctx, aad_client_app_id=aad_client_app_id, aad_client_app_secret=aad_client_app_secret, aad_tenant_id=aad_tenant_id, identifier=None, @@ -4416,7 +4422,8 @@ def openshift_create(cmd, client, resource_group_name, name, # pylint: disable= resource_group_name=resource_group_name, resource_name=name, parameters=osamc) result = LongRunningOperation(cmd.cli_ctx)(result) instance = client.get(resource_group_name, name) - _ensure_osa_aad(cmd.cli_ctx, + _ensure_osa_aad(cmd, + cmd.cli_ctx, aad_client_app_id=osa_aad_identity.client_id, aad_client_app_secret=osa_aad_identity.secret, aad_tenant_id=osa_aad_identity.tenant_id, identifier=instance.public_hostname, @@ -4460,6 +4467,7 @@ def openshift_scale(cmd, client, resource_group_name, name, compute_count, no_wa def openshift_monitor_enable(cmd, client, resource_group_name, name, workspace_id, no_wait=False): + OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile',resource_type=ResourceType.MGMT_CONTAINERSERVICE) logger.warning('The az openshift command is deprecated and has been replaced by az aro for ARO 4 clusters. See http://aka.ms/aro/4 for information on switching to ARO 4.') # pylint: disable=line-too-long instance = client.get(resource_group_name, name) @@ -4472,6 +4480,7 @@ def openshift_monitor_enable(cmd, client, resource_group_name, name, workspace_i def openshift_monitor_disable(cmd, client, resource_group_name, name, no_wait=False): + OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile',resource_type=ResourceType.MGMT_CONTAINERSERVICE) logger.warning('The az openshift command is deprecated and has been replaced by az aro for ARO 4 clusters. See http://aka.ms/aro/4 for information on switching to ARO 4.') # pylint: disable=line-too-long instance = client.get(resource_group_name, name) From 7fcc7fcb25e8515f811ed4e3c56a71cc8476fe92 Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Thu, 27 May 2021 16:03:28 -0700 Subject: [PATCH 05/29] Removing versioned models import --- .../azure/cli/command_modules/acs/_helpers.py | 5 +- .../cli/command_modules/acs/_loadbalancer.py | 19 ++--- .../azure/cli/command_modules/acs/_params.py | 27 +++---- .../cli/command_modules/acs/_validators.py | 5 +- .../azure/cli/command_modules/acs/commands.py | 7 +- .../azure/cli/command_modules/acs/custom.py | 71 ++++++++++--------- 6 files changed, 71 insertions(+), 63 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/_helpers.py index 2bac1eacbad..a945b87e261 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_helpers.py @@ -5,13 +5,14 @@ from distutils.version import StrictVersion # pylint: disable=no-name-in-module,import-error # pylint: disable=no-name-in-module,import-error -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterAPIServerAccessProfile from knack.util import CLIError +from azure.cli.core.profiles import ResourceType from ._consts import CONST_OUTBOUND_TYPE_LOAD_BALANCER, CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING -def _populate_api_server_access_profile(api_server_authorized_ip_ranges, enable_private_cluster=False, instance=None): +def _populate_api_server_access_profile(cmd, api_server_authorized_ip_ranges, enable_private_cluster=False, instance=None): if instance is None or instance.api_server_access_profile is None: + ManagedClusterAPIServerAccessProfile = cmd.get_models('ManagedClusterAPIServerAccessProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) profile = ManagedClusterAPIServerAccessProfile() else: profile = instance.api_server_access_profile diff --git a/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py b/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py index b7b04a385b4..6bf4dd5099f 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py @@ -6,10 +6,7 @@ from distutils.version import StrictVersion # pylint: disable=no-name-in-module,import-error # pylint: disable=no-name-in-module,import-error -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfile -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfileManagedOutboundIPs -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfileOutboundIPPrefixes -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfileOutboundIPs +from azure.cli.core.profiles import ResourceType from azure.mgmt.containerservice.v2021_03_01.models import ResourceReference from knack.log import get_logger @@ -38,19 +35,20 @@ def update_load_balancer_profile(managed_outbound_ip_count, outbound_ips, outbou outbound_ports, idle_timeout, profile) -def create_load_balancer_profile(managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, +def create_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, outbound_ports, idle_timeout): """parse and build load balancer profile""" if not is_load_balancer_profile_provided(managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, outbound_ports, idle_timeout): return None + ManagedClusterLoadBalancerProfile = cmd.get_models('ManagedClusterLoadBalancerProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) profile = ManagedClusterLoadBalancerProfile() return configure_load_balancer_profile(managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, outbound_ports, idle_timeout, profile) -def configure_load_balancer_profile(managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, outbound_ports, +def configure_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, outbound_ports, idle_timeout, profile): """configure a load balancer with customer supplied values""" if not profile: @@ -65,14 +63,17 @@ def configure_load_balancer_profile(managed_outbound_ip_count, outbound_ips, out profile.outbound_ips = None profile.outbound_ip_prefixes = None if managed_outbound_ip_count: + ManagedClusterLoadBalancerProfileManagedOutboundIPs = cmd.get_models('ManagedClusterLoadBalancerProfileManagedOutboundIPs', resource_type=ResourceType.MGMT_CONTAINERSERVICE) profile.managed_outbound_ips = ManagedClusterLoadBalancerProfileManagedOutboundIPs( count=managed_outbound_ip_count ) if outbound_ip_resources: + ManagedClusterLoadBalancerProfileOutboundIPs = cmd.get_models('ManagedClusterLoadBalancerProfileOutboundIPs', resource_type=ResourceType.MGMT_CONTAINERSERVICE) profile.outbound_ips = ManagedClusterLoadBalancerProfileOutboundIPs( public_ips=outbound_ip_resources ) if outbound_ip_prefix_resources: + ManagedClusterLoadBalancerProfileOutboundIPPrefixes = cmd.get_models('ManagedClusterLoadBalancerProfileOutboundIPPrefixes', resource_type=ResourceType.MGMT_CONTAINERSERVICE) profile.outbound_ip_prefixes = ManagedClusterLoadBalancerProfileOutboundIPPrefixes( public_ip_prefixes=outbound_ip_prefix_resources ) @@ -92,9 +93,10 @@ def is_load_balancer_profile_provided(managed_outbound_ip_count, outbound_ips, i idle_timeout]) -def _get_load_balancer_outbound_ips(load_balancer_outbound_ips): +def _get_load_balancer_outbound_ips(cmd, load_balancer_outbound_ips): """parse load balancer profile outbound IP ids and return an array of references to the outbound IP resources""" load_balancer_outbound_ip_resources = None + ResourceReference = cmd.get_models('ResourceReference', resource_type=ResourceType.MGMT_CONTAINERSERVICE) if load_balancer_outbound_ips: load_balancer_outbound_ip_resources = \ [ResourceReference(id=x.strip()) @@ -102,10 +104,11 @@ def _get_load_balancer_outbound_ips(load_balancer_outbound_ips): return load_balancer_outbound_ip_resources -def _get_load_balancer_outbound_ip_prefixes(load_balancer_outbound_ip_prefixes): +def _get_load_balancer_outbound_ip_prefixes(cmd, load_balancer_outbound_ip_prefixes): """parse load balancer profile outbound IP prefix ids and return an array \ of references to the outbound IP prefix resources""" load_balancer_outbound_ip_prefix_resources = None + ResourceReference = cmd.get_models('ResourceReference', resource_type=ResourceType.MGMT_CONTAINERSERVICE) if load_balancer_outbound_ip_prefixes: load_balancer_outbound_ip_prefix_resources = \ [ResourceReference(id=x.strip()) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_params.py b/src/azure-cli/azure/cli/command_modules/acs/_params.py index 5d43905d975..82c7b5cdf95 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_params.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_params.py @@ -13,6 +13,7 @@ file_type, get_enum_type, get_resource_name_completion_list, name_type, tags_type, zones_type) from azure.cli.core.commands.validators import validate_file_or_dict from knack.arguments import CLIArgumentType +from azure.cli.core.profiles import ResourceType from ._completers import ( get_vm_size_completion_list, get_k8s_versions_completion_list, get_k8s_upgrades_completion_list) @@ -157,7 +158,7 @@ def load_arguments(self, _): completer=FilesCompleter(), help='Path to an SSH key file to use.') # AKS command argument configuration - with self.argument_context('aks') as c: + with self.argument_context('aks', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c: c.argument('resource_name', name_type, help='Name of the managed cluster.', completer=get_resource_name_completion_list('Microsoft.ContainerService/ManagedClusters')) c.argument('name', name_type, help='Name of the managed cluster.', @@ -167,7 +168,7 @@ def load_arguments(self, _): c.argument('node_count', options_list=['--node-count', '-c'], type=int) c.argument('tags', tags_type) - with self.argument_context('aks create') as c: + with self.argument_context('aks create', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c: c.argument('name', validator=validate_linux_host_name) c.argument('kubernetes_version', completer=get_k8s_versions_completion_list) @@ -265,7 +266,7 @@ def load_arguments(self, _): '--yes', '-y'], help='Do not prompt for confirmation.', action='store_true') c.argument('enable_sgxquotehelper', action='store_true') - with self.argument_context('aks update') as c: + with self.argument_context('aks update', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c: c.argument('attach_acr', acr_arg_type, validator=validate_acr) c.argument('detach_acr', acr_arg_type, validator=validate_acr) @@ -303,10 +304,10 @@ def load_arguments(self, _): c.argument('yes', options_list=[ '--yes', '-y'], help='Do not prompt for confirmation.', action='store_true') - with self.argument_context('aks disable-addons') as c: + with self.argument_context('aks disable-addons', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c: c.argument('addons', options_list=['--addons', '-a']) - with self.argument_context('aks enable-addons') as c: + with self.argument_context('aks enable-addons', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c: c.argument('addons', options_list=['--addons', '-a']) c.argument('subnet_name', options_list=[ '--subnet-name', '-s'], help='Name of an existing subnet to use with the virtual-node add-on.') @@ -322,7 +323,7 @@ def load_arguments(self, _): '--appgw-watch-namespace'], arg_group='Application Gateway') c.argument('enable_sgxquotehelper', action='store_true') - with self.argument_context('aks get-credentials') as c: + with self.argument_context('aks get-credentials', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c: c.argument('admin', options_list=['--admin', '-a'], default=False) c.argument('context_name', options_list=['--context'], help='If specified, overwrite the default context name.') @@ -356,17 +357,17 @@ def load_arguments(self, _): c.argument('aad_server_app_secret') c.argument('aad_tenant_id') - with self.argument_context('aks upgrade') as c: + with self.argument_context('aks upgrade', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c: c.argument('kubernetes_version', completer=get_k8s_upgrades_completion_list) c.argument('yes', options_list=[ '--yes', '-y'], help='Do not prompt for confirmation.', action='store_true') - with self.argument_context('aks scale') as c: + with self.argument_context('aks scale', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c: c.argument('nodepool_name', type=str, help='Node pool name, up to 12 alphanumeric characters', validator=validate_nodepool_name) - with self.argument_context('aks nodepool') as c: + with self.argument_context('aks nodepool', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c: c.argument('cluster_name', type=str, help='The cluster name.') for scope in ['aks nodepool add']: @@ -405,7 +406,7 @@ def load_arguments(self, _): c.argument('nodepool_name', type=str, options_list=[ '--name', '-n'], validator=validate_nodepool_name, help='The node pool name.') - with self.argument_context('aks nodepool update') as c: + with self.argument_context('aks nodepool update', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='agent_pools') as c: c.argument('enable_cluster_autoscaler', options_list=[ "--enable-cluster-autoscaler", "-e"], action='store_true') c.argument('disable_cluster_autoscaler', options_list=[ @@ -439,7 +440,7 @@ def load_arguments(self, _): '--yes', '-y'], action='store_true', help='Do not prompt for confirmation') # OpenShift command argument configuration - with self.argument_context('openshift') as c: + with self.argument_context('openshift', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') as c: c.argument('resource_name', name_type, help='Name of the managed OpenShift cluster.', completer=get_resource_name_completion_list('Microsoft.ContainerService/OpenShiftManagedClusters')) c.argument('name', name_type, help='Name of the managed OpenShift cluster.', @@ -448,14 +449,14 @@ def load_arguments(self, _): '--compute-count', '-c'], type=int, default=4) c.argument('tags', tags_type) - with self.argument_context('openshift create') as c: + with self.argument_context('openshift create', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') as c: c.argument('name', validator=validate_linux_host_name) c.argument('compute_vm_size', options_list=['--compute-vm-size', '-s']) c.argument('customer_admin_group_id', options_list=[ '--customer-admin-group-id']) c.argument('workspace_id') - with self.argument_context('openshift monitor enable') as c: + with self.argument_context('openshift monitor enable', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') as c: c.argument( 'workspace_id', help='The resource ID of an existing Log Analytics Workspace to use for storing monitoring data.') diff --git a/src/azure-cli/azure/cli/command_modules/acs/_validators.py b/src/azure-cli/azure/cli/command_modules/acs/_validators.py index a650e3ca351..cf4ce0cd47b 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_validators.py @@ -18,7 +18,7 @@ from azure.cli.core.azclierror import InvalidArgumentValueError import azure.cli.core.keys as keys -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterPropertiesAutoScalerProfile +from azure.cli.core.profiles import ResourceType logger = get_logger(__name__) @@ -119,9 +119,10 @@ def validate_cluster_autoscaler_profile(namespace): _validate_cluster_autoscaler_key(key) -def _validate_cluster_autoscaler_key(key): +def _validate_cluster_autoscaler_key(cmd, key): if not key: raise CLIError('Empty key specified for cluster-autoscaler-profile') + ManagedClusterPropertiesAutoScalerProfile = cmd.get_models('ManagedClusterPropertiesAutoScalerProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) valid_keys = list(k.replace("_", "-") for k, v in ManagedClusterPropertiesAutoScalerProfile._attribute_map.items()) # pylint: disable=protected-access if key not in valid_keys: raise CLIError("'{0}' is an invalid key for cluster-autoscaler-profile. " diff --git a/src/azure-cli/azure/cli/command_modules/acs/commands.py b/src/azure-cli/azure/cli/command_modules/acs/commands.py index daa0ea031f6..e0d37dfacd9 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/commands.py +++ b/src/azure-cli/azure/cli/command_modules/acs/commands.py @@ -115,15 +115,15 @@ def load_command_table(self, _): confirmation='Kubernetes will be unavailable during certificate rotation process.\n' + 'Are you sure you want to perform this operation?') g.wait_command('wait') - g.command('stop', 'stop', supports_no_wait=True) - g.command('start', 'start', supports_no_wait=True) + g.command('stop', 'stop', supports_no_wait=True, min_api='2020-09-01', client_factory=cf_managed_clusters) + g.command('start', 'start', supports_no_wait=True, min_api='2020-09-01', client_factory=cf_managed_clusters) with self.command_group('aks', container_services_sdk, client_factory=cf_container_services) as g: g.custom_command('get-versions', 'aks_get_versions', table_transformer=aks_versions_table_format) # AKS agent pool commands - with self.command_group('aks nodepool', agent_pools_sdk, client_factory=cf_agent_pools) as g: + with self.command_group('aks nodepool', agent_pools_sdk, client_factory=cf_agent_pools, operation_group='agent_pools') as g: g.custom_command('list', 'aks_agentpool_list', table_transformer=aks_agentpool_list_table_format) g.custom_show_command('show', 'aks_agentpool_show', @@ -147,6 +147,7 @@ def load_command_table(self, _): # OSA commands with self.command_group('openshift', openshift_managed_clusters_sdk, client_factory=cf_openshift_managed_clusters, + operation_group='open_shift_managed_clusters', deprecate_info=self.deprecate(redirect='aro', hide=True)) as g: g.custom_command('create', 'openshift_create', supports_no_wait=True) g.command('delete', 'delete', supports_no_wait=True, confirmation=True) 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 66d68d9e066..ba70cf08ccb 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/custom.py @@ -105,6 +105,7 @@ # pylint:disable=too-many-lines,unused-argument + def which(binary): path_var = os.getenv('PATH') if platform.system() == 'Windows': @@ -1624,7 +1625,7 @@ def aks_check_acr(cmd, client, resource_group_name, name, acr): # pylint: disable=too-many-statements,too-many-branches def aks_browse(cmd, client, resource_group_name, name, disable_browser=False, listen_address='127.0.0.1', listen_port='8001'): - ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') # verify the kube-dashboard addon was not disabled instance = client.get(resource_group_name, name) addon_profiles = instance.addon_profiles or {} @@ -1959,18 +1960,18 @@ def aks_create(cmd, client, resource_group_name, name, ssh_key_value, # pylint: no_wait=False, yes=False, enable_azure_rbac=False): - ManagedClusterIdentityUserAssignedIdentitiesValue = cmd.get_models('ManagedClusterIdentityUserAssignedIdentitiesValue',resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ManagedClusterWindowsProfile = cmd.get_models('ManagedClusterWindowsProfile',resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ManagedClusterSKU = cmd.get_models('ManagedClusterSKU', resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ContainerServiceNetworkProfile = cmd.get_models('ContainerServiceNetworkProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ContainerServiceLinuxProfile = cmd.get_models('ContainerServiceLinuxProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ManagedClusterServicePrincipalProfile = cmd.get_models('ManagedClusterServicePrincipalProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ContainerServiceSshConfiguration = cmd.get_models('ContainerServiceSshConfiguration', resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ContainerServiceSshPublicKey = cmd.get_models('ContainerServiceSshPublicKey', resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ManagedClusterAADProfile = cmd.get_models('ManagedClusterAADProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ManagedClusterAgentPoolProfile = cmd.get_models('ManagedClusterAgentPoolProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ManagedClusterIdentity = cmd.get_models('ManagedClusterIdentity', resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ManagedCluster = cmd.get_models('ManagedCluster', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterIdentityUserAssignedIdentitiesValue = cmd.get_models('ManagedClusterIdentityUserAssignedIdentitiesValue', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') + ManagedClusterWindowsProfile = cmd.get_models('ManagedClusterWindowsProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') + ManagedClusterSKU = cmd.get_models('ManagedClusterSKU', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') + ContainerServiceNetworkProfile = cmd.get_models('ContainerServiceNetworkProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='container_services') + ContainerServiceLinuxProfile = cmd.get_models('ContainerServiceLinuxProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='container_services') + ManagedClusterServicePrincipalProfile = cmd.get_models('ManagedClusterServicePrincipalProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') + ContainerServiceSshConfiguration = cmd.get_models('ContainerServiceSshConfiguration', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='container_services') + ContainerServiceSshPublicKey = cmd.get_models('ContainerServiceSshPublicKey', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='container_services') + ManagedClusterAADProfile = cmd.get_models('ManagedClusterAADProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') + ManagedClusterAgentPoolProfile = cmd.get_models('ManagedClusterAgentPoolProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') + ManagedClusterIdentity = cmd.get_models('ManagedClusterIdentity', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') + ManagedCluster = cmd.get_models('ManagedCluster', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') _validate_ssh_key(no_ssh_key, ssh_key_value) subscription_id = get_subscription_id(cmd.cli_ctx) @@ -2564,10 +2565,10 @@ def aks_update(cmd, client, resource_group_name, name, no_wait=False, enable_azure_rbac=False, disable_azure_rbac=False): - ManagedClusterIdentityUserAssignedIdentitiesValue = cmd.get_models('ManagedClusterIdentityUserAssignedIdentitiesValue',resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ManagedClusterSKU = cmd.get_models('ManagedClusterSKU', resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ManagedClusterAADProfile = cmd.get_models('ManagedClusterAADProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ManagedClusterIdentity = cmd.get_models('ManagedClusterIdentity', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterIdentityUserAssignedIdentitiesValue = cmd.get_models('ManagedClusterIdentityUserAssignedIdentitiesValue', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') + ManagedClusterSKU = cmd.get_models('ManagedClusterSKU', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') + ManagedClusterAADProfile = cmd.get_models('ManagedClusterAADProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') + ManagedClusterIdentity = cmd.get_models('ManagedClusterIdentity', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') update_autoscaler = enable_cluster_autoscaler + \ disable_cluster_autoscaler + update_cluster_autoscaler update_lb_profile = is_load_balancer_profile_provided(load_balancer_managed_outbound_ip_count, @@ -2930,7 +2931,7 @@ def aks_runcommand(cmd, client, resource_group_name, name, command_string="", co if not command_string: raise ValidationError('Command cannot be empty.') - RunCommandRequest = cmd.get_models('RunCommandRequest',resource_type=ResourceType.MGMT_CONTAINERSERVICE) + RunCommandRequest = cmd.get_models('RunCommandRequest', resource_type=ResourceType.MGMT_CONTAINERSERVICE) request_payload = RunCommandRequest(command=command_string) request_payload.context = _get_command_context(command_files) @@ -3118,7 +3119,7 @@ def _update_addons(cmd, instance, subscription_id, resource_group_name, name, ad appgw_watch_namespace=None, enable_sgxquotehelper=False, no_wait=False): - ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') # parse the comma-separated addons argument addon_args = addons.split(',') @@ -3245,7 +3246,7 @@ def _handle_addons_args(cmd, addons_str, subscription_id, resource_group_name, a appgw_subnet_id=None, appgw_watch_namespace=None, enable_sgxquotehelper=False): - ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') if not addon_profiles: addon_profiles = {} addons = addons_str.split(',') if addons_str else [] @@ -3742,8 +3743,8 @@ def aks_agentpool_add(cmd, client, resource_group_name, cluster_name, nodepool_n mode="User", enable_encryption_at_host=False, no_wait=False): - AgentPool = cmd.get_models('AgentPool', resource_type=ResourceType.MGMT_CONTAINERSERVICE) - AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + AgentPool = cmd.get_models('AgentPool', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='agent_pools') + AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='agent_pools') instances = client.list(resource_group_name, cluster_name) for agentpool_profile in instances: if agentpool_profile.name == nodepool_name: @@ -3832,7 +3833,7 @@ def aks_agentpool_upgrade(cmd, client, resource_group_name, cluster_name, node_image_only=False, max_surge=None, no_wait=False): - AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings', operation_group='agent_pools') if kubernetes_version != '' and node_image_only: raise CLIError('Conflicting flags. Upgrading the Kubernetes version will also upgrade node image version.' 'If you only want to upgrade the node version please use the "--node-image-only" option only.') @@ -3865,7 +3866,7 @@ def aks_agentpool_update(cmd, client, resource_group_name, cluster_name, nodepoo max_surge=None, mode=None, no_wait=False): - AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='agent_pools') update_autoscaler = enable_cluster_autoscaler + \ disable_cluster_autoscaler + update_cluster_autoscaler @@ -4019,7 +4020,7 @@ def _ensure_osa_aad(cmd, identifier=None, name=None, create=False, customer_admin_group_id=None): - OpenShiftManagedClusterAADIdentityProvider = cmd.get_models('OpenShiftManagedClusterAADIdentityProvider',resource_type=ResourceType.MGMT_CONTAINERSERVICE) + OpenShiftManagedClusterAADIdentityProvider = cmd.get_models('OpenShiftManagedClusterAADIdentityProvider', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') rbac_client = get_graph_rbac_management_client(cli_ctx) if create: # This reply_url is temporary set since Azure need one to create the AAD. @@ -4317,14 +4318,14 @@ def openshift_create(cmd, client, resource_group_name, name, # pylint: disable= no_wait=False, workspace_id=None, customer_admin_group_id=None): - OpenShiftManagedClusterAgentPoolProfile = cmd.get_models('OpenShiftManagedClusterAgentPoolProfile',resource_type=ResourceType.MGMT_CONTAINERSERVICE) - OpenShiftAgentPoolProfileRole = cmd.get_models('OpenShiftAgentPoolProfileRole',resource_type=ResourceType.MGMT_CONTAINERSERVICE) - OpenShiftManagedClusterIdentityProvider = cmd.get_models('OpenShiftManagedClusterIdentityProvider',resource_type=ResourceType.MGMT_CONTAINERSERVICE) - OpenShiftManagedCluster = cmd.get_models('OpenShiftManagedCluster',resource_type=ResourceType.MGMT_CONTAINERSERVICE) - OpenShiftRouterProfile = cmd.get_models('OpenShiftRouterProfile',resource_type=ResourceType.MGMT_CONTAINERSERVICE) - NetworkProfile = cmd.get_models('NetworkProfile',resource_type=ResourceType.MGMT_CONTAINERSERVICE) - OpenShiftManagedClusterAuthProfile = cmd.get_models('OpenShiftManagedClusterAuthProfile',resource_type=ResourceType.MGMT_CONTAINERSERVICE) - OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile',resource_type=ResourceType.MGMT_CONTAINERSERVICE) + OpenShiftManagedClusterAgentPoolProfile = cmd.get_models('OpenShiftManagedClusterAgentPoolProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') + OpenShiftAgentPoolProfileRole = cmd.get_models('OpenShiftAgentPoolProfileRole', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') + OpenShiftManagedClusterIdentityProvider = cmd.get_models('OpenShiftManagedClusterIdentityProvider', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') + OpenShiftManagedCluster = cmd.get_models('OpenShiftManagedCluster', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') + OpenShiftRouterProfile = cmd.get_models('OpenShiftRouterProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') + NetworkProfile = cmd.get_models('NetworkProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') + OpenShiftManagedClusterAuthProfile = cmd.get_models('OpenShiftManagedClusterAuthProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') + OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') logger.warning('Support for the creation of ARO 3.11 clusters ends 30 Nov 2020. Please see aka.ms/aro/4 for information on switching to ARO 4.') # pylint: disable=line-too-long if location is None: @@ -4467,7 +4468,7 @@ def openshift_scale(cmd, client, resource_group_name, name, compute_count, no_wa def openshift_monitor_enable(cmd, client, resource_group_name, name, workspace_id, no_wait=False): - OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile',resource_type=ResourceType.MGMT_CONTAINERSERVICE) + OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') logger.warning('The az openshift command is deprecated and has been replaced by az aro for ARO 4 clusters. See http://aka.ms/aro/4 for information on switching to ARO 4.') # pylint: disable=line-too-long instance = client.get(resource_group_name, name) @@ -4480,7 +4481,7 @@ def openshift_monitor_enable(cmd, client, resource_group_name, name, workspace_i def openshift_monitor_disable(cmd, client, resource_group_name, name, no_wait=False): - OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile',resource_type=ResourceType.MGMT_CONTAINERSERVICE) + OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') logger.warning('The az openshift command is deprecated and has been replaced by az aro for ARO 4 clusters. See http://aka.ms/aro/4 for information on switching to ARO 4.') # pylint: disable=line-too-long instance = client.get(resource_group_name, name) From 19ac1f2d4e92ff8e424670d7aeacc9cab37b3187 Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Thu, 27 May 2021 17:12:05 -0700 Subject: [PATCH 06/29] Removing versioned models import --- src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py b/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py index 6bf4dd5099f..f91725798a4 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py @@ -7,7 +7,6 @@ # pylint: disable=no-name-in-module,import-error from azure.cli.core.profiles import ResourceType -from azure.mgmt.containerservice.v2021_03_01.models import ResourceReference from knack.log import get_logger From ae844d4e60cb75698d6aee7df7c831374a49555e Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Fri, 28 May 2021 01:32:41 -0700 Subject: [PATCH 07/29] Fixing style and models --- .../azure/cli/command_modules/acs/_helpers.py | 7 +- .../cli/command_modules/acs/_loadbalancer.py | 22 +-- .../azure/cli/command_modules/acs/_params.py | 2 +- .../cli/command_modules/acs/_validators.py | 3 +- .../azure/cli/command_modules/acs/commands.py | 5 +- .../azure/cli/command_modules/acs/custom.py | 141 +++++++++++++----- 6 files changed, 129 insertions(+), 51 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/_helpers.py index a945b87e261..b3196aa153b 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_helpers.py @@ -10,9 +10,12 @@ from ._consts import CONST_OUTBOUND_TYPE_LOAD_BALANCER, CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING -def _populate_api_server_access_profile(cmd, api_server_authorized_ip_ranges, enable_private_cluster=False, instance=None): +def _populate_api_server_access_profile(cmd, + api_server_authorized_ip_ranges, + enable_private_cluster=False, instance=None): if instance is None or instance.api_server_access_profile is None: - ManagedClusterAPIServerAccessProfile = cmd.get_models('ManagedClusterAPIServerAccessProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterAPIServerAccessProfile = cmd.get_models('ManagedClusterAPIServerAccessProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE) profile = ManagedClusterAPIServerAccessProfile() else: profile = instance.api_server_access_profile diff --git a/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py b/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py index f91725798a4..e5c3c7632e0 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py @@ -24,13 +24,13 @@ def set_load_balancer_sku(sku, kubernetes_version): return "standard" -def update_load_balancer_profile(managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, +def update_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, outbound_ports, idle_timeout, profile): """parse and update an existing load balancer profile""" if not is_load_balancer_profile_provided(managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, outbound_ports, idle_timeout): return profile - return configure_load_balancer_profile(managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, + return configure_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, outbound_ports, idle_timeout, profile) @@ -41,9 +41,10 @@ def create_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, o outbound_ports, idle_timeout): return None - ManagedClusterLoadBalancerProfile = cmd.get_models('ManagedClusterLoadBalancerProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterLoadBalancerProfile = cmd.get_models('ManagedClusterLoadBalancerProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE) profile = ManagedClusterLoadBalancerProfile() - return configure_load_balancer_profile(managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, + return configure_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, outbound_ports, idle_timeout, profile) @@ -53,26 +54,29 @@ def configure_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips if not profile: return profile - outbound_ip_resources = _get_load_balancer_outbound_ips(outbound_ips) + outbound_ip_resources = _get_load_balancer_outbound_ips(cmd, outbound_ips) outbound_ip_prefix_resources = _get_load_balancer_outbound_ip_prefixes( - outbound_ip_prefixes) + cmd, outbound_ip_prefixes) if managed_outbound_ip_count or outbound_ip_resources or outbound_ip_prefix_resources: profile.managed_outbound_ips = None profile.outbound_ips = None profile.outbound_ip_prefixes = None if managed_outbound_ip_count: - ManagedClusterLoadBalancerProfileManagedOutboundIPs = cmd.get_models('ManagedClusterLoadBalancerProfileManagedOutboundIPs', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterLoadBalancerProfileManagedOutboundIPs = cmd.get_models( + 'ManagedClusterLoadBalancerProfileManagedOutboundIPs', resource_type=ResourceType.MGMT_CONTAINERSERVICE) profile.managed_outbound_ips = ManagedClusterLoadBalancerProfileManagedOutboundIPs( count=managed_outbound_ip_count ) if outbound_ip_resources: - ManagedClusterLoadBalancerProfileOutboundIPs = cmd.get_models('ManagedClusterLoadBalancerProfileOutboundIPs', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterLoadBalancerProfileOutboundIPs = cmd.get_models( + 'ManagedClusterLoadBalancerProfileOutboundIPs', resource_type=ResourceType.MGMT_CONTAINERSERVICE) profile.outbound_ips = ManagedClusterLoadBalancerProfileOutboundIPs( public_ips=outbound_ip_resources ) if outbound_ip_prefix_resources: - ManagedClusterLoadBalancerProfileOutboundIPPrefixes = cmd.get_models('ManagedClusterLoadBalancerProfileOutboundIPPrefixes', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterLoadBalancerProfileOutboundIPPrefixes = cmd.get_models( + 'ManagedClusterLoadBalancerProfileOutboundIPPrefixes', resource_type=ResourceType.MGMT_CONTAINERSERVICE) profile.outbound_ip_prefixes = ManagedClusterLoadBalancerProfileOutboundIPPrefixes( public_ip_prefixes=outbound_ip_prefix_resources ) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_params.py b/src/azure-cli/azure/cli/command_modules/acs/_params.py index 82c7b5cdf95..a8149fe83a7 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_params.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_params.py @@ -12,8 +12,8 @@ from azure.cli.core.commands.parameters import ( file_type, get_enum_type, get_resource_name_completion_list, name_type, tags_type, zones_type) from azure.cli.core.commands.validators import validate_file_or_dict -from knack.arguments import CLIArgumentType from azure.cli.core.profiles import ResourceType +from knack.arguments import CLIArgumentType from ._completers import ( get_vm_size_completion_list, get_k8s_versions_completion_list, get_k8s_upgrades_completion_list) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_validators.py b/src/azure-cli/azure/cli/command_modules/acs/_validators.py index cf4ce0cd47b..91d63ca02e1 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_validators.py @@ -122,7 +122,8 @@ def validate_cluster_autoscaler_profile(namespace): def _validate_cluster_autoscaler_key(cmd, key): if not key: raise CLIError('Empty key specified for cluster-autoscaler-profile') - ManagedClusterPropertiesAutoScalerProfile = cmd.get_models('ManagedClusterPropertiesAutoScalerProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterPropertiesAutoScalerProfile = cmd.get_models('ManagedClusterPropertiesAutoScalerProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE) valid_keys = list(k.replace("_", "-") for k, v in ManagedClusterPropertiesAutoScalerProfile._attribute_map.items()) # pylint: disable=protected-access if key not in valid_keys: raise CLIError("'{0}' is an invalid key for cluster-autoscaler-profile. " diff --git a/src/azure-cli/azure/cli/command_modules/acs/commands.py b/src/azure-cli/azure/cli/command_modules/acs/commands.py index e0d37dfacd9..0c27948759b 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/commands.py +++ b/src/azure-cli/azure/cli/command_modules/acs/commands.py @@ -123,7 +123,10 @@ def load_command_table(self, _): table_transformer=aks_versions_table_format) # AKS agent pool commands - with self.command_group('aks nodepool', agent_pools_sdk, client_factory=cf_agent_pools, operation_group='agent_pools') as g: + with self.command_group('aks nodepool', + agent_pools_sdk, + client_factory=cf_agent_pools, + operation_group='agent_pools') as g: g.custom_command('list', 'aks_agentpool_list', table_transformer=aks_agentpool_list_table_format) g.custom_show_command('show', 'aks_agentpool_show', 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 ba70cf08ccb..80b4ee91dbe 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/custom.py @@ -1043,8 +1043,6 @@ def load_service_principals(config_path): def _invoke_deployment(cmd, resource_group_name, deployment_name, template, parameters, validate, no_wait, subscription_id=None): - - from azure.cli.core.profiles import ResourceType DeploymentProperties = cmd.get_models( 'DeploymentProperties', resource_type=ResourceType.MGMT_RESOURCE_RESOURCES) properties = DeploymentProperties( @@ -1425,7 +1423,7 @@ def create_role_assignment(cli_ctx, role, assignee, is_service_principal, resour def _create_role_assignment(cli_ctx, role, assignee, resource_group_name=None, scope=None, resolve_assignee=True): - from azure.cli.core.profiles import ResourceType, get_sdk + from azure.cli.core.profiles import get_sdk factory = get_auth_management_client(cli_ctx, scope) assignments_client = factory.role_assignments definitions_client = factory.role_definitions @@ -1625,7 +1623,9 @@ def aks_check_acr(cmd, client, resource_group_name, name, acr): # pylint: disable=too-many-statements,too-many-branches def aks_browse(cmd, client, resource_group_name, name, disable_browser=False, listen_address='127.0.0.1', listen_port='8001'): - ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') + ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') # verify the kube-dashboard addon was not disabled instance = client.get(resource_group_name, name) addon_profiles = instance.addon_profiles or {} @@ -1960,18 +1960,43 @@ def aks_create(cmd, client, resource_group_name, name, ssh_key_value, # pylint: no_wait=False, yes=False, enable_azure_rbac=False): - ManagedClusterIdentityUserAssignedIdentitiesValue = cmd.get_models('ManagedClusterIdentityUserAssignedIdentitiesValue', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') - ManagedClusterWindowsProfile = cmd.get_models('ManagedClusterWindowsProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') - ManagedClusterSKU = cmd.get_models('ManagedClusterSKU', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') - ContainerServiceNetworkProfile = cmd.get_models('ContainerServiceNetworkProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='container_services') - ContainerServiceLinuxProfile = cmd.get_models('ContainerServiceLinuxProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='container_services') - ManagedClusterServicePrincipalProfile = cmd.get_models('ManagedClusterServicePrincipalProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') - ContainerServiceSshConfiguration = cmd.get_models('ContainerServiceSshConfiguration', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='container_services') - ContainerServiceSshPublicKey = cmd.get_models('ContainerServiceSshPublicKey', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='container_services') - ManagedClusterAADProfile = cmd.get_models('ManagedClusterAADProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') - ManagedClusterAgentPoolProfile = cmd.get_models('ManagedClusterAgentPoolProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') - ManagedClusterIdentity = cmd.get_models('ManagedClusterIdentity', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') - ManagedCluster = cmd.get_models('ManagedCluster', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') + ManagedClusterIdentityUserAssignedIdentitiesValue = cmd.get_models( + 'ManagedClusterIdentityUserAssignedIdentitiesValue', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') + ManagedClusterWindowsProfile = cmd.get_models('ManagedClusterWindowsProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') + ManagedClusterSKU = cmd.get_models('ManagedClusterSKU', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') + ContainerServiceNetworkProfile = cmd.get_models('ContainerServiceNetworkProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='container_services') + ContainerServiceLinuxProfile = cmd.get_models('ContainerServiceLinuxProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='container_services') + ManagedClusterServicePrincipalProfile = cmd.get_models('ManagedClusterServicePrincipalProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') + ContainerServiceSshConfiguration = cmd.get_models('ContainerServiceSshConfiguration', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='container_services') + ContainerServiceSshPublicKey = cmd.get_models('ContainerServiceSshPublicKey', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='container_services') + ManagedClusterAADProfile = cmd.get_models('ManagedClusterAADProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') + ManagedClusterAgentPoolProfile = cmd.get_models('ManagedClusterAgentPoolProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') + ManagedClusterIdentity = cmd.get_models('ManagedClusterIdentity', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') + ManagedCluster = cmd.get_models('ManagedCluster', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') _validate_ssh_key(no_ssh_key, ssh_key_value) subscription_id = get_subscription_id(cmd.cli_ctx) @@ -2112,6 +2137,7 @@ def aks_create(cmd, client, resource_group_name, name, ssh_key_value, # pylint: 'Are you an Owner on this subscription?') load_balancer_profile = create_load_balancer_profile( + cmd, load_balancer_managed_outbound_ip_count, load_balancer_outbound_ips, load_balancer_outbound_ip_prefixes, @@ -2565,10 +2591,19 @@ def aks_update(cmd, client, resource_group_name, name, no_wait=False, enable_azure_rbac=False, disable_azure_rbac=False): - ManagedClusterIdentityUserAssignedIdentitiesValue = cmd.get_models('ManagedClusterIdentityUserAssignedIdentitiesValue', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') - ManagedClusterSKU = cmd.get_models('ManagedClusterSKU', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') - ManagedClusterAADProfile = cmd.get_models('ManagedClusterAADProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') - ManagedClusterIdentity = cmd.get_models('ManagedClusterIdentity', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') + ManagedClusterIdentityUserAssignedIdentitiesValue = cmd.get_models( + 'ManagedClusterIdentityUserAssignedIdentitiesValue', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') + ManagedClusterSKU = cmd.get_models('ManagedClusterSKU', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') + ManagedClusterAADProfile = cmd.get_models('ManagedClusterAADProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') + ManagedClusterIdentity = cmd.get_models('ManagedClusterIdentity', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') update_autoscaler = enable_cluster_autoscaler + \ disable_cluster_autoscaler + update_cluster_autoscaler update_lb_profile = is_load_balancer_profile_provided(load_balancer_managed_outbound_ip_count, @@ -2714,6 +2749,7 @@ def aks_update(cmd, client, resource_group_name, name, if update_lb_profile: instance.network_profile.load_balancer_profile = update_load_balancer_profile( + cmd, load_balancer_managed_outbound_ip_count, load_balancer_outbound_ips, load_balancer_outbound_ip_prefixes, @@ -3119,7 +3155,9 @@ def _update_addons(cmd, instance, subscription_id, resource_group_name, name, ad appgw_watch_namespace=None, enable_sgxquotehelper=False, no_wait=False): - ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') + ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') # parse the comma-separated addons argument addon_args = addons.split(',') @@ -3246,7 +3284,9 @@ def _handle_addons_args(cmd, addons_str, subscription_id, resource_group_name, a appgw_subnet_id=None, appgw_watch_namespace=None, enable_sgxquotehelper=False): - ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') + ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') if not addon_profiles: addon_profiles = {} addons = addons_str.split(',') if addons_str else [] @@ -3533,7 +3573,6 @@ def _ensure_default_log_analytics_workspace_for_monitoring(cmd, subscription_id, resource_groups.create_or_update(default_workspace_resource_group, { 'location': workspace_region}) - from azure.cli.core.profiles import ResourceType GenericResource = cmd.get_models( 'GenericResource', resource_type=ResourceType.MGMT_RESOURCE_RESOURCES) generic_resource = GenericResource(location=workspace_region, properties={ @@ -3743,8 +3782,12 @@ def aks_agentpool_add(cmd, client, resource_group_name, cluster_name, nodepool_n mode="User", enable_encryption_at_host=False, no_wait=False): - AgentPool = cmd.get_models('AgentPool', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='agent_pools') - AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='agent_pools') + AgentPool = cmd.get_models('AgentPool', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='agent_pools') + AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='agent_pools') instances = client.list(resource_group_name, cluster_name) for agentpool_profile in instances: if agentpool_profile.name == nodepool_name: @@ -3866,7 +3909,9 @@ def aks_agentpool_update(cmd, client, resource_group_name, cluster_name, nodepoo max_surge=None, mode=None, no_wait=False): - AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='agent_pools') + AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='agent_pools') update_autoscaler = enable_cluster_autoscaler + \ disable_cluster_autoscaler + update_cluster_autoscaler @@ -4020,7 +4065,9 @@ def _ensure_osa_aad(cmd, identifier=None, name=None, create=False, customer_admin_group_id=None): - OpenShiftManagedClusterAADIdentityProvider = cmd.get_models('OpenShiftManagedClusterAADIdentityProvider', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') + OpenShiftManagedClusterAADIdentityProvider = cmd.get_models('OpenShiftManagedClusterAADIdentityProvider', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') rbac_client = get_graph_rbac_management_client(cli_ctx) if create: # This reply_url is temporary set since Azure need one to create the AAD. @@ -4318,14 +4365,30 @@ def openshift_create(cmd, client, resource_group_name, name, # pylint: disable= no_wait=False, workspace_id=None, customer_admin_group_id=None): - OpenShiftManagedClusterAgentPoolProfile = cmd.get_models('OpenShiftManagedClusterAgentPoolProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') - OpenShiftAgentPoolProfileRole = cmd.get_models('OpenShiftAgentPoolProfileRole', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') - OpenShiftManagedClusterIdentityProvider = cmd.get_models('OpenShiftManagedClusterIdentityProvider', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') - OpenShiftManagedCluster = cmd.get_models('OpenShiftManagedCluster', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') - OpenShiftRouterProfile = cmd.get_models('OpenShiftRouterProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') - NetworkProfile = cmd.get_models('NetworkProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') - OpenShiftManagedClusterAuthProfile = cmd.get_models('OpenShiftManagedClusterAuthProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') - OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') + OpenShiftManagedClusterAgentPoolProfile = cmd.get_models('OpenShiftManagedClusterAgentPoolProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') + OpenShiftAgentPoolProfileRole = cmd.get_models('OpenShiftAgentPoolProfileRole', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') + OpenShiftManagedClusterIdentityProvider = cmd.get_models('OpenShiftManagedClusterIdentityProvider', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') + OpenShiftManagedCluster = cmd.get_models('OpenShiftManagedCluster', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') + OpenShiftRouterProfile = cmd.get_models('OpenShiftRouterProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') + NetworkProfile = cmd.get_models('NetworkProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') + OpenShiftManagedClusterAuthProfile = cmd.get_models('OpenShiftManagedClusterAuthProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') + OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') logger.warning('Support for the creation of ARO 3.11 clusters ends 30 Nov 2020. Please see aka.ms/aro/4 for information on switching to ARO 4.') # pylint: disable=line-too-long if location is None: @@ -4468,7 +4531,9 @@ def openshift_scale(cmd, client, resource_group_name, name, compute_count, no_wa def openshift_monitor_enable(cmd, client, resource_group_name, name, workspace_id, no_wait=False): - OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') + OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') logger.warning('The az openshift command is deprecated and has been replaced by az aro for ARO 4 clusters. See http://aka.ms/aro/4 for information on switching to ARO 4.') # pylint: disable=line-too-long instance = client.get(resource_group_name, name) @@ -4481,7 +4546,9 @@ def openshift_monitor_enable(cmd, client, resource_group_name, name, workspace_i def openshift_monitor_disable(cmd, client, resource_group_name, name, no_wait=False): - OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') + OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') logger.warning('The az openshift command is deprecated and has been replaced by az aro for ARO 4 clusters. See http://aka.ms/aro/4 for information on switching to ARO 4.') # pylint: disable=line-too-long instance = client.get(resource_group_name, name) From f76fc0c868a6a76438a6b617cbbf4dc46faf515c Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Fri, 28 May 2021 16:43:18 -0700 Subject: [PATCH 08/29] Changing Azure stack API version for container service --- .../azure/cli/core/profiles/_shared.py | 2 +- .../cli/command_modules/acs/_validators.py | 2 +- .../azure/cli/command_modules/acs/commands.py | 11 +- .../azure/cli/command_modules/acs/custom.py | 101 ++++++------------ 4 files changed, 37 insertions(+), 79 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/profiles/_shared.py b/src/azure-cli-core/azure/cli/core/profiles/_shared.py index a30e083d74e..63387866e4e 100644 --- a/src/azure-cli-core/azure/cli/core/profiles/_shared.py +++ b/src/azure-cli-core/azure/cli/core/profiles/_shared.py @@ -256,7 +256,7 @@ def default_api_version(self): ResourceType.MGMT_IOTHUB: '2019-07-01-preview', ResourceType.MGMT_DATABOXEDGE: '2019-08-01', ResourceType.MGMT_CONTAINERREGISTRY: '2019-05-01', - ResourceType.MGMT_CONTAINERSERVICE: SDKProfile('2020-03-01', { + ResourceType.MGMT_CONTAINERSERVICE: SDKProfile('2020-11-01', { 'container_services': '2017-07-01', 'open_shift_managed_clusters': '2019-10-27-preview' }) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_validators.py b/src/azure-cli/azure/cli/command_modules/acs/_validators.py index 91d63ca02e1..67f8dc9a3c8 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_validators.py @@ -116,7 +116,7 @@ def validate_cluster_autoscaler_profile(namespace): _extract_cluster_autoscaler_params(namespace) if namespace.cluster_autoscaler_profile is not None: for key in namespace.cluster_autoscaler_profile.keys(): - _validate_cluster_autoscaler_key(key) + _validate_cluster_autoscaler_key(cmd, key) def _validate_cluster_autoscaler_key(cmd, key): diff --git a/src/azure-cli/azure/cli/command_modules/acs/commands.py b/src/azure-cli/azure/cli/command_modules/acs/commands.py index 0c27948759b..8fd8b65ab6b 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/commands.py +++ b/src/azure-cli/azure/cli/command_modules/acs/commands.py @@ -28,31 +28,24 @@ def load_command_table(self, _): container_services_sdk = CliCommandType( operations_tmpl='azure.mgmt.containerservice.operations.' '_container_services_operations#ContainerServicesOperations.{}', - operation_group='container_services', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, client_factory=cf_container_services ) managed_clusters_sdk = CliCommandType( operations_tmpl='azure.mgmt.containerservice.operations.' '_managed_clusters_operations#ManagedClustersOperations.{}', - operation_group='managed_clusters', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, client_factory=cf_managed_clusters ) agent_pools_sdk = CliCommandType( operations_tmpl='azext_aks_preview.vendored_sdks.azure_mgmt_preview_aks.' 'operations._agent_pools_operations#AgentPoolsOperations.{}', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, client_factory=cf_managed_clusters ) openshift_managed_clusters_sdk = CliCommandType( operations_tmpl='azure.mgmt.containerservice.operations.' '_open_shift_managed_clusters_operations#OpenShiftManagedClustersOperations.{}', - operation_group='open_shift_managed_clusters', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, client_factory=cf_openshift_managed_clusters ) @@ -125,8 +118,7 @@ def load_command_table(self, _): # AKS agent pool commands with self.command_group('aks nodepool', agent_pools_sdk, - client_factory=cf_agent_pools, - operation_group='agent_pools') as g: + client_factory=cf_agent_pools) as g: g.custom_command('list', 'aks_agentpool_list', table_transformer=aks_agentpool_list_table_format) g.custom_show_command('show', 'aks_agentpool_show', @@ -150,7 +142,6 @@ def load_command_table(self, _): # OSA commands with self.command_group('openshift', openshift_managed_clusters_sdk, client_factory=cf_openshift_managed_clusters, - operation_group='open_shift_managed_clusters', deprecate_info=self.deprecate(redirect='aro', hide=True)) as g: g.custom_command('create', 'openshift_create', supports_no_wait=True) g.command('delete', 'delete', supports_no_wait=True, confirmation=True) 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 80b4ee91dbe..39cd9bf1395 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/custom.py @@ -1624,8 +1624,7 @@ def aks_check_acr(cmd, client, resource_group_name, name, acr): def aks_browse(cmd, client, resource_group_name, name, disable_browser=False, listen_address='127.0.0.1', listen_port='8001'): ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) # verify the kube-dashboard addon was not disabled instance = client.get(resource_group_name, name) addon_profiles = instance.addon_profiles or {} @@ -1962,41 +1961,29 @@ def aks_create(cmd, client, resource_group_name, name, ssh_key_value, # pylint: enable_azure_rbac=False): ManagedClusterIdentityUserAssignedIdentitiesValue = cmd.get_models( 'ManagedClusterIdentityUserAssignedIdentitiesValue', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) ManagedClusterWindowsProfile = cmd.get_models('ManagedClusterWindowsProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) ManagedClusterSKU = cmd.get_models('ManagedClusterSKU', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) ContainerServiceNetworkProfile = cmd.get_models('ContainerServiceNetworkProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='container_services') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) ContainerServiceLinuxProfile = cmd.get_models('ContainerServiceLinuxProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='container_services') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) ManagedClusterServicePrincipalProfile = cmd.get_models('ManagedClusterServicePrincipalProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) ContainerServiceSshConfiguration = cmd.get_models('ContainerServiceSshConfiguration', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='container_services') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) ContainerServiceSshPublicKey = cmd.get_models('ContainerServiceSshPublicKey', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='container_services') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) ManagedClusterAADProfile = cmd.get_models('ManagedClusterAADProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) ManagedClusterAgentPoolProfile = cmd.get_models('ManagedClusterAgentPoolProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) ManagedClusterIdentity = cmd.get_models('ManagedClusterIdentity', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) ManagedCluster = cmd.get_models('ManagedCluster', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) _validate_ssh_key(no_ssh_key, ssh_key_value) subscription_id = get_subscription_id(cmd.cli_ctx) @@ -2593,17 +2580,13 @@ def aks_update(cmd, client, resource_group_name, name, disable_azure_rbac=False): ManagedClusterIdentityUserAssignedIdentitiesValue = cmd.get_models( 'ManagedClusterIdentityUserAssignedIdentitiesValue', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) ManagedClusterSKU = cmd.get_models('ManagedClusterSKU', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) ManagedClusterAADProfile = cmd.get_models('ManagedClusterAADProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) ManagedClusterIdentity = cmd.get_models('ManagedClusterIdentity', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) update_autoscaler = enable_cluster_autoscaler + \ disable_cluster_autoscaler + update_cluster_autoscaler update_lb_profile = is_load_balancer_profile_provided(load_balancer_managed_outbound_ip_count, @@ -3156,8 +3139,7 @@ def _update_addons(cmd, instance, subscription_id, resource_group_name, name, ad enable_sgxquotehelper=False, no_wait=False): ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) # parse the comma-separated addons argument addon_args = addons.split(',') @@ -3285,8 +3267,7 @@ def _handle_addons_args(cmd, addons_str, subscription_id, resource_group_name, a appgw_watch_namespace=None, enable_sgxquotehelper=False): ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) if not addon_profiles: addon_profiles = {} addons = addons_str.split(',') if addons_str else [] @@ -3783,11 +3764,9 @@ def aks_agentpool_add(cmd, client, resource_group_name, cluster_name, nodepool_n enable_encryption_at_host=False, no_wait=False): AgentPool = cmd.get_models('AgentPool', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='agent_pools') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='agent_pools') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) instances = client.list(resource_group_name, cluster_name) for agentpool_profile in instances: if agentpool_profile.name == nodepool_name: @@ -3876,7 +3855,7 @@ def aks_agentpool_upgrade(cmd, client, resource_group_name, cluster_name, node_image_only=False, max_surge=None, no_wait=False): - AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings', operation_group='agent_pools') + AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings') if kubernetes_version != '' and node_image_only: raise CLIError('Conflicting flags. Upgrading the Kubernetes version will also upgrade node image version.' 'If you only want to upgrade the node version please use the "--node-image-only" option only.') @@ -3910,8 +3889,7 @@ def aks_agentpool_update(cmd, client, resource_group_name, cluster_name, nodepoo mode=None, no_wait=False): AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='agent_pools') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) update_autoscaler = enable_cluster_autoscaler + \ disable_cluster_autoscaler + update_cluster_autoscaler @@ -4066,8 +4044,7 @@ def _ensure_osa_aad(cmd, name=None, create=False, customer_admin_group_id=None): OpenShiftManagedClusterAADIdentityProvider = cmd.get_models('OpenShiftManagedClusterAADIdentityProvider', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='open_shift_managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) rbac_client = get_graph_rbac_management_client(cli_ctx) if create: # This reply_url is temporary set since Azure need one to create the AAD. @@ -4366,29 +4343,21 @@ def openshift_create(cmd, client, resource_group_name, name, # pylint: disable= workspace_id=None, customer_admin_group_id=None): OpenShiftManagedClusterAgentPoolProfile = cmd.get_models('OpenShiftManagedClusterAgentPoolProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='open_shift_managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) OpenShiftAgentPoolProfileRole = cmd.get_models('OpenShiftAgentPoolProfileRole', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='open_shift_managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) OpenShiftManagedClusterIdentityProvider = cmd.get_models('OpenShiftManagedClusterIdentityProvider', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='open_shift_managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) OpenShiftManagedCluster = cmd.get_models('OpenShiftManagedCluster', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='open_shift_managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) OpenShiftRouterProfile = cmd.get_models('OpenShiftRouterProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='open_shift_managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) NetworkProfile = cmd.get_models('NetworkProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='open_shift_managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) OpenShiftManagedClusterAuthProfile = cmd.get_models('OpenShiftManagedClusterAuthProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='open_shift_managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='open_shift_managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) logger.warning('Support for the creation of ARO 3.11 clusters ends 30 Nov 2020. Please see aka.ms/aro/4 for information on switching to ARO 4.') # pylint: disable=line-too-long if location is None: @@ -4532,8 +4501,7 @@ def openshift_scale(cmd, client, resource_group_name, name, compute_count, no_wa def openshift_monitor_enable(cmd, client, resource_group_name, name, workspace_id, no_wait=False): OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='open_shift_managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) logger.warning('The az openshift command is deprecated and has been replaced by az aro for ARO 4 clusters. See http://aka.ms/aro/4 for information on switching to ARO 4.') # pylint: disable=line-too-long instance = client.get(resource_group_name, name) @@ -4547,8 +4515,7 @@ def openshift_monitor_enable(cmd, client, resource_group_name, name, workspace_i def openshift_monitor_disable(cmd, client, resource_group_name, name, no_wait=False): OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='open_shift_managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) logger.warning('The az openshift command is deprecated and has been replaced by az aro for ARO 4 clusters. See http://aka.ms/aro/4 for information on switching to ARO 4.') # pylint: disable=line-too-long instance = client.get(resource_group_name, name) From bba1cd3e7fa03bc14eaeabaccd80f5d603065431 Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Tue, 1 Jun 2021 14:48:26 -0700 Subject: [PATCH 09/29] Adding operation-group to container service --- .../cli/command_modules/acs/_validators.py | 2 +- .../azure/cli/command_modules/acs/commands.py | 16 ++- .../azure/cli/command_modules/acs/custom.py | 102 ++++++++++++------ 3 files changed, 81 insertions(+), 39 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_validators.py b/src/azure-cli/azure/cli/command_modules/acs/_validators.py index 67f8dc9a3c8..9a23aaba7eb 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_validators.py @@ -107,7 +107,7 @@ def validate_k8s_version(namespace): 'such as "1.11.8" or "1.12.6"') -def validate_cluster_autoscaler_profile(namespace): +def validate_cluster_autoscaler_profile(cmd, namespace): """ Validates that cluster autoscaler profile is acceptable by: 1. Extracting the key[=value] format to map 2. Validating that the key isn't empty and that the key is valid diff --git a/src/azure-cli/azure/cli/command_modules/acs/commands.py b/src/azure-cli/azure/cli/command_modules/acs/commands.py index 8fd8b65ab6b..cca1a61fed9 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/commands.py +++ b/src/azure-cli/azure/cli/command_modules/acs/commands.py @@ -28,24 +28,31 @@ def load_command_table(self, _): container_services_sdk = CliCommandType( operations_tmpl='azure.mgmt.containerservice.operations.' '_container_services_operations#ContainerServicesOperations.{}', + operation_group='container_services', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, client_factory=cf_container_services ) managed_clusters_sdk = CliCommandType( operations_tmpl='azure.mgmt.containerservice.operations.' '_managed_clusters_operations#ManagedClustersOperations.{}', + operation_group='managed_clusters', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, client_factory=cf_managed_clusters ) agent_pools_sdk = CliCommandType( operations_tmpl='azext_aks_preview.vendored_sdks.azure_mgmt_preview_aks.' 'operations._agent_pools_operations#AgentPoolsOperations.{}', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, client_factory=cf_managed_clusters ) openshift_managed_clusters_sdk = CliCommandType( operations_tmpl='azure.mgmt.containerservice.operations.' '_open_shift_managed_clusters_operations#OpenShiftManagedClustersOperations.{}', + operation_group='open_shift_managed_clusters', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, client_factory=cf_openshift_managed_clusters ) @@ -72,13 +79,16 @@ def load_command_table(self, _): client_factory=None) # ACS Kubernetes commands - with self.command_group('acs kubernetes', container_services_sdk, client_factory=cf_container_services) as g: + with self.command_group('acs kubernetes', container_services_sdk, + resource_type=ResourceType.MGMT_CONTAINERSERVICE, client_factory=cf_container_services) as g: g.custom_command('browse', 'k8s_browse') g.custom_command('get-credentials', 'k8s_get_credentials') g.custom_command('install-cli', 'k8s_install_cli', client_factory=None) # AKS commands - with self.command_group('aks', managed_clusters_sdk, client_factory=cf_managed_clusters) as g: + with self.command_group('aks', managed_clusters_sdk, + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters', client_factory=cf_managed_clusters) as g: g.custom_command('browse', 'aks_browse') g.custom_command('create', 'aks_create', supports_no_wait=True) g.custom_command('update', 'aks_update', supports_no_wait=True) @@ -107,7 +117,7 @@ def load_command_table(self, _): g.custom_command('rotate-certs', 'aks_rotate_certs', supports_no_wait=True, confirmation='Kubernetes will be unavailable during certificate rotation process.\n' + 'Are you sure you want to perform this operation?') - g.wait_command('wait') + g.wait_command('wait', operation_group='managed_clusters') g.command('stop', 'stop', supports_no_wait=True, min_api='2020-09-01', client_factory=cf_managed_clusters) g.command('start', 'start', supports_no_wait=True, min_api='2020-09-01', client_factory=cf_managed_clusters) 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 39cd9bf1395..e546b53c787 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/custom.py @@ -1624,7 +1624,8 @@ def aks_check_acr(cmd, client, resource_group_name, name, acr): def aks_browse(cmd, client, resource_group_name, name, disable_browser=False, listen_address='127.0.0.1', listen_port='8001'): ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') # verify the kube-dashboard addon was not disabled instance = client.get(resource_group_name, name) addon_profiles = instance.addon_profiles or {} @@ -1961,29 +1962,41 @@ def aks_create(cmd, client, resource_group_name, name, ssh_key_value, # pylint: enable_azure_rbac=False): ManagedClusterIdentityUserAssignedIdentitiesValue = cmd.get_models( 'ManagedClusterIdentityUserAssignedIdentitiesValue', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') ManagedClusterWindowsProfile = cmd.get_models('ManagedClusterWindowsProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') ManagedClusterSKU = cmd.get_models('ManagedClusterSKU', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') ContainerServiceNetworkProfile = cmd.get_models('ContainerServiceNetworkProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='container_services') ContainerServiceLinuxProfile = cmd.get_models('ContainerServiceLinuxProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='container_services') ManagedClusterServicePrincipalProfile = cmd.get_models('ManagedClusterServicePrincipalProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') ContainerServiceSshConfiguration = cmd.get_models('ContainerServiceSshConfiguration', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='container_services') ContainerServiceSshPublicKey = cmd.get_models('ContainerServiceSshPublicKey', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='container_services') ManagedClusterAADProfile = cmd.get_models('ManagedClusterAADProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') ManagedClusterAgentPoolProfile = cmd.get_models('ManagedClusterAgentPoolProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') ManagedClusterIdentity = cmd.get_models('ManagedClusterIdentity', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') ManagedCluster = cmd.get_models('ManagedCluster', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') _validate_ssh_key(no_ssh_key, ssh_key_value) subscription_id = get_subscription_id(cmd.cli_ctx) @@ -2580,13 +2593,17 @@ def aks_update(cmd, client, resource_group_name, name, disable_azure_rbac=False): ManagedClusterIdentityUserAssignedIdentitiesValue = cmd.get_models( 'ManagedClusterIdentityUserAssignedIdentitiesValue', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') ManagedClusterSKU = cmd.get_models('ManagedClusterSKU', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') ManagedClusterAADProfile = cmd.get_models('ManagedClusterAADProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') ManagedClusterIdentity = cmd.get_models('ManagedClusterIdentity', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') update_autoscaler = enable_cluster_autoscaler + \ disable_cluster_autoscaler + update_cluster_autoscaler update_lb_profile = is_load_balancer_profile_provided(load_balancer_managed_outbound_ip_count, @@ -3139,7 +3156,8 @@ def _update_addons(cmd, instance, subscription_id, resource_group_name, name, ad enable_sgxquotehelper=False, no_wait=False): ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') # parse the comma-separated addons argument addon_args = addons.split(',') @@ -3267,7 +3285,8 @@ def _handle_addons_args(cmd, addons_str, subscription_id, resource_group_name, a appgw_watch_namespace=None, enable_sgxquotehelper=False): ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') if not addon_profiles: addon_profiles = {} addons = addons_str.split(',') if addons_str else [] @@ -3553,7 +3572,6 @@ def _ensure_default_log_analytics_workspace_for_monitoring(cmd, subscription_id, else: resource_groups.create_or_update(default_workspace_resource_group, { 'location': workspace_region}) - GenericResource = cmd.get_models( 'GenericResource', resource_type=ResourceType.MGMT_RESOURCE_RESOURCES) generic_resource = GenericResource(location=workspace_region, properties={ @@ -3764,9 +3782,11 @@ def aks_agentpool_add(cmd, client, resource_group_name, cluster_name, nodepool_n enable_encryption_at_host=False, no_wait=False): AgentPool = cmd.get_models('AgentPool', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='agent_pools') AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='agent_pools') instances = client.list(resource_group_name, cluster_name) for agentpool_profile in instances: if agentpool_profile.name == nodepool_name: @@ -3855,7 +3875,7 @@ def aks_agentpool_upgrade(cmd, client, resource_group_name, cluster_name, node_image_only=False, max_surge=None, no_wait=False): - AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings') + AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings', operation_group='agent_pools') if kubernetes_version != '' and node_image_only: raise CLIError('Conflicting flags. Upgrading the Kubernetes version will also upgrade node image version.' 'If you only want to upgrade the node version please use the "--node-image-only" option only.') @@ -3889,7 +3909,8 @@ def aks_agentpool_update(cmd, client, resource_group_name, cluster_name, nodepoo mode=None, no_wait=False): AgentPoolUpgradeSettings = cmd.get_models('AgentPoolUpgradeSettings', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='agent_pools') update_autoscaler = enable_cluster_autoscaler + \ disable_cluster_autoscaler + update_cluster_autoscaler @@ -4044,7 +4065,8 @@ def _ensure_osa_aad(cmd, name=None, create=False, customer_admin_group_id=None): OpenShiftManagedClusterAADIdentityProvider = cmd.get_models('OpenShiftManagedClusterAADIdentityProvider', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') rbac_client = get_graph_rbac_management_client(cli_ctx) if create: # This reply_url is temporary set since Azure need one to create the AAD. @@ -4343,21 +4365,29 @@ def openshift_create(cmd, client, resource_group_name, name, # pylint: disable= workspace_id=None, customer_admin_group_id=None): OpenShiftManagedClusterAgentPoolProfile = cmd.get_models('OpenShiftManagedClusterAgentPoolProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') OpenShiftAgentPoolProfileRole = cmd.get_models('OpenShiftAgentPoolProfileRole', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') OpenShiftManagedClusterIdentityProvider = cmd.get_models('OpenShiftManagedClusterIdentityProvider', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') OpenShiftManagedCluster = cmd.get_models('OpenShiftManagedCluster', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') OpenShiftRouterProfile = cmd.get_models('OpenShiftRouterProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') NetworkProfile = cmd.get_models('NetworkProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') OpenShiftManagedClusterAuthProfile = cmd.get_models('OpenShiftManagedClusterAuthProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') logger.warning('Support for the creation of ARO 3.11 clusters ends 30 Nov 2020. Please see aka.ms/aro/4 for information on switching to ARO 4.') # pylint: disable=line-too-long if location is None: @@ -4501,7 +4531,8 @@ def openshift_scale(cmd, client, resource_group_name, name, compute_count, no_wa def openshift_monitor_enable(cmd, client, resource_group_name, name, workspace_id, no_wait=False): OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') logger.warning('The az openshift command is deprecated and has been replaced by az aro for ARO 4 clusters. See http://aka.ms/aro/4 for information on switching to ARO 4.') # pylint: disable=line-too-long instance = client.get(resource_group_name, name) @@ -4515,7 +4546,8 @@ def openshift_monitor_enable(cmd, client, resource_group_name, name, workspace_i def openshift_monitor_disable(cmd, client, resource_group_name, name, no_wait=False): OpenShiftManagedClusterMonitorProfile = cmd.get_models('OpenShiftManagedClusterMonitorProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='open_shift_managed_clusters') logger.warning('The az openshift command is deprecated and has been replaced by az aro for ARO 4 clusters. See http://aka.ms/aro/4 for information on switching to ARO 4.') # pylint: disable=line-too-long instance = client.get(resource_group_name, name) From d96d92e3982d57ef79cc4dbc2092df960682a438 Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Tue, 1 Jun 2021 16:55:29 -0700 Subject: [PATCH 10/29] Changing container service test_validator --- .../command_modules/acs/tests/latest/test_custom.py | 4 +++- .../acs/tests/latest/test_loadbalancer.py | 13 ++++++++----- .../acs/tests/latest/test_validators.py | 12 ++++++------ 3 files changed, 17 insertions(+), 12 deletions(-) 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 c85497a75f8..628b1f786b0 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 @@ -25,7 +25,6 @@ from azure.mgmt.containerservice.models import (ContainerServiceOrchestratorTypes, ContainerService, ContainerServiceOrchestratorProfile) -from azure.mgmt.containerservice.v2020_03_01.models import ManagedClusterAddonProfile from azure.cli.core.util import CLIError from azure.cli.command_modules.acs._consts import (CONST_HTTP_APPLICATION_ROUTING_ADDON_NAME, CONST_MONITORING_ADDON_NAME, @@ -661,6 +660,9 @@ def test_update_addons(self, rg_def, cf_resource_groups, cf_resources): # kube-dashboard disabled, there's existing dashboard addon profile instance.addon_profiles.pop(CONST_KUBE_DASHBOARD_ADDON_NAME, None) # test lower cased key name + ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') instance.addon_profiles['kubedashboard'] = ManagedClusterAddonProfile(enabled=True) instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'kube-dashboard', enable=False) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py index 10b6b8b7ebe..74dce670ee6 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py @@ -4,10 +4,6 @@ # -------------------------------------------------------------------------------------------- import unittest -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfile -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfileManagedOutboundIPs -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfileOutboundIPPrefixes -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfileOutboundIPs from azure.cli.core.util import CLIError from azure.cli.command_modules.acs import _loadbalancer as loadbalancer @@ -19,7 +15,14 @@ def test_configure_load_balancer_profile(self): outbound_ip_prefixes = None outbound_ports = 80 idle_timeout = 3600 - + ManagedClusterLoadBalancerProfile = cmd.get_models('ManagedClusterLoadBalancerProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterLoadBalancerProfileManagedOutboundIPs = cmd.get_models( + 'ManagedClusterLoadBalancerProfileManagedOutboundIPs', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterLoadBalancerProfileOutboundIPs = cmd.get_models( + 'ManagedClusterLoadBalancerProfileOutboundIPs', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterLoadBalancerProfileOutboundIPPrefixes = cmd.get_models( + 'ManagedClusterLoadBalancerProfileOutboundIPPrefixes', resource_type=ResourceType.MGMT_CONTAINERSERVICE) profile = ManagedClusterLoadBalancerProfile() profile.managed_outbound_ips = ManagedClusterLoadBalancerProfileManagedOutboundIPs( count=2 diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py index c3ec8d14a60..04fc29cbb32 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py @@ -68,14 +68,14 @@ def test_empty_key_empty_value(self): err = "Empty key specified for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(namespace) + validators.validate_cluster_autoscaler_profile(cmd, namespace) self.assertEqual(str(cm.exception), err) def test_non_empty_key_empty_value(self): cluster_autoscaler_profile = ["scan-interval="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) - validators.validate_cluster_autoscaler_profile(namespace) + validators.validate_cluster_autoscaler_profile(cmd, namespace) def test_two_empty_keys_empty_value(self): cluster_autoscaler_profile = ["=", "="] @@ -83,7 +83,7 @@ def test_two_empty_keys_empty_value(self): err = "Empty key specified for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(namespace) + validators.validate_cluster_autoscaler_profile(cmd, namespace) self.assertEqual(str(cm.exception), err) def test_one_empty_key_in_pair_one_non_empty(self): @@ -92,7 +92,7 @@ def test_one_empty_key_in_pair_one_non_empty(self): err = "Empty key specified for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(namespace) + validators.validate_cluster_autoscaler_profile(cmd, namespace) self.assertEqual(str(cm.exception), err) def test_invalid_key(self): @@ -101,14 +101,14 @@ def test_invalid_key(self): err = "'bad-key' is an invalid key for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(namespace) + validators.validate_cluster_autoscaler_profile(cmd, namespace) self.assertIn(err, str(cm.exception),) def test_valid_parameters(self): cluster_autoscaler_profile = ["scan-interval=20s", "scale-down-delay-after-add=15m"] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) - validators.validate_cluster_autoscaler_profile(namespace) + validators.validate_cluster_autoscaler_profile(cmd, namespace) class Namespace: From 0b0cde52efb58fe300bdbf7a7babfaad40ecafd5 Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Tue, 1 Jun 2021 16:59:49 -0700 Subject: [PATCH 11/29] Changing container service test_validator --- src/azure-cli/azure/cli/command_modules/acs/commands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/commands.py b/src/azure-cli/azure/cli/command_modules/acs/commands.py index cca1a61fed9..f391e3eafbc 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/commands.py +++ b/src/azure-cli/azure/cli/command_modules/acs/commands.py @@ -80,7 +80,8 @@ def load_command_table(self, _): # ACS Kubernetes commands with self.command_group('acs kubernetes', container_services_sdk, - resource_type=ResourceType.MGMT_CONTAINERSERVICE, client_factory=cf_container_services) as g: + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + client_factory=cf_container_services) as g: g.custom_command('browse', 'k8s_browse') g.custom_command('get-credentials', 'k8s_get_credentials') g.custom_command('install-cli', 'k8s_install_cli', client_factory=None) From dde88dab1fc4130a256203c5373b84280b6ba07a Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Tue, 1 Jun 2021 19:34:55 -0700 Subject: [PATCH 12/29] Modifying operation_group to managed_clusters --- src/azure-cli/azure/cli/command_modules/acs/custom.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 e546b53c787..fdba51f7a79 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/custom.py @@ -1972,19 +1972,19 @@ def aks_create(cmd, client, resource_group_name, name, ssh_key_value, # pylint: operation_group='managed_clusters') ContainerServiceNetworkProfile = cmd.get_models('ContainerServiceNetworkProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='container_services') + operation_group='managed_clusters') ContainerServiceLinuxProfile = cmd.get_models('ContainerServiceLinuxProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='container_services') + operation_group='managed_clusters') ManagedClusterServicePrincipalProfile = cmd.get_models('ManagedClusterServicePrincipalProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') ContainerServiceSshConfiguration = cmd.get_models('ContainerServiceSshConfiguration', resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='container_services') + operation_group='managed_clusters') ContainerServiceSshPublicKey = cmd.get_models('ContainerServiceSshPublicKey', resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='container_services') + operation_group='managed_clusters') ManagedClusterAADProfile = cmd.get_models('ManagedClusterAADProfile', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') From 55d82606b9d9c53c8f33fe0761a002a9b08e24ff Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Tue, 1 Jun 2021 23:48:27 -0700 Subject: [PATCH 13/29] Adding managed_clusters operation group to aks run command --- .../azure/cli/command_modules/acs/custom.py | 5 ++++- .../acs/tests/latest/test_loadbalancer.py | 2 +- .../acs/tests/latest/test_validators.py | 12 ++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) 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 fdba51f7a79..588d4a95160 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/custom.py @@ -2259,6 +2259,7 @@ def aks_create(cmd, client, resource_group_name, name, ssh_key_value, # pylint: raise CLIError("Please use standard load balancer for private cluster") if api_server_authorized_ip_ranges or enable_private_cluster: api_server_access_profile = _populate_api_server_access_profile( + cmd, api_server_authorized_ip_ranges, enable_private_cluster=enable_private_cluster ) @@ -2761,6 +2762,7 @@ def aks_update(cmd, client, resource_group_name, name, if api_server_authorized_ip_ranges is not None: instance.api_server_access_profile = \ _populate_api_server_access_profile( + cmd, api_server_authorized_ip_ranges, instance=instance) if enable_aad: @@ -2967,7 +2969,8 @@ def aks_runcommand(cmd, client, resource_group_name, name, command_string="", co if not command_string: raise ValidationError('Command cannot be empty.') - RunCommandRequest = cmd.get_models('RunCommandRequest', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + RunCommandRequest = cmd.get_models('RunCommandRequest', resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') request_payload = RunCommandRequest(command=command_string) request_payload.context = _get_command_context(command_files) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py index 74dce670ee6..2f600c2f04c 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py @@ -9,7 +9,7 @@ class TestLoadBalancer(unittest.TestCase): - def test_configure_load_balancer_profile(self): + def test_configure_load_balancer_profile(cmd, self): managed_outbound_ip_count = 5 outbound_ips = None outbound_ip_prefixes = None diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py index 04fc29cbb32..dc91d32e9ad 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py @@ -62,7 +62,7 @@ def test_IPv6(self): class TestClusterAutoscalerParamsValidators(unittest.TestCase): - def test_empty_key_empty_value(self): + def test_empty_key_empty_value(cmd, self): cluster_autoscaler_profile = ["="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "Empty key specified for cluster-autoscaler-profile" @@ -71,13 +71,13 @@ def test_empty_key_empty_value(self): validators.validate_cluster_autoscaler_profile(cmd, namespace) self.assertEqual(str(cm.exception), err) - def test_non_empty_key_empty_value(self): + def test_non_empty_key_empty_value(cmd, self): cluster_autoscaler_profile = ["scan-interval="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) validators.validate_cluster_autoscaler_profile(cmd, namespace) - def test_two_empty_keys_empty_value(self): + def test_two_empty_keys_empty_value(cmd, self): cluster_autoscaler_profile = ["=", "="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "Empty key specified for cluster-autoscaler-profile" @@ -86,7 +86,7 @@ def test_two_empty_keys_empty_value(self): validators.validate_cluster_autoscaler_profile(cmd, namespace) self.assertEqual(str(cm.exception), err) - def test_one_empty_key_in_pair_one_non_empty(self): + def test_one_empty_key_in_pair_one_non_empty(cmd, self): cluster_autoscaler_profile = ["scan-interval=20s", "="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "Empty key specified for cluster-autoscaler-profile" @@ -95,7 +95,7 @@ def test_one_empty_key_in_pair_one_non_empty(self): validators.validate_cluster_autoscaler_profile(cmd, namespace) self.assertEqual(str(cm.exception), err) - def test_invalid_key(self): + def test_invalid_key(cmd, self): cluster_autoscaler_profile = ["bad-key=val"] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "'bad-key' is an invalid key for cluster-autoscaler-profile" @@ -104,7 +104,7 @@ def test_invalid_key(self): validators.validate_cluster_autoscaler_profile(cmd, namespace) self.assertIn(err, str(cm.exception),) - def test_valid_parameters(self): + def test_valid_parameters(cmd, self): cluster_autoscaler_profile = ["scan-interval=20s", "scale-down-delay-after-add=15m"] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) From c551f3b8fd0bfbe3570bb767070353d2011a9f6b Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Wed, 2 Jun 2021 01:51:27 -0700 Subject: [PATCH 14/29] Container service test code changes --- .../acs/tests/latest/test_custom.py | 4 +- .../acs/tests/latest/test_helpers.py | 40 ++++++++++++-- .../acs/tests/latest/test_loadbalancer.py | 15 ++--- .../acs/tests/latest/test_validators.py | 55 +++++++++++++++---- 4 files changed, 85 insertions(+), 29 deletions(-) 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 628b1f786b0..c85497a75f8 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 @@ -25,6 +25,7 @@ from azure.mgmt.containerservice.models import (ContainerServiceOrchestratorTypes, ContainerService, ContainerServiceOrchestratorProfile) +from azure.mgmt.containerservice.v2020_03_01.models import ManagedClusterAddonProfile from azure.cli.core.util import CLIError from azure.cli.command_modules.acs._consts import (CONST_HTTP_APPLICATION_ROUTING_ADDON_NAME, CONST_MONITORING_ADDON_NAME, @@ -660,9 +661,6 @@ def test_update_addons(self, rg_def, cf_resource_groups, cf_resources): # kube-dashboard disabled, there's existing dashboard addon profile instance.addon_profiles.pop(CONST_KUBE_DASHBOARD_ADDON_NAME, None) # test lower cased key name - ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='managed_clusters') instance.addon_profiles['kubedashboard'] = ManagedClusterAddonProfile(enabled=True) instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'kube-dashboard', enable=False) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py index 7da178f8e29..0a623c5b5ef 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py @@ -4,22 +4,52 @@ # -------------------------------------------------------------------------------------------- import unittest +import mock from azure.cli.command_modules.acs import _helpers as helpers +from azure.cli.core._config import GLOBAL_CONFIG_DIR, ENV_VAR_PREFIX +from azure.cli.core.cloud import get_active_cloud +from azure.cli.core.profiles import get_sdk, ResourceType, supported_api_version + +class MockCLI(CLI): + def __init__(self): + super(MockCLI, self).__init__(cli_name='mock_cli', config_dir=GLOBAL_CONFIG_DIR, + config_env_var_prefix=ENV_VAR_PREFIX, commands_loader_cls=MockLoader) + self.cloud = get_active_cloud(self) + +class MockLoader(object): + def __init__(self, ctx): + self.ctx = ctx + + def get_models(self, *attr_args, **_): + from azure.cli.core.profiles import get_sdk + return get_sdk(self.ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, mod='models') + +class MockCmd(object): + def __init__(self, ctx, arguments={}): + self.cli_ctx = ctx + self.loader = MockLoader(self.cli_ctx) + self.arguments = arguments + + def get_models(self, *attr_args, **kwargs): + return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, **kwargs) class TestPopulateApiServerAccessProfile(unittest.TestCase): + def setUp(self): + self.cli = MockCLI() + def test_single_cidr_with_spaces(self): api_server_authorized_ip_ranges = "0.0.0.0/32 " - profile = helpers._populate_api_server_access_profile(api_server_authorized_ip_ranges, enable_private_cluster=False) + profile = helpers._populate_api_server_access_profile(MockCmd(self.cli), api_server_authorized_ip_ranges, enable_private_cluster=False) self.assertListEqual(profile.authorized_ip_ranges, ["0.0.0.0/32"]) - def test_multi_cidr_with_spaces(self): + def test_multi_cidr_with_spaces(cmd, self): api_server_authorized_ip_ranges = " 0.0.0.0/32 , 129.1.1.1/32" - profile = helpers._populate_api_server_access_profile(api_server_authorized_ip_ranges, enable_private_cluster=False) + profile = helpers._populate_api_server_access_profile(MockCmd(self.cli), api_server_authorized_ip_ranges, enable_private_cluster=False) self.assertListEqual(profile.authorized_ip_ranges, ["0.0.0.0/32", "129.1.1.1/32"]) - def test_private_cluster(self): - profile = helpers._populate_api_server_access_profile(None, enable_private_cluster=True) + def test_private_cluster(cmd, self): + profile = helpers._populate_api_server_access_profile(MockCmd(self.cli), None, enable_private_cluster=True) self.assertListEqual(profile.authorized_ip_ranges, []) self.assertEqual(profile.enable_private_cluster, True) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py index 2f600c2f04c..10b6b8b7ebe 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py @@ -4,25 +4,22 @@ # -------------------------------------------------------------------------------------------- import unittest +from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfile +from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfileManagedOutboundIPs +from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfileOutboundIPPrefixes +from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfileOutboundIPs from azure.cli.core.util import CLIError from azure.cli.command_modules.acs import _loadbalancer as loadbalancer class TestLoadBalancer(unittest.TestCase): - def test_configure_load_balancer_profile(cmd, self): + def test_configure_load_balancer_profile(self): managed_outbound_ip_count = 5 outbound_ips = None outbound_ip_prefixes = None outbound_ports = 80 idle_timeout = 3600 - ManagedClusterLoadBalancerProfile = cmd.get_models('ManagedClusterLoadBalancerProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ManagedClusterLoadBalancerProfileManagedOutboundIPs = cmd.get_models( - 'ManagedClusterLoadBalancerProfileManagedOutboundIPs', resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ManagedClusterLoadBalancerProfileOutboundIPs = cmd.get_models( - 'ManagedClusterLoadBalancerProfileOutboundIPs', resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ManagedClusterLoadBalancerProfileOutboundIPPrefixes = cmd.get_models( - 'ManagedClusterLoadBalancerProfileOutboundIPPrefixes', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + profile = ManagedClusterLoadBalancerProfile() profile.managed_outbound_ips = ManagedClusterLoadBalancerProfileManagedOutboundIPs( count=2 diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py index dc91d32e9ad..74239233923 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py @@ -3,11 +3,39 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- import unittest +import mock from azure.cli.core.util import CLIError from azure.cli.command_modules.acs import _validators as validators +from azure.cli.core._config import GLOBAL_CONFIG_DIR, ENV_VAR_PREFIX +from azure.cli.core.cloud import get_active_cloud +from azure.cli.core.profiles import get_sdk, ResourceType, supported_api_version + +class MockCLI(CLI): + def __init__(self): + super(MockCLI, self).__init__(cli_name='mock_cli', config_dir=GLOBAL_CONFIG_DIR, + config_env_var_prefix=ENV_VAR_PREFIX, commands_loader_cls=MockLoader) + self.cloud = get_active_cloud(self) + +class MockLoader(object): + def __init__(self, ctx): + self.ctx = ctx + + def get_models(self, *attr_args, **_): + from azure.cli.core.profiles import get_sdk + return get_sdk(self.ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, mod='models') + +class MockCmd(object): + def __init__(self, ctx, arguments={}): + self.cli_ctx = ctx + self.loader = MockLoader(self.cli_ctx) + self.arguments = arguments + + def get_models(self, *attr_args, **kwargs): + return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, **kwargs) class TestValidateIPRanges(unittest.TestCase): + def test_simultaneous_allow_and_disallow_with_spaces(self): api_server_authorized_ip_ranges = " 0.0.0.0/32 , 129.1.1.1.1 " namespace = Namespace(api_server_authorized_ip_ranges) @@ -62,53 +90,56 @@ def test_IPv6(self): class TestClusterAutoscalerParamsValidators(unittest.TestCase): - def test_empty_key_empty_value(cmd, self): + def setUp(self): + self.cli = MockCLI() + + def test_empty_key_empty_value(self): cluster_autoscaler_profile = ["="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "Empty key specified for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(cmd, namespace) + validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) self.assertEqual(str(cm.exception), err) - def test_non_empty_key_empty_value(cmd, self): + def test_non_empty_key_empty_value(self): cluster_autoscaler_profile = ["scan-interval="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) - validators.validate_cluster_autoscaler_profile(cmd, namespace) + validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) - def test_two_empty_keys_empty_value(cmd, self): + def test_two_empty_keys_empty_value(self): cluster_autoscaler_profile = ["=", "="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "Empty key specified for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(cmd, namespace) + validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) self.assertEqual(str(cm.exception), err) - def test_one_empty_key_in_pair_one_non_empty(cmd, self): + def test_one_empty_key_in_pair_one_non_empty(self): cluster_autoscaler_profile = ["scan-interval=20s", "="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "Empty key specified for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(cmd, namespace) + validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) self.assertEqual(str(cm.exception), err) - def test_invalid_key(cmd, self): + def test_invalid_key(self): cluster_autoscaler_profile = ["bad-key=val"] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "'bad-key' is an invalid key for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(cmd, namespace) + validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) self.assertIn(err, str(cm.exception),) - def test_valid_parameters(cmd, self): + def test_valid_parameters(self): cluster_autoscaler_profile = ["scan-interval=20s", "scale-down-delay-after-add=15m"] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) - validators.validate_cluster_autoscaler_profile(cmd, namespace) + validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) class Namespace: From aa501086ff366efe140fb8c1a368c74134cca043 Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Wed, 2 Jun 2021 02:33:11 -0700 Subject: [PATCH 15/29] Revert "Container service test code changes" This reverts commit c551f3b8fd0bfbe3570bb767070353d2011a9f6b. --- .../acs/tests/latest/test_custom.py | 4 +- .../acs/tests/latest/test_helpers.py | 40 ++------------ .../acs/tests/latest/test_loadbalancer.py | 15 +++-- .../acs/tests/latest/test_validators.py | 55 ++++--------------- 4 files changed, 29 insertions(+), 85 deletions(-) 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 c85497a75f8..628b1f786b0 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 @@ -25,7 +25,6 @@ from azure.mgmt.containerservice.models import (ContainerServiceOrchestratorTypes, ContainerService, ContainerServiceOrchestratorProfile) -from azure.mgmt.containerservice.v2020_03_01.models import ManagedClusterAddonProfile from azure.cli.core.util import CLIError from azure.cli.command_modules.acs._consts import (CONST_HTTP_APPLICATION_ROUTING_ADDON_NAME, CONST_MONITORING_ADDON_NAME, @@ -661,6 +660,9 @@ def test_update_addons(self, rg_def, cf_resource_groups, cf_resources): # kube-dashboard disabled, there's existing dashboard addon profile instance.addon_profiles.pop(CONST_KUBE_DASHBOARD_ADDON_NAME, None) # test lower cased key name + ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') instance.addon_profiles['kubedashboard'] = ManagedClusterAddonProfile(enabled=True) instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'kube-dashboard', enable=False) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py index 0a623c5b5ef..7da178f8e29 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py @@ -4,52 +4,22 @@ # -------------------------------------------------------------------------------------------- import unittest -import mock from azure.cli.command_modules.acs import _helpers as helpers -from azure.cli.core._config import GLOBAL_CONFIG_DIR, ENV_VAR_PREFIX -from azure.cli.core.cloud import get_active_cloud -from azure.cli.core.profiles import get_sdk, ResourceType, supported_api_version - -class MockCLI(CLI): - def __init__(self): - super(MockCLI, self).__init__(cli_name='mock_cli', config_dir=GLOBAL_CONFIG_DIR, - config_env_var_prefix=ENV_VAR_PREFIX, commands_loader_cls=MockLoader) - self.cloud = get_active_cloud(self) - -class MockLoader(object): - def __init__(self, ctx): - self.ctx = ctx - - def get_models(self, *attr_args, **_): - from azure.cli.core.profiles import get_sdk - return get_sdk(self.ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, mod='models') - -class MockCmd(object): - def __init__(self, ctx, arguments={}): - self.cli_ctx = ctx - self.loader = MockLoader(self.cli_ctx) - self.arguments = arguments - - def get_models(self, *attr_args, **kwargs): - return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, **kwargs) class TestPopulateApiServerAccessProfile(unittest.TestCase): - def setUp(self): - self.cli = MockCLI() - def test_single_cidr_with_spaces(self): api_server_authorized_ip_ranges = "0.0.0.0/32 " - profile = helpers._populate_api_server_access_profile(MockCmd(self.cli), api_server_authorized_ip_ranges, enable_private_cluster=False) + profile = helpers._populate_api_server_access_profile(api_server_authorized_ip_ranges, enable_private_cluster=False) self.assertListEqual(profile.authorized_ip_ranges, ["0.0.0.0/32"]) - def test_multi_cidr_with_spaces(cmd, self): + def test_multi_cidr_with_spaces(self): api_server_authorized_ip_ranges = " 0.0.0.0/32 , 129.1.1.1/32" - profile = helpers._populate_api_server_access_profile(MockCmd(self.cli), api_server_authorized_ip_ranges, enable_private_cluster=False) + profile = helpers._populate_api_server_access_profile(api_server_authorized_ip_ranges, enable_private_cluster=False) self.assertListEqual(profile.authorized_ip_ranges, ["0.0.0.0/32", "129.1.1.1/32"]) - def test_private_cluster(cmd, self): - profile = helpers._populate_api_server_access_profile(MockCmd(self.cli), None, enable_private_cluster=True) + def test_private_cluster(self): + profile = helpers._populate_api_server_access_profile(None, enable_private_cluster=True) self.assertListEqual(profile.authorized_ip_ranges, []) self.assertEqual(profile.enable_private_cluster, True) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py index 10b6b8b7ebe..2f600c2f04c 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py @@ -4,22 +4,25 @@ # -------------------------------------------------------------------------------------------- import unittest -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfile -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfileManagedOutboundIPs -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfileOutboundIPPrefixes -from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfileOutboundIPs from azure.cli.core.util import CLIError from azure.cli.command_modules.acs import _loadbalancer as loadbalancer class TestLoadBalancer(unittest.TestCase): - def test_configure_load_balancer_profile(self): + def test_configure_load_balancer_profile(cmd, self): managed_outbound_ip_count = 5 outbound_ips = None outbound_ip_prefixes = None outbound_ports = 80 idle_timeout = 3600 - + ManagedClusterLoadBalancerProfile = cmd.get_models('ManagedClusterLoadBalancerProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterLoadBalancerProfileManagedOutboundIPs = cmd.get_models( + 'ManagedClusterLoadBalancerProfileManagedOutboundIPs', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterLoadBalancerProfileOutboundIPs = cmd.get_models( + 'ManagedClusterLoadBalancerProfileOutboundIPs', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterLoadBalancerProfileOutboundIPPrefixes = cmd.get_models( + 'ManagedClusterLoadBalancerProfileOutboundIPPrefixes', resource_type=ResourceType.MGMT_CONTAINERSERVICE) profile = ManagedClusterLoadBalancerProfile() profile.managed_outbound_ips = ManagedClusterLoadBalancerProfileManagedOutboundIPs( count=2 diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py index 74239233923..dc91d32e9ad 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py @@ -3,39 +3,11 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- import unittest -import mock from azure.cli.core.util import CLIError from azure.cli.command_modules.acs import _validators as validators -from azure.cli.core._config import GLOBAL_CONFIG_DIR, ENV_VAR_PREFIX -from azure.cli.core.cloud import get_active_cloud -from azure.cli.core.profiles import get_sdk, ResourceType, supported_api_version - -class MockCLI(CLI): - def __init__(self): - super(MockCLI, self).__init__(cli_name='mock_cli', config_dir=GLOBAL_CONFIG_DIR, - config_env_var_prefix=ENV_VAR_PREFIX, commands_loader_cls=MockLoader) - self.cloud = get_active_cloud(self) - -class MockLoader(object): - def __init__(self, ctx): - self.ctx = ctx - - def get_models(self, *attr_args, **_): - from azure.cli.core.profiles import get_sdk - return get_sdk(self.ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, mod='models') - -class MockCmd(object): - def __init__(self, ctx, arguments={}): - self.cli_ctx = ctx - self.loader = MockLoader(self.cli_ctx) - self.arguments = arguments - - def get_models(self, *attr_args, **kwargs): - return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, **kwargs) class TestValidateIPRanges(unittest.TestCase): - def test_simultaneous_allow_and_disallow_with_spaces(self): api_server_authorized_ip_ranges = " 0.0.0.0/32 , 129.1.1.1.1 " namespace = Namespace(api_server_authorized_ip_ranges) @@ -90,56 +62,53 @@ def test_IPv6(self): class TestClusterAutoscalerParamsValidators(unittest.TestCase): - def setUp(self): - self.cli = MockCLI() - - def test_empty_key_empty_value(self): + def test_empty_key_empty_value(cmd, self): cluster_autoscaler_profile = ["="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "Empty key specified for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) + validators.validate_cluster_autoscaler_profile(cmd, namespace) self.assertEqual(str(cm.exception), err) - def test_non_empty_key_empty_value(self): + def test_non_empty_key_empty_value(cmd, self): cluster_autoscaler_profile = ["scan-interval="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) - validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) + validators.validate_cluster_autoscaler_profile(cmd, namespace) - def test_two_empty_keys_empty_value(self): + def test_two_empty_keys_empty_value(cmd, self): cluster_autoscaler_profile = ["=", "="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "Empty key specified for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) + validators.validate_cluster_autoscaler_profile(cmd, namespace) self.assertEqual(str(cm.exception), err) - def test_one_empty_key_in_pair_one_non_empty(self): + def test_one_empty_key_in_pair_one_non_empty(cmd, self): cluster_autoscaler_profile = ["scan-interval=20s", "="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "Empty key specified for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) + validators.validate_cluster_autoscaler_profile(cmd, namespace) self.assertEqual(str(cm.exception), err) - def test_invalid_key(self): + def test_invalid_key(cmd, self): cluster_autoscaler_profile = ["bad-key=val"] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "'bad-key' is an invalid key for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) + validators.validate_cluster_autoscaler_profile(cmd, namespace) self.assertIn(err, str(cm.exception),) - def test_valid_parameters(self): + def test_valid_parameters(cmd, self): cluster_autoscaler_profile = ["scan-interval=20s", "scale-down-delay-after-add=15m"] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) - validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) + validators.validate_cluster_autoscaler_profile(cmd, namespace) class Namespace: From 124fcd446ef6e3b84ae67551ec70a54e93955f67 Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Wed, 2 Jun 2021 23:42:37 -0700 Subject: [PATCH 16/29] Adding mock cmd to acs test --- .../acs/tests/latest/test_custom.py | 4 +- .../acs/tests/latest/test_helpers.py | 42 ++++++++++++- .../acs/tests/latest/test_loadbalancer.py | 15 ++--- .../acs/tests/latest/test_validators.py | 60 +++++++++++++++---- 4 files changed, 94 insertions(+), 27 deletions(-) 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 628b1f786b0..c85497a75f8 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 @@ -25,6 +25,7 @@ from azure.mgmt.containerservice.models import (ContainerServiceOrchestratorTypes, ContainerService, ContainerServiceOrchestratorProfile) +from azure.mgmt.containerservice.v2020_03_01.models import ManagedClusterAddonProfile from azure.cli.core.util import CLIError from azure.cli.command_modules.acs._consts import (CONST_HTTP_APPLICATION_ROUTING_ADDON_NAME, CONST_MONITORING_ADDON_NAME, @@ -660,9 +661,6 @@ def test_update_addons(self, rg_def, cf_resource_groups, cf_resources): # kube-dashboard disabled, there's existing dashboard addon profile instance.addon_profiles.pop(CONST_KUBE_DASHBOARD_ADDON_NAME, None) # test lower cased key name - ManagedClusterAddonProfile = cmd.get_models('ManagedClusterAddonProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='managed_clusters') instance.addon_profiles['kubedashboard'] = ManagedClusterAddonProfile(enabled=True) instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'kube-dashboard', enable=False) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py index 7da178f8e29..4bf705d1b7d 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py @@ -4,22 +4,58 @@ # -------------------------------------------------------------------------------------------- import unittest +import mock + +from knack import CLI + +from azure.cli.core._config import GLOBAL_CONFIG_DIR, ENV_VAR_PREFIX +from azure.cli.core.cloud import get_active_cloud +from azure.cli.core.profiles import get_sdk, ResourceType, supported_api_version + from azure.cli.command_modules.acs import _helpers as helpers +class MockCLI(CLI): + def __init__(self): + super(MockCLI, self).__init__(cli_name='mock_cli', config_dir=GLOBAL_CONFIG_DIR, + config_env_var_prefix=ENV_VAR_PREFIX, commands_loader_cls=MockLoader) + self.cloud = get_active_cloud(self) + + +class MockLoader(object): + def __init__(self, ctx): + self.ctx = ctx + + def get_models(self, *attr_args, **_): + from azure.cli.core.profiles import get_sdk + return get_sdk(self.ctx, ResourceType.DATA_STORAGE, *attr_args, mod='models') + + +class MockCmd(object): + def __init__(self, ctx, arguments={}): + self.cli_ctx = ctx + self.loader = MockLoader(self.cli_ctx) + self.arguments = arguments + + def get_models(self, *attr_args, **kwargs): + return get_sdk(self.cli_ctx, ResourceType.DATA_STORAGE, *attr_args, **kwargs) + class TestPopulateApiServerAccessProfile(unittest.TestCase): + def setUp(self): + self.cli = MockCLI() + def test_single_cidr_with_spaces(self): api_server_authorized_ip_ranges = "0.0.0.0/32 " - profile = helpers._populate_api_server_access_profile(api_server_authorized_ip_ranges, enable_private_cluster=False) + profile = helpers._populate_api_server_access_profile(MockCmd(self.cli), api_server_authorized_ip_ranges, enable_private_cluster=False) self.assertListEqual(profile.authorized_ip_ranges, ["0.0.0.0/32"]) def test_multi_cidr_with_spaces(self): api_server_authorized_ip_ranges = " 0.0.0.0/32 , 129.1.1.1/32" - profile = helpers._populate_api_server_access_profile(api_server_authorized_ip_ranges, enable_private_cluster=False) + profile = helpers._populate_api_server_access_profile(MockCmd(self.cli), api_server_authorized_ip_ranges, enable_private_cluster=False) self.assertListEqual(profile.authorized_ip_ranges, ["0.0.0.0/32", "129.1.1.1/32"]) def test_private_cluster(self): - profile = helpers._populate_api_server_access_profile(None, enable_private_cluster=True) + profile = helpers._populate_api_server_access_profile(MockCmd(self.cli), None, enable_private_cluster=True) self.assertListEqual(profile.authorized_ip_ranges, []) self.assertEqual(profile.enable_private_cluster, True) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py index 2f600c2f04c..10b6b8b7ebe 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py @@ -4,25 +4,22 @@ # -------------------------------------------------------------------------------------------- import unittest +from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfile +from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfileManagedOutboundIPs +from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfileOutboundIPPrefixes +from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfileOutboundIPs from azure.cli.core.util import CLIError from azure.cli.command_modules.acs import _loadbalancer as loadbalancer class TestLoadBalancer(unittest.TestCase): - def test_configure_load_balancer_profile(cmd, self): + def test_configure_load_balancer_profile(self): managed_outbound_ip_count = 5 outbound_ips = None outbound_ip_prefixes = None outbound_ports = 80 idle_timeout = 3600 - ManagedClusterLoadBalancerProfile = cmd.get_models('ManagedClusterLoadBalancerProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ManagedClusterLoadBalancerProfileManagedOutboundIPs = cmd.get_models( - 'ManagedClusterLoadBalancerProfileManagedOutboundIPs', resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ManagedClusterLoadBalancerProfileOutboundIPs = cmd.get_models( - 'ManagedClusterLoadBalancerProfileOutboundIPs', resource_type=ResourceType.MGMT_CONTAINERSERVICE) - ManagedClusterLoadBalancerProfileOutboundIPPrefixes = cmd.get_models( - 'ManagedClusterLoadBalancerProfileOutboundIPPrefixes', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + profile = ManagedClusterLoadBalancerProfile() profile.managed_outbound_ips = ManagedClusterLoadBalancerProfileManagedOutboundIPs( count=2 diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py index dc91d32e9ad..cbe54549022 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py @@ -3,9 +3,42 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- import unittest +import mock + +from knack import CLI + +from azure.cli.core._config import GLOBAL_CONFIG_DIR, ENV_VAR_PREFIX +from azure.cli.core.cloud import get_active_cloud +from azure.cli.core.profiles import get_sdk, ResourceType, supported_api_version + from azure.cli.core.util import CLIError from azure.cli.command_modules.acs import _validators as validators +class MockCLI(CLI): + def __init__(self): + super(MockCLI, self).__init__(cli_name='mock_cli', config_dir=GLOBAL_CONFIG_DIR, + config_env_var_prefix=ENV_VAR_PREFIX, commands_loader_cls=MockLoader) + self.cloud = get_active_cloud(self) + + +class MockLoader(object): + def __init__(self, ctx): + self.ctx = ctx + + def get_models(self, *attr_args, **_): + from azure.cli.core.profiles import get_sdk + return get_sdk(self.ctx, ResourceType.DATA_STORAGE, *attr_args, mod='models') + + +class MockCmd(object): + def __init__(self, ctx, arguments={}): + self.cli_ctx = ctx + self.loader = MockLoader(self.cli_ctx) + self.arguments = arguments + + def get_models(self, *attr_args, **kwargs): + return get_sdk(self.cli_ctx, ResourceType.DATA_STORAGE, *attr_args, **kwargs) + class TestValidateIPRanges(unittest.TestCase): def test_simultaneous_allow_and_disallow_with_spaces(self): @@ -62,53 +95,56 @@ def test_IPv6(self): class TestClusterAutoscalerParamsValidators(unittest.TestCase): - def test_empty_key_empty_value(cmd, self): + def setUp(self): + self.cli = MockCLI() + + def test_empty_key_empty_value(self): cluster_autoscaler_profile = ["="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "Empty key specified for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(cmd, namespace) + validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) self.assertEqual(str(cm.exception), err) - def test_non_empty_key_empty_value(cmd, self): + def test_non_empty_key_empty_value(self): cluster_autoscaler_profile = ["scan-interval="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) - validators.validate_cluster_autoscaler_profile(cmd, namespace) + validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) - def test_two_empty_keys_empty_value(cmd, self): + def test_two_empty_keys_empty_value(self): cluster_autoscaler_profile = ["=", "="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "Empty key specified for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(cmd, namespace) + validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) self.assertEqual(str(cm.exception), err) - def test_one_empty_key_in_pair_one_non_empty(cmd, self): + def test_one_empty_key_in_pair_one_non_empty(self): cluster_autoscaler_profile = ["scan-interval=20s", "="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "Empty key specified for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(cmd, namespace) + validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) self.assertEqual(str(cm.exception), err) - def test_invalid_key(cmd, self): + def test_invalid_key(self): cluster_autoscaler_profile = ["bad-key=val"] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "'bad-key' is an invalid key for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(cmd, namespace) + validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) self.assertIn(err, str(cm.exception),) - def test_valid_parameters(cmd, self): + def test_valid_parameters(self): cluster_autoscaler_profile = ["scan-interval=20s", "scale-down-delay-after-add=15m"] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) - validators.validate_cluster_autoscaler_profile(cmd, namespace) + validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) class Namespace: From 20a60f08d2c09e25aa4ca439b8978b1388fc511b Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Thu, 3 Jun 2021 00:29:00 -0700 Subject: [PATCH 17/29] Fix resource tyope in acs test --- .../cli/command_modules/acs/tests/latest/test_helpers.py | 4 ++-- .../cli/command_modules/acs/tests/latest/test_validators.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py index 4bf705d1b7d..cb79aa9ae86 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py @@ -27,7 +27,7 @@ def __init__(self, ctx): def get_models(self, *attr_args, **_): from azure.cli.core.profiles import get_sdk - return get_sdk(self.ctx, ResourceType.DATA_STORAGE, *attr_args, mod='models') + return get_sdk(self.ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, mod='models') class MockCmd(object): @@ -37,7 +37,7 @@ def __init__(self, ctx, arguments={}): self.arguments = arguments def get_models(self, *attr_args, **kwargs): - return get_sdk(self.cli_ctx, ResourceType.DATA_STORAGE, *attr_args, **kwargs) + return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, **kwargs) class TestPopulateApiServerAccessProfile(unittest.TestCase): diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py index cbe54549022..16ce55450cb 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py @@ -27,7 +27,7 @@ def __init__(self, ctx): def get_models(self, *attr_args, **_): from azure.cli.core.profiles import get_sdk - return get_sdk(self.ctx, ResourceType.DATA_STORAGE, *attr_args, mod='models') + return get_sdk(self.ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, mod='models') class MockCmd(object): @@ -37,7 +37,7 @@ def __init__(self, ctx, arguments={}): self.arguments = arguments def get_models(self, *attr_args, **kwargs): - return get_sdk(self.cli_ctx, ResourceType.DATA_STORAGE, *attr_args, **kwargs) + return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, **kwargs) class TestValidateIPRanges(unittest.TestCase): From 4c206ea6f6e27d896fd6e46c48c5b23c7c656467 Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Thu, 3 Jun 2021 02:08:27 -0700 Subject: [PATCH 18/29] Fix resource tyope in acs test --- .../acs/tests/latest/test_helpers.py | 2 +- .../acs/tests/latest/test_loadbalancer.py | 36 ++++++++++++++++++- .../acs/tests/latest/test_validators.py | 2 +- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py index cb79aa9ae86..2761654b19f 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py @@ -37,7 +37,7 @@ def __init__(self, ctx, arguments={}): self.arguments = arguments def get_models(self, *attr_args, **kwargs): - return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, **kwargs) + return get_sdk(self.cli_ctx, *attr_args, **kwargs) class TestPopulateApiServerAccessProfile(unittest.TestCase): diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py index 10b6b8b7ebe..b0051dd2fb2 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py @@ -3,6 +3,13 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- import unittest +import mock + +from knack import CLI + +from azure.cli.core._config import GLOBAL_CONFIG_DIR, ENV_VAR_PREFIX +from azure.cli.core.cloud import get_active_cloud +from azure.cli.core.profiles import get_sdk, ResourceType, supported_api_version from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfile from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfileManagedOutboundIPs @@ -11,8 +18,35 @@ from azure.cli.core.util import CLIError from azure.cli.command_modules.acs import _loadbalancer as loadbalancer +class MockCLI(CLI): + def __init__(self): + super(MockCLI, self).__init__(cli_name='mock_cli', config_dir=GLOBAL_CONFIG_DIR, + config_env_var_prefix=ENV_VAR_PREFIX, commands_loader_cls=MockLoader) + self.cloud = get_active_cloud(self) + + +class MockLoader(object): + def __init__(self, ctx): + self.ctx = ctx + + def get_models(self, *attr_args, **_): + from azure.cli.core.profiles import get_sdk + return get_sdk(self.ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, mod='models') + + +class MockCmd(object): + def __init__(self, ctx, arguments={}): + self.cli_ctx = ctx + self.loader = MockLoader(self.cli_ctx) + self.arguments = arguments + + def get_models(self, *attr_args, **kwargs): + return get_sdk(self.cli_ctx, *attr_args, **kwargs) class TestLoadBalancer(unittest.TestCase): + def setUp(self): + self.cli = MockCLI() + def test_configure_load_balancer_profile(self): managed_outbound_ip_count = 5 outbound_ips = None @@ -31,7 +65,7 @@ def test_configure_load_balancer_profile(self): public_ip_prefixes="public_ip_prefixes" ) - p = loadbalancer.configure_load_balancer_profile( + p = loadbalancer.configure_load_balancer_profile(MockCmd(self.cli), managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, outbound_ports, idle_timeout, profile) self.assertIsNotNone(p.managed_outbound_ips) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py index 16ce55450cb..53dae44dd62 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py @@ -37,7 +37,7 @@ def __init__(self, ctx, arguments={}): self.arguments = arguments def get_models(self, *attr_args, **kwargs): - return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, **kwargs) + return get_sdk(self.cli_ctx, *attr_args, **kwargs) class TestValidateIPRanges(unittest.TestCase): From 98bd825db3b6ed92cb82291c63de5d3feef6473b Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Thu, 3 Jun 2021 11:16:59 -0700 Subject: [PATCH 19/29] Removing resource type in mock cmd --- .../cli/command_modules/acs/tests/latest/test_loadbalancer.py | 2 +- .../cli/command_modules/acs/tests/latest/test_validators.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py index b0051dd2fb2..60e362220b4 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py @@ -31,7 +31,7 @@ def __init__(self, ctx): def get_models(self, *attr_args, **_): from azure.cli.core.profiles import get_sdk - return get_sdk(self.ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, mod='models') + return get_sdk(self.ctx, *attr_args, mod='models') class MockCmd(object): diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py index 53dae44dd62..bc7088d9841 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py @@ -27,7 +27,7 @@ def __init__(self, ctx): def get_models(self, *attr_args, **_): from azure.cli.core.profiles import get_sdk - return get_sdk(self.ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, mod='models') + return get_sdk(self.ctx, *attr_args, mod='models') class MockCmd(object): From 990dcf0244e1740598b5ae8463f7b7b1beaa67c3 Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Fri, 4 Jun 2021 14:03:23 -0700 Subject: [PATCH 20/29] Changing acs get_models --- src/azure-cli/azure/cli/command_modules/acs/_helpers.py | 4 +--- .../azure/cli/command_modules/acs/_loadbalancer.py | 9 ++++----- .../azure/cli/command_modules/acs/_validators.py | 4 +--- .../cli/command_modules/acs/tests/latest/test_helpers.py | 2 +- .../command_modules/acs/tests/latest/test_validators.py | 4 ++-- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/_helpers.py index b3196aa153b..7169fcc6ae2 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_helpers.py @@ -6,7 +6,6 @@ from distutils.version import StrictVersion # pylint: disable=no-name-in-module,import-error # pylint: disable=no-name-in-module,import-error from knack.util import CLIError -from azure.cli.core.profiles import ResourceType from ._consts import CONST_OUTBOUND_TYPE_LOAD_BALANCER, CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING @@ -14,8 +13,7 @@ def _populate_api_server_access_profile(cmd, api_server_authorized_ip_ranges, enable_private_cluster=False, instance=None): if instance is None or instance.api_server_access_profile is None: - ManagedClusterAPIServerAccessProfile = cmd.get_models('ManagedClusterAPIServerAccessProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterAPIServerAccessProfile = cmd.get_models('ManagedClusterAPIServerAccessProfile') profile = ManagedClusterAPIServerAccessProfile() else: profile = instance.api_server_access_profile diff --git a/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py b/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py index e5c3c7632e0..4773549940f 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py @@ -41,8 +41,7 @@ def create_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, o outbound_ports, idle_timeout): return None - ManagedClusterLoadBalancerProfile = cmd.get_models('ManagedClusterLoadBalancerProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterLoadBalancerProfile = cmd.get_models('ManagedClusterLoadBalancerProfile') profile = ManagedClusterLoadBalancerProfile() return configure_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, outbound_ports, idle_timeout, profile) @@ -64,19 +63,19 @@ def configure_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips profile.outbound_ip_prefixes = None if managed_outbound_ip_count: ManagedClusterLoadBalancerProfileManagedOutboundIPs = cmd.get_models( - 'ManagedClusterLoadBalancerProfileManagedOutboundIPs', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + 'ManagedClusterLoadBalancerProfileManagedOutboundIPs') profile.managed_outbound_ips = ManagedClusterLoadBalancerProfileManagedOutboundIPs( count=managed_outbound_ip_count ) if outbound_ip_resources: ManagedClusterLoadBalancerProfileOutboundIPs = cmd.get_models( - 'ManagedClusterLoadBalancerProfileOutboundIPs', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + 'ManagedClusterLoadBalancerProfileOutboundIPs') profile.outbound_ips = ManagedClusterLoadBalancerProfileOutboundIPs( public_ips=outbound_ip_resources ) if outbound_ip_prefix_resources: ManagedClusterLoadBalancerProfileOutboundIPPrefixes = cmd.get_models( - 'ManagedClusterLoadBalancerProfileOutboundIPPrefixes', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + 'ManagedClusterLoadBalancerProfileOutboundIPPrefixes') profile.outbound_ip_prefixes = ManagedClusterLoadBalancerProfileOutboundIPPrefixes( public_ip_prefixes=outbound_ip_prefix_resources ) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_validators.py b/src/azure-cli/azure/cli/command_modules/acs/_validators.py index 9a23aaba7eb..356dfbb650a 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_validators.py @@ -18,7 +18,6 @@ from azure.cli.core.azclierror import InvalidArgumentValueError import azure.cli.core.keys as keys -from azure.cli.core.profiles import ResourceType logger = get_logger(__name__) @@ -122,8 +121,7 @@ def validate_cluster_autoscaler_profile(cmd, namespace): def _validate_cluster_autoscaler_key(cmd, key): if not key: raise CLIError('Empty key specified for cluster-autoscaler-profile') - ManagedClusterPropertiesAutoScalerProfile = cmd.get_models('ManagedClusterPropertiesAutoScalerProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterPropertiesAutoScalerProfile = cmd.get_models('ManagedClusterPropertiesAutoScalerProfile') valid_keys = list(k.replace("_", "-") for k, v in ManagedClusterPropertiesAutoScalerProfile._attribute_map.items()) # pylint: disable=protected-access if key not in valid_keys: raise CLIError("'{0}' is an invalid key for cluster-autoscaler-profile. " diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py index 2761654b19f..cb79aa9ae86 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py @@ -37,7 +37,7 @@ def __init__(self, ctx, arguments={}): self.arguments = arguments def get_models(self, *attr_args, **kwargs): - return get_sdk(self.cli_ctx, *attr_args, **kwargs) + return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, **kwargs) class TestPopulateApiServerAccessProfile(unittest.TestCase): diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py index bc7088d9841..16ce55450cb 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py @@ -27,7 +27,7 @@ def __init__(self, ctx): def get_models(self, *attr_args, **_): from azure.cli.core.profiles import get_sdk - return get_sdk(self.ctx, *attr_args, mod='models') + return get_sdk(self.ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, mod='models') class MockCmd(object): @@ -37,7 +37,7 @@ def __init__(self, ctx, arguments={}): self.arguments = arguments def get_models(self, *attr_args, **kwargs): - return get_sdk(self.cli_ctx, *attr_args, **kwargs) + return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, **kwargs) class TestValidateIPRanges(unittest.TestCase): From a64810308b8f7d462a800f65bd2af62b523e6284 Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Fri, 4 Jun 2021 14:56:38 -0700 Subject: [PATCH 21/29] Adding operation group to get_models --- src/azure-cli/azure/cli/command_modules/acs/_helpers.py | 3 ++- .../azure/cli/command_modules/acs/_loadbalancer.py | 9 +++++---- .../azure/cli/command_modules/acs/_validators.py | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/_helpers.py index 7169fcc6ae2..33a5ec1c11c 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_helpers.py @@ -13,7 +13,8 @@ def _populate_api_server_access_profile(cmd, api_server_authorized_ip_ranges, enable_private_cluster=False, instance=None): if instance is None or instance.api_server_access_profile is None: - ManagedClusterAPIServerAccessProfile = cmd.get_models('ManagedClusterAPIServerAccessProfile') + ManagedClusterAPIServerAccessProfile = cmd.get_models('ManagedClusterAPIServerAccessProfile', + operation_group='managed_clusters') profile = ManagedClusterAPIServerAccessProfile() else: profile = instance.api_server_access_profile diff --git a/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py b/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py index 4773549940f..1421c2b3237 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py @@ -41,7 +41,8 @@ def create_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, o outbound_ports, idle_timeout): return None - ManagedClusterLoadBalancerProfile = cmd.get_models('ManagedClusterLoadBalancerProfile') + ManagedClusterLoadBalancerProfile = cmd.get_models('ManagedClusterLoadBalancerProfile', + operation_group='managed_clusters') profile = ManagedClusterLoadBalancerProfile() return configure_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, outbound_ports, idle_timeout, profile) @@ -63,19 +64,19 @@ def configure_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips profile.outbound_ip_prefixes = None if managed_outbound_ip_count: ManagedClusterLoadBalancerProfileManagedOutboundIPs = cmd.get_models( - 'ManagedClusterLoadBalancerProfileManagedOutboundIPs') + 'ManagedClusterLoadBalancerProfileManagedOutboundIPs', operation_group='managed_clusters') profile.managed_outbound_ips = ManagedClusterLoadBalancerProfileManagedOutboundIPs( count=managed_outbound_ip_count ) if outbound_ip_resources: ManagedClusterLoadBalancerProfileOutboundIPs = cmd.get_models( - 'ManagedClusterLoadBalancerProfileOutboundIPs') + 'ManagedClusterLoadBalancerProfileOutboundIPs', operation_group='managed_clusters') profile.outbound_ips = ManagedClusterLoadBalancerProfileOutboundIPs( public_ips=outbound_ip_resources ) if outbound_ip_prefix_resources: ManagedClusterLoadBalancerProfileOutboundIPPrefixes = cmd.get_models( - 'ManagedClusterLoadBalancerProfileOutboundIPPrefixes') + 'ManagedClusterLoadBalancerProfileOutboundIPPrefixes', operation_group='managed_clusters') profile.outbound_ip_prefixes = ManagedClusterLoadBalancerProfileOutboundIPPrefixes( public_ip_prefixes=outbound_ip_prefix_resources ) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_validators.py b/src/azure-cli/azure/cli/command_modules/acs/_validators.py index 356dfbb650a..6a604e99ebd 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_validators.py @@ -121,7 +121,8 @@ def validate_cluster_autoscaler_profile(cmd, namespace): def _validate_cluster_autoscaler_key(cmd, key): if not key: raise CLIError('Empty key specified for cluster-autoscaler-profile') - ManagedClusterPropertiesAutoScalerProfile = cmd.get_models('ManagedClusterPropertiesAutoScalerProfile') + ManagedClusterPropertiesAutoScalerProfile = cmd.get_models('ManagedClusterPropertiesAutoScalerProfile', + operation_group='managed_clusters') valid_keys = list(k.replace("_", "-") for k, v in ManagedClusterPropertiesAutoScalerProfile._attribute_map.items()) # pylint: disable=protected-access if key not in valid_keys: raise CLIError("'{0}' is an invalid key for cluster-autoscaler-profile. " From e01899e4afe1efa0bd81af194180e2853a9b66c9 Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Fri, 4 Jun 2021 17:53:37 -0700 Subject: [PATCH 22/29] Adding magicmock to acs test --- .../azure/cli/command_modules/acs/_helpers.py | 3 ++- .../cli/command_modules/acs/_loadbalancer.py | 11 +++++++---- .../azure/cli/command_modules/acs/_validators.py | 4 +++- .../acs/tests/latest/test_helpers.py | 9 ++++----- .../acs/tests/latest/test_loadbalancer.py | 5 ++--- .../acs/tests/latest/test_validators.py | 15 +++++++-------- 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/_helpers.py index 33a5ec1c11c..b3196aa153b 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_helpers.py @@ -6,6 +6,7 @@ from distutils.version import StrictVersion # pylint: disable=no-name-in-module,import-error # pylint: disable=no-name-in-module,import-error from knack.util import CLIError +from azure.cli.core.profiles import ResourceType from ._consts import CONST_OUTBOUND_TYPE_LOAD_BALANCER, CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING @@ -14,7 +15,7 @@ def _populate_api_server_access_profile(cmd, enable_private_cluster=False, instance=None): if instance is None or instance.api_server_access_profile is None: ManagedClusterAPIServerAccessProfile = cmd.get_models('ManagedClusterAPIServerAccessProfile', - operation_group='managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) profile = ManagedClusterAPIServerAccessProfile() else: profile = instance.api_server_access_profile diff --git a/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py b/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py index 1421c2b3237..de4776dc409 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py @@ -42,7 +42,7 @@ def create_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, o return None ManagedClusterLoadBalancerProfile = cmd.get_models('ManagedClusterLoadBalancerProfile', - operation_group='managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) profile = ManagedClusterLoadBalancerProfile() return configure_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, outbound_ports, idle_timeout, profile) @@ -64,19 +64,22 @@ def configure_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips profile.outbound_ip_prefixes = None if managed_outbound_ip_count: ManagedClusterLoadBalancerProfileManagedOutboundIPs = cmd.get_models( - 'ManagedClusterLoadBalancerProfileManagedOutboundIPs', operation_group='managed_clusters') + 'ManagedClusterLoadBalancerProfileManagedOutboundIPs', + resource_type=ResourceType.MGMT_CONTAINERSERVICE) profile.managed_outbound_ips = ManagedClusterLoadBalancerProfileManagedOutboundIPs( count=managed_outbound_ip_count ) if outbound_ip_resources: ManagedClusterLoadBalancerProfileOutboundIPs = cmd.get_models( - 'ManagedClusterLoadBalancerProfileOutboundIPs', operation_group='managed_clusters') + 'ManagedClusterLoadBalancerProfileOutboundIPs', + resource_type=ResourceType.MGMT_CONTAINERSERVICE) profile.outbound_ips = ManagedClusterLoadBalancerProfileOutboundIPs( public_ips=outbound_ip_resources ) if outbound_ip_prefix_resources: ManagedClusterLoadBalancerProfileOutboundIPPrefixes = cmd.get_models( - 'ManagedClusterLoadBalancerProfileOutboundIPPrefixes', operation_group='managed_clusters') + 'ManagedClusterLoadBalancerProfileOutboundIPPrefixes', + resource_type=ResourceType.MGMT_CONTAINERSERVICE) profile.outbound_ip_prefixes = ManagedClusterLoadBalancerProfileOutboundIPPrefixes( public_ip_prefixes=outbound_ip_prefix_resources ) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_validators.py b/src/azure-cli/azure/cli/command_modules/acs/_validators.py index 6a604e99ebd..e61c299b66c 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_validators.py @@ -13,6 +13,8 @@ # pylint: disable=no-name-in-module,import-error from knack.log import get_logger +from azure.cli.core.profiles import ResourceType + from azure.cli.core.commands.validators import validate_tag from azure.cli.core.util import CLIError from azure.cli.core.azclierror import InvalidArgumentValueError @@ -122,7 +124,7 @@ def _validate_cluster_autoscaler_key(cmd, key): if not key: raise CLIError('Empty key specified for cluster-autoscaler-profile') ManagedClusterPropertiesAutoScalerProfile = cmd.get_models('ManagedClusterPropertiesAutoScalerProfile', - operation_group='managed_clusters') + resource_type=ResourceType.MGMT_CONTAINERSERVICE) valid_keys = list(k.replace("_", "-") for k, v in ManagedClusterPropertiesAutoScalerProfile._attribute_map.items()) # pylint: disable=protected-access if key not in valid_keys: raise CLIError("'{0}' is an invalid key for cluster-autoscaler-profile. " diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py index cb79aa9ae86..1ff49956cb2 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py @@ -41,21 +41,20 @@ def get_models(self, *attr_args, **kwargs): class TestPopulateApiServerAccessProfile(unittest.TestCase): - def setUp(self): - self.cli = MockCLI() + cmd = mock.MagicMock() def test_single_cidr_with_spaces(self): api_server_authorized_ip_ranges = "0.0.0.0/32 " - profile = helpers._populate_api_server_access_profile(MockCmd(self.cli), api_server_authorized_ip_ranges, enable_private_cluster=False) + profile = helpers._populate_api_server_access_profile(cmd, api_server_authorized_ip_ranges, enable_private_cluster=False) self.assertListEqual(profile.authorized_ip_ranges, ["0.0.0.0/32"]) def test_multi_cidr_with_spaces(self): api_server_authorized_ip_ranges = " 0.0.0.0/32 , 129.1.1.1/32" - profile = helpers._populate_api_server_access_profile(MockCmd(self.cli), api_server_authorized_ip_ranges, enable_private_cluster=False) + profile = helpers._populate_api_server_access_profile(cmd, api_server_authorized_ip_ranges, enable_private_cluster=False) self.assertListEqual(profile.authorized_ip_ranges, ["0.0.0.0/32", "129.1.1.1/32"]) def test_private_cluster(self): - profile = helpers._populate_api_server_access_profile(MockCmd(self.cli), None, enable_private_cluster=True) + profile = helpers._populate_api_server_access_profile(cmd, None, enable_private_cluster=True) self.assertListEqual(profile.authorized_ip_ranges, []) self.assertEqual(profile.enable_private_cluster, True) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py index 60e362220b4..641ddc75138 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py @@ -44,8 +44,7 @@ def get_models(self, *attr_args, **kwargs): return get_sdk(self.cli_ctx, *attr_args, **kwargs) class TestLoadBalancer(unittest.TestCase): - def setUp(self): - self.cli = MockCLI() + cmd = mock.MagicMock() def test_configure_load_balancer_profile(self): managed_outbound_ip_count = 5 @@ -65,7 +64,7 @@ def test_configure_load_balancer_profile(self): public_ip_prefixes="public_ip_prefixes" ) - p = loadbalancer.configure_load_balancer_profile(MockCmd(self.cli), + p = loadbalancer.configure_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, outbound_ports, idle_timeout, profile) self.assertIsNotNone(p.managed_outbound_ips) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py index 16ce55450cb..55f138d5287 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py @@ -95,8 +95,7 @@ def test_IPv6(self): class TestClusterAutoscalerParamsValidators(unittest.TestCase): - def setUp(self): - self.cli = MockCLI() + cmd = mock.MagicMock() def test_empty_key_empty_value(self): cluster_autoscaler_profile = ["="] @@ -104,14 +103,14 @@ def test_empty_key_empty_value(self): err = "Empty key specified for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) + validators.validate_cluster_autoscaler_profile(cmd, namespace) self.assertEqual(str(cm.exception), err) def test_non_empty_key_empty_value(self): cluster_autoscaler_profile = ["scan-interval="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) - validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) + validators.validate_cluster_autoscaler_profile(cmd, namespace) def test_two_empty_keys_empty_value(self): cluster_autoscaler_profile = ["=", "="] @@ -119,7 +118,7 @@ def test_two_empty_keys_empty_value(self): err = "Empty key specified for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) + validators.validate_cluster_autoscaler_profile(cmd, namespace) self.assertEqual(str(cm.exception), err) def test_one_empty_key_in_pair_one_non_empty(self): @@ -128,7 +127,7 @@ def test_one_empty_key_in_pair_one_non_empty(self): err = "Empty key specified for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) + validators.validate_cluster_autoscaler_profile(cmd, namespace) self.assertEqual(str(cm.exception), err) def test_invalid_key(self): @@ -137,14 +136,14 @@ def test_invalid_key(self): err = "'bad-key' is an invalid key for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) + validators.validate_cluster_autoscaler_profile(cmd, namespace) self.assertIn(err, str(cm.exception),) def test_valid_parameters(self): cluster_autoscaler_profile = ["scan-interval=20s", "scale-down-delay-after-add=15m"] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) - validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) + validators.validate_cluster_autoscaler_profile(cmd, namespace) class Namespace: From 0f152fcf5bf2ecc4908a40c232142cfff28485bb Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Fri, 4 Jun 2021 19:37:11 -0700 Subject: [PATCH 23/29] Ading magicmock to acs test --- .../cli/command_modules/acs/tests/latest/test_helpers.py | 4 +++- .../command_modules/acs/tests/latest/test_loadbalancer.py | 2 +- .../command_modules/acs/tests/latest/test_validators.py | 7 ++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py index 1ff49956cb2..88b10625db7 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py @@ -41,19 +41,21 @@ def get_models(self, *attr_args, **kwargs): class TestPopulateApiServerAccessProfile(unittest.TestCase): - cmd = mock.MagicMock() def test_single_cidr_with_spaces(self): + cmd = mock.MagicMock() api_server_authorized_ip_ranges = "0.0.0.0/32 " profile = helpers._populate_api_server_access_profile(cmd, api_server_authorized_ip_ranges, enable_private_cluster=False) self.assertListEqual(profile.authorized_ip_ranges, ["0.0.0.0/32"]) def test_multi_cidr_with_spaces(self): + cmd = mock.MagicMock() api_server_authorized_ip_ranges = " 0.0.0.0/32 , 129.1.1.1/32" profile = helpers._populate_api_server_access_profile(cmd, api_server_authorized_ip_ranges, enable_private_cluster=False) self.assertListEqual(profile.authorized_ip_ranges, ["0.0.0.0/32", "129.1.1.1/32"]) def test_private_cluster(self): + cmd = mock.MagicMock() profile = helpers._populate_api_server_access_profile(cmd, None, enable_private_cluster=True) self.assertListEqual(profile.authorized_ip_ranges, []) self.assertEqual(profile.enable_private_cluster, True) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py index 641ddc75138..03a5877748a 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py @@ -44,9 +44,9 @@ def get_models(self, *attr_args, **kwargs): return get_sdk(self.cli_ctx, *attr_args, **kwargs) class TestLoadBalancer(unittest.TestCase): - cmd = mock.MagicMock() def test_configure_load_balancer_profile(self): + cmd = mock.MagicMock() managed_outbound_ip_count = 5 outbound_ips = None outbound_ip_prefixes = None diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py index 55f138d5287..1b7ea10198e 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py @@ -95,9 +95,9 @@ def test_IPv6(self): class TestClusterAutoscalerParamsValidators(unittest.TestCase): - cmd = mock.MagicMock() def test_empty_key_empty_value(self): + cmd = mock.MagicMock() cluster_autoscaler_profile = ["="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "Empty key specified for cluster-autoscaler-profile" @@ -107,12 +107,14 @@ def test_empty_key_empty_value(self): self.assertEqual(str(cm.exception), err) def test_non_empty_key_empty_value(self): + cmd = mock.MagicMock() cluster_autoscaler_profile = ["scan-interval="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) validators.validate_cluster_autoscaler_profile(cmd, namespace) def test_two_empty_keys_empty_value(self): + cmd = mock.MagicMock() cluster_autoscaler_profile = ["=", "="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "Empty key specified for cluster-autoscaler-profile" @@ -122,6 +124,7 @@ def test_two_empty_keys_empty_value(self): self.assertEqual(str(cm.exception), err) def test_one_empty_key_in_pair_one_non_empty(self): + cmd = mock.MagicMock() cluster_autoscaler_profile = ["scan-interval=20s", "="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "Empty key specified for cluster-autoscaler-profile" @@ -131,6 +134,7 @@ def test_one_empty_key_in_pair_one_non_empty(self): self.assertEqual(str(cm.exception), err) def test_invalid_key(self): + cmd = mock.MagicMock() cluster_autoscaler_profile = ["bad-key=val"] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "'bad-key' is an invalid key for cluster-autoscaler-profile" @@ -140,6 +144,7 @@ def test_invalid_key(self): self.assertIn(err, str(cm.exception),) def test_valid_parameters(self): + cmd = mock.MagicMock() cluster_autoscaler_profile = ["scan-interval=20s", "scale-down-delay-after-add=15m"] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) From c0ac58d3e5cde2f07f542e766e07ba60e5caa93c Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Sat, 5 Jun 2021 02:13:45 -0700 Subject: [PATCH 24/29] Modifying mock cmd --- src/azure-cli/azure/cli/command_modules/acs/_helpers.py | 6 +++--- src/azure-cli/azure/cli/command_modules/acs/_validators.py | 6 ++---- .../cli/command_modules/acs/tests/latest/test_helpers.py | 5 ++--- .../cli/command_modules/acs/tests/latest/test_validators.py | 6 ------ 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/_helpers.py index b3196aa153b..8a0f7639478 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_helpers.py @@ -6,7 +6,7 @@ from distutils.version import StrictVersion # pylint: disable=no-name-in-module,import-error # pylint: disable=no-name-in-module,import-error from knack.util import CLIError -from azure.cli.core.profiles import ResourceType + from ._consts import CONST_OUTBOUND_TYPE_LOAD_BALANCER, CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING @@ -14,8 +14,8 @@ def _populate_api_server_access_profile(cmd, api_server_authorized_ip_ranges, enable_private_cluster=False, instance=None): if instance is None or instance.api_server_access_profile is None: - ManagedClusterAPIServerAccessProfile = cmd.get_models('ManagedClusterAPIServerAccessProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterAPIServerAccessProfile = cmd.get_models( + 'containerservice.models#ManagedClusterAPIServerAccessProfile') profile = ManagedClusterAPIServerAccessProfile() else: profile = instance.api_server_access_profile diff --git a/src/azure-cli/azure/cli/command_modules/acs/_validators.py b/src/azure-cli/azure/cli/command_modules/acs/_validators.py index e61c299b66c..fe71e45974a 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_validators.py @@ -13,8 +13,6 @@ # pylint: disable=no-name-in-module,import-error from knack.log import get_logger -from azure.cli.core.profiles import ResourceType - from azure.cli.core.commands.validators import validate_tag from azure.cli.core.util import CLIError from azure.cli.core.azclierror import InvalidArgumentValueError @@ -123,8 +121,8 @@ def validate_cluster_autoscaler_profile(cmd, namespace): def _validate_cluster_autoscaler_key(cmd, key): if not key: raise CLIError('Empty key specified for cluster-autoscaler-profile') - ManagedClusterPropertiesAutoScalerProfile = cmd.get_models('ManagedClusterPropertiesAutoScalerProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ManagedClusterPropertiesAutoScalerProfile = cmd.get_models( + 'containerservice.models#ManagedClusterPropertiesAutoScalerProfile') valid_keys = list(k.replace("_", "-") for k, v in ManagedClusterPropertiesAutoScalerProfile._attribute_map.items()) # pylint: disable=protected-access if key not in valid_keys: raise CLIError("'{0}' is an invalid key for cluster-autoscaler-profile. " diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py index 88b10625db7..d8d18821818 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py @@ -41,21 +41,20 @@ def get_models(self, *attr_args, **kwargs): class TestPopulateApiServerAccessProfile(unittest.TestCase): + def setUp(self): + self.cli = MockCLI() def test_single_cidr_with_spaces(self): - cmd = mock.MagicMock() api_server_authorized_ip_ranges = "0.0.0.0/32 " profile = helpers._populate_api_server_access_profile(cmd, api_server_authorized_ip_ranges, enable_private_cluster=False) self.assertListEqual(profile.authorized_ip_ranges, ["0.0.0.0/32"]) def test_multi_cidr_with_spaces(self): - cmd = mock.MagicMock() api_server_authorized_ip_ranges = " 0.0.0.0/32 , 129.1.1.1/32" profile = helpers._populate_api_server_access_profile(cmd, api_server_authorized_ip_ranges, enable_private_cluster=False) self.assertListEqual(profile.authorized_ip_ranges, ["0.0.0.0/32", "129.1.1.1/32"]) def test_private_cluster(self): - cmd = mock.MagicMock() profile = helpers._populate_api_server_access_profile(cmd, None, enable_private_cluster=True) self.assertListEqual(profile.authorized_ip_ranges, []) self.assertEqual(profile.enable_private_cluster, True) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py index 1b7ea10198e..8d46a4aeb15 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py @@ -97,7 +97,6 @@ def test_IPv6(self): class TestClusterAutoscalerParamsValidators(unittest.TestCase): def test_empty_key_empty_value(self): - cmd = mock.MagicMock() cluster_autoscaler_profile = ["="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "Empty key specified for cluster-autoscaler-profile" @@ -107,14 +106,12 @@ def test_empty_key_empty_value(self): self.assertEqual(str(cm.exception), err) def test_non_empty_key_empty_value(self): - cmd = mock.MagicMock() cluster_autoscaler_profile = ["scan-interval="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) validators.validate_cluster_autoscaler_profile(cmd, namespace) def test_two_empty_keys_empty_value(self): - cmd = mock.MagicMock() cluster_autoscaler_profile = ["=", "="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "Empty key specified for cluster-autoscaler-profile" @@ -124,7 +121,6 @@ def test_two_empty_keys_empty_value(self): self.assertEqual(str(cm.exception), err) def test_one_empty_key_in_pair_one_non_empty(self): - cmd = mock.MagicMock() cluster_autoscaler_profile = ["scan-interval=20s", "="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "Empty key specified for cluster-autoscaler-profile" @@ -134,7 +130,6 @@ def test_one_empty_key_in_pair_one_non_empty(self): self.assertEqual(str(cm.exception), err) def test_invalid_key(self): - cmd = mock.MagicMock() cluster_autoscaler_profile = ["bad-key=val"] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) err = "'bad-key' is an invalid key for cluster-autoscaler-profile" @@ -144,7 +139,6 @@ def test_invalid_key(self): self.assertIn(err, str(cm.exception),) def test_valid_parameters(self): - cmd = mock.MagicMock() cluster_autoscaler_profile = ["scan-interval=20s", "scale-down-delay-after-add=15m"] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) From f1b643fed0296aa98330b72777fbf3dedba2ed72 Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Sat, 5 Jun 2021 03:33:57 -0700 Subject: [PATCH 25/29] Modifying acs mock cmd --- .../azure/cli/command_modules/acs/_helpers.py | 6 ++--- .../cli/command_modules/acs/_validators.py | 6 +++-- .../acs/tests/latest/test_helpers.py | 10 ++++---- .../acs/tests/latest/test_loadbalancer.py | 25 ------------------- 4 files changed, 12 insertions(+), 35 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/_helpers.py index 8a0f7639478..b3196aa153b 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_helpers.py @@ -6,7 +6,7 @@ from distutils.version import StrictVersion # pylint: disable=no-name-in-module,import-error # pylint: disable=no-name-in-module,import-error from knack.util import CLIError - +from azure.cli.core.profiles import ResourceType from ._consts import CONST_OUTBOUND_TYPE_LOAD_BALANCER, CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING @@ -14,8 +14,8 @@ def _populate_api_server_access_profile(cmd, api_server_authorized_ip_ranges, enable_private_cluster=False, instance=None): if instance is None or instance.api_server_access_profile is None: - ManagedClusterAPIServerAccessProfile = cmd.get_models( - 'containerservice.models#ManagedClusterAPIServerAccessProfile') + ManagedClusterAPIServerAccessProfile = cmd.get_models('ManagedClusterAPIServerAccessProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE) profile = ManagedClusterAPIServerAccessProfile() else: profile = instance.api_server_access_profile diff --git a/src/azure-cli/azure/cli/command_modules/acs/_validators.py b/src/azure-cli/azure/cli/command_modules/acs/_validators.py index fe71e45974a..e61c299b66c 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_validators.py @@ -13,6 +13,8 @@ # pylint: disable=no-name-in-module,import-error from knack.log import get_logger +from azure.cli.core.profiles import ResourceType + from azure.cli.core.commands.validators import validate_tag from azure.cli.core.util import CLIError from azure.cli.core.azclierror import InvalidArgumentValueError @@ -121,8 +123,8 @@ def validate_cluster_autoscaler_profile(cmd, namespace): def _validate_cluster_autoscaler_key(cmd, key): if not key: raise CLIError('Empty key specified for cluster-autoscaler-profile') - ManagedClusterPropertiesAutoScalerProfile = cmd.get_models( - 'containerservice.models#ManagedClusterPropertiesAutoScalerProfile') + ManagedClusterPropertiesAutoScalerProfile = cmd.get_models('ManagedClusterPropertiesAutoScalerProfile', + resource_type=ResourceType.MGMT_CONTAINERSERVICE) valid_keys = list(k.replace("_", "-") for k, v in ManagedClusterPropertiesAutoScalerProfile._attribute_map.items()) # pylint: disable=protected-access if key not in valid_keys: raise CLIError("'{0}' is an invalid key for cluster-autoscaler-profile. " diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py index d8d18821818..b16ec584b22 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py @@ -27,7 +27,7 @@ def __init__(self, ctx): def get_models(self, *attr_args, **_): from azure.cli.core.profiles import get_sdk - return get_sdk(self.ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, mod='models') + return get_sdk(self.ctx, ResourceType.MGMT_CONTAINERSERVICE, 'ManagedClusterAPIServerAccessProfile', mod='models') class MockCmd(object): @@ -37,7 +37,7 @@ def __init__(self, ctx, arguments={}): self.arguments = arguments def get_models(self, *attr_args, **kwargs): - return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, **kwargs) + return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, 'ManagedClusterAPIServerAccessProfile') class TestPopulateApiServerAccessProfile(unittest.TestCase): @@ -46,16 +46,16 @@ def setUp(self): def test_single_cidr_with_spaces(self): api_server_authorized_ip_ranges = "0.0.0.0/32 " - profile = helpers._populate_api_server_access_profile(cmd, api_server_authorized_ip_ranges, enable_private_cluster=False) + profile = helpers._populate_api_server_access_profile(MockCmd(self.cli), api_server_authorized_ip_ranges, enable_private_cluster=False) self.assertListEqual(profile.authorized_ip_ranges, ["0.0.0.0/32"]) def test_multi_cidr_with_spaces(self): api_server_authorized_ip_ranges = " 0.0.0.0/32 , 129.1.1.1/32" - profile = helpers._populate_api_server_access_profile(cmd, api_server_authorized_ip_ranges, enable_private_cluster=False) + profile = helpers._populate_api_server_access_profile(MockCmd(self.cli), api_server_authorized_ip_ranges, enable_private_cluster=False) self.assertListEqual(profile.authorized_ip_ranges, ["0.0.0.0/32", "129.1.1.1/32"]) def test_private_cluster(self): - profile = helpers._populate_api_server_access_profile(cmd, None, enable_private_cluster=True) + profile = helpers._populate_api_server_access_profile(MockCmd(self.cli), None, enable_private_cluster=True) self.assertListEqual(profile.authorized_ip_ranges, []) self.assertEqual(profile.enable_private_cluster, True) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py index 03a5877748a..3f7310f374e 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_loadbalancer.py @@ -18,31 +18,6 @@ from azure.cli.core.util import CLIError from azure.cli.command_modules.acs import _loadbalancer as loadbalancer -class MockCLI(CLI): - def __init__(self): - super(MockCLI, self).__init__(cli_name='mock_cli', config_dir=GLOBAL_CONFIG_DIR, - config_env_var_prefix=ENV_VAR_PREFIX, commands_loader_cls=MockLoader) - self.cloud = get_active_cloud(self) - - -class MockLoader(object): - def __init__(self, ctx): - self.ctx = ctx - - def get_models(self, *attr_args, **_): - from azure.cli.core.profiles import get_sdk - return get_sdk(self.ctx, *attr_args, mod='models') - - -class MockCmd(object): - def __init__(self, ctx, arguments={}): - self.cli_ctx = ctx - self.loader = MockLoader(self.cli_ctx) - self.arguments = arguments - - def get_models(self, *attr_args, **kwargs): - return get_sdk(self.cli_ctx, *attr_args, **kwargs) - class TestLoadBalancer(unittest.TestCase): def test_configure_load_balancer_profile(self): From e8eb6a0b0eddcf1d96f4962306949296addfb458 Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Sat, 5 Jun 2021 12:23:55 -0700 Subject: [PATCH 26/29] Adding operation_group to acs mock --- .../azure/cli/command_modules/acs/_helpers.py | 3 +- .../cli/command_modules/acs/_validators.py | 3 +- .../acs/tests/latest/test_custom.py | 73 ++++++++++++++----- .../acs/tests/latest/test_helpers.py | 6 +- .../acs/tests/latest/test_validators.py | 18 +++-- 5 files changed, 72 insertions(+), 31 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/_helpers.py index b3196aa153b..4ad75defd71 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_helpers.py @@ -15,7 +15,8 @@ def _populate_api_server_access_profile(cmd, enable_private_cluster=False, instance=None): if instance is None or instance.api_server_access_profile is None: ManagedClusterAPIServerAccessProfile = cmd.get_models('ManagedClusterAPIServerAccessProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') profile = ManagedClusterAPIServerAccessProfile() else: profile = instance.api_server_access_profile diff --git a/src/azure-cli/azure/cli/command_modules/acs/_validators.py b/src/azure-cli/azure/cli/command_modules/acs/_validators.py index e61c299b66c..7bca9a11186 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_validators.py @@ -124,7 +124,8 @@ def _validate_cluster_autoscaler_key(cmd, key): if not key: raise CLIError('Empty key specified for cluster-autoscaler-profile') ManagedClusterPropertiesAutoScalerProfile = cmd.get_models('ManagedClusterPropertiesAutoScalerProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') valid_keys = list(k.replace("_", "-") for k, v in ManagedClusterPropertiesAutoScalerProfile._attribute_map.items()) # pylint: disable=protected-access if key not in valid_keys: raise CLIError("'{0}' is an invalid key for cluster-autoscaler-profile. " 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 c85497a75f8..7fda73da664 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 @@ -13,6 +13,12 @@ import unittest import yaml +from knack import CLI + +from azure.cli.core._config import GLOBAL_CONFIG_DIR, ENV_VAR_PREFIX +from azure.cli.core.cloud import get_active_cloud +from azure.cli.core.profiles import get_sdk, ResourceType, supported_api_version + from msrestazure.azure_exceptions import CloudError from azure.graphrbac.models import GraphErrorException from azure.cli.command_modules.acs._params import (regions_in_preview, @@ -33,8 +39,37 @@ CONST_KUBE_DASHBOARD_ADDON_NAME, CONST_AZURE_POLICY_ADDON_NAME) +class MockCLI(CLI): + def __init__(self): + super(MockCLI, self).__init__(cli_name='mock_cli', config_dir=GLOBAL_CONFIG_DIR, + config_env_var_prefix=ENV_VAR_PREFIX, commands_loader_cls=MockLoader) + self.cloud = get_active_cloud(self) + + +class MockLoader(object): + def __init__(self, ctx): + self.ctx = ctx + + def get_models(self, *attr_args, **_): + from azure.cli.core.profiles import get_sdk + return get_sdk(self.ctx, ResourceType.MGMT_CONTAINERSERVICE, 'ManagedClusterAddonProfile', + mod='models', operation_group='managed_clusters') + + +class MockCmd(object): + def __init__(self, ctx, arguments={}): + self.cli_ctx = ctx + self.loader = MockLoader(self.cli_ctx) + self.arguments = arguments + + def get_models(self, *attr_args, **kwargs): + return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, 'ManagedClusterAddonProfile', + operation_group='managed_clusters') class AcsCustomCommandTest(unittest.TestCase): + def setUp(self): + self.cli = MockCLI() + def test_list_acs_locations(self): client, cmd = mock.MagicMock(), mock.MagicMock() regions = list_acs_locations(client, cmd) @@ -590,21 +625,21 @@ def test_update_addons(self, rg_def, cf_resource_groups, cf_resources): # http_application_routing enabled instance = mock.MagicMock() instance.addon_profiles = None - cmd = mock.MagicMock() - instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', + + 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) addon_profile = instance.addon_profiles[CONST_HTTP_APPLICATION_ROUTING_ADDON_NAME] self.assertTrue(addon_profile.enabled) # http_application_routing disabled - instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', + instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'http_application_routing', enable=False) addon_profile = instance.addon_profiles[CONST_HTTP_APPLICATION_ROUTING_ADDON_NAME] self.assertFalse(addon_profile.enabled) # monitoring added - instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', + instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'monitoring', enable=True) monitoring_addon_profile = instance.addon_profiles[CONST_MONITORING_ADDON_NAME] self.assertTrue(monitoring_addon_profile.enabled) @@ -612,9 +647,9 @@ def test_update_addons(self, rg_def, cf_resource_groups, cf_resources): self.assertFalse(routing_addon_profile.enabled) # monitoring disabled, routing enabled - instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', + instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'monitoring', enable=False) - instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', + instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'http_application_routing', enable=True) monitoring_addon_profile = instance.addon_profiles[CONST_MONITORING_ADDON_NAME] self.assertFalse(monitoring_addon_profile.enabled) @@ -623,7 +658,7 @@ def test_update_addons(self, rg_def, cf_resource_groups, cf_resources): self.assertEqual(sorted(list(instance.addon_profiles)), [CONST_HTTP_APPLICATION_ROUTING_ADDON_NAME, CONST_MONITORING_ADDON_NAME]) # azurepolicy added - instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', + instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'azure-policy', enable=True) azurepolicy_addon_profile = instance.addon_profiles[CONST_AZURE_POLICY_ADDON_NAME] self.assertTrue(azurepolicy_addon_profile.enabled) @@ -633,9 +668,9 @@ def test_update_addons(self, rg_def, cf_resource_groups, cf_resources): self.assertFalse(monitoring_addon_profile.enabled) # azurepolicy disabled, routing enabled - instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', + instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'azure-policy', enable=False) - instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', + instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'http_application_routing', enable=True) azurepolicy_addon_profile = instance.addon_profiles[CONST_AZURE_POLICY_ADDON_NAME] self.assertFalse(azurepolicy_addon_profile.enabled) @@ -646,14 +681,14 @@ def test_update_addons(self, rg_def, cf_resource_groups, cf_resources): self.assertEqual(sorted(list(instance.addon_profiles)), [CONST_AZURE_POLICY_ADDON_NAME, CONST_HTTP_APPLICATION_ROUTING_ADDON_NAME, CONST_MONITORING_ADDON_NAME]) # kube-dashboard disabled, no existing dashboard addon profile - instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', + instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'kube-dashboard', enable=False) dashboard_addon_profile = instance.addon_profiles[CONST_KUBE_DASHBOARD_ADDON_NAME] self.assertFalse(dashboard_addon_profile.enabled) # kube-dashboard enabled, no existing dashboard addon profile instance.addon_profiles.pop(CONST_KUBE_DASHBOARD_ADDON_NAME, None) - instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', + instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'kube-dashboard', enable=True) dashboard_addon_profile = instance.addon_profiles[CONST_KUBE_DASHBOARD_ADDON_NAME] self.assertTrue(dashboard_addon_profile.enabled) @@ -662,7 +697,7 @@ def test_update_addons(self, rg_def, cf_resource_groups, cf_resources): instance.addon_profiles.pop(CONST_KUBE_DASHBOARD_ADDON_NAME, None) # test lower cased key name instance.addon_profiles['kubedashboard'] = ManagedClusterAddonProfile(enabled=True) - instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', + instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'kube-dashboard', enable=False) dashboard_addon_profile = instance.addon_profiles[CONST_KUBE_DASHBOARD_ADDON_NAME] self.assertFalse(dashboard_addon_profile.enabled) @@ -671,7 +706,7 @@ def test_update_addons(self, rg_def, cf_resource_groups, cf_resources): instance.addon_profiles.pop(CONST_KUBE_DASHBOARD_ADDON_NAME, None) # test lower cased key name instance.addon_profiles['kubedashboard'] = ManagedClusterAddonProfile(enabled=False) - instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', + instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'kube-dashboard', enable=True) dashboard_addon_profile = instance.addon_profiles[CONST_KUBE_DASHBOARD_ADDON_NAME] self.assertTrue(dashboard_addon_profile.enabled) @@ -679,24 +714,24 @@ def test_update_addons(self, rg_def, cf_resource_groups, cf_resources): # monitoring enabled and then enabled again should error instance = mock.Mock() instance.addon_profiles = None - instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', + instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'monitoring', enable=True) with self.assertRaises(CLIError): - instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', + instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'monitoring', enable=True) # virtual-node enabled instance = mock.MagicMock() instance.addon_profiles = None cmd = mock.MagicMock() - instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', + instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'virtual-node', enable=True, subnet_name='foo') self.assertIn('aciConnectorLinux', instance.addon_profiles) addon_profile = instance.addon_profiles['aciConnectorLinux'] self.assertTrue(addon_profile.enabled) # virtual-node disabled - instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', + instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'virtual-node', enable=False) addon_profile = instance.addon_profiles['aciConnectorLinux'] self.assertFalse(addon_profile.enabled) @@ -705,14 +740,14 @@ def test_update_addons(self, rg_def, cf_resource_groups, cf_resources): instance = mock.MagicMock() instance.addon_profiles = None cmd = mock.MagicMock() - instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', + instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'ingress-appgw', enable=True, appgw_subnet_cidr='10.2.0.0/16') self.assertIn('ingressApplicationGateway', instance.addon_profiles) addon_profile = instance.addon_profiles['ingressApplicationGateway'] self.assertTrue(addon_profile.enabled) # ingress-appgw disabled - instance = _update_addons(cmd, instance, '00000000-0000-0000-0000-000000000000', + instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000', 'clitest000001', 'clitest000001', 'ingress-appgw', enable=False) addon_profile = instance.addon_profiles['ingressApplicationGateway'] self.assertFalse(addon_profile.enabled) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py index b16ec584b22..c7a2f84b64e 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py @@ -27,7 +27,8 @@ def __init__(self, ctx): def get_models(self, *attr_args, **_): from azure.cli.core.profiles import get_sdk - return get_sdk(self.ctx, ResourceType.MGMT_CONTAINERSERVICE, 'ManagedClusterAPIServerAccessProfile', mod='models') + return get_sdk(self.ctx, ResourceType.MGMT_CONTAINERSERVICE, 'ManagedClusterAPIServerAccessProfile', + mod='models', operation_group='managed_clusters') class MockCmd(object): @@ -37,7 +38,8 @@ def __init__(self, ctx, arguments={}): self.arguments = arguments def get_models(self, *attr_args, **kwargs): - return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, 'ManagedClusterAPIServerAccessProfile') + return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, 'ManagedClusterAPIServerAccessProfile', + operation_group='managed_clusters') class TestPopulateApiServerAccessProfile(unittest.TestCase): diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py index 8d46a4aeb15..e02d256c23e 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py @@ -27,7 +27,8 @@ def __init__(self, ctx): def get_models(self, *attr_args, **_): from azure.cli.core.profiles import get_sdk - return get_sdk(self.ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, mod='models') + return get_sdk(self.ctx, ResourceType.MGMT_CONTAINERSERVICE, 'ManagedClusterPropertiesAutoScalerProfile', + mod='models', operation_group='managed_clusters') class MockCmd(object): @@ -37,7 +38,8 @@ def __init__(self, ctx, arguments={}): self.arguments = arguments def get_models(self, *attr_args, **kwargs): - return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, *attr_args, **kwargs) + return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, 'ManagedClusterPropertiesAutoScalerProfile', + operation_group='managed_clusters') class TestValidateIPRanges(unittest.TestCase): @@ -102,14 +104,14 @@ def test_empty_key_empty_value(self): err = "Empty key specified for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(cmd, namespace) + validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) self.assertEqual(str(cm.exception), err) def test_non_empty_key_empty_value(self): cluster_autoscaler_profile = ["scan-interval="] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) - validators.validate_cluster_autoscaler_profile(cmd, namespace) + validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) def test_two_empty_keys_empty_value(self): cluster_autoscaler_profile = ["=", "="] @@ -117,7 +119,7 @@ def test_two_empty_keys_empty_value(self): err = "Empty key specified for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(cmd, namespace) + validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) self.assertEqual(str(cm.exception), err) def test_one_empty_key_in_pair_one_non_empty(self): @@ -126,7 +128,7 @@ def test_one_empty_key_in_pair_one_non_empty(self): err = "Empty key specified for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(cmd, namespace) + validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) self.assertEqual(str(cm.exception), err) def test_invalid_key(self): @@ -135,14 +137,14 @@ def test_invalid_key(self): err = "'bad-key' is an invalid key for cluster-autoscaler-profile" with self.assertRaises(CLIError) as cm: - validators.validate_cluster_autoscaler_profile(cmd, namespace) + validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) self.assertIn(err, str(cm.exception),) def test_valid_parameters(self): cluster_autoscaler_profile = ["scan-interval=20s", "scale-down-delay-after-add=15m"] namespace = Namespace(cluster_autoscaler_profile=cluster_autoscaler_profile) - validators.validate_cluster_autoscaler_profile(cmd, namespace) + validators.validate_cluster_autoscaler_profile(MockCmd(self.cli), namespace) class Namespace: From fed1fc106fac2735c058398e0fb3d7a5ce6a8d20 Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Sat, 5 Jun 2021 16:04:21 -0700 Subject: [PATCH 27/29] Adding mod=models for acs mock cmd --- .../azure/cli/command_modules/acs/tests/latest/test_custom.py | 2 +- .../cli/command_modules/acs/tests/latest/test_helpers.py | 2 +- .../cli/command_modules/acs/tests/latest/test_validators.py | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) 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 7fda73da664..ceb605d7a3e 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 @@ -64,7 +64,7 @@ def __init__(self, ctx, arguments={}): def get_models(self, *attr_args, **kwargs): return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, 'ManagedClusterAddonProfile', - operation_group='managed_clusters') + mod='models', operation_group='managed_clusters') class AcsCustomCommandTest(unittest.TestCase): def setUp(self): diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py index c7a2f84b64e..a8dc8fff7c4 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py @@ -39,7 +39,7 @@ def __init__(self, ctx, arguments={}): def get_models(self, *attr_args, **kwargs): return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, 'ManagedClusterAPIServerAccessProfile', - operation_group='managed_clusters') + mod='models', operation_group='managed_clusters') class TestPopulateApiServerAccessProfile(unittest.TestCase): diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py index e02d256c23e..1df8d527c3e 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py @@ -39,7 +39,7 @@ def __init__(self, ctx, arguments={}): def get_models(self, *attr_args, **kwargs): return get_sdk(self.cli_ctx, ResourceType.MGMT_CONTAINERSERVICE, 'ManagedClusterPropertiesAutoScalerProfile', - operation_group='managed_clusters') + mod='models', operation_group='managed_clusters') class TestValidateIPRanges(unittest.TestCase): @@ -97,6 +97,8 @@ def test_IPv6(self): class TestClusterAutoscalerParamsValidators(unittest.TestCase): + def setUp(self): + self.cli = MockCLI() def test_empty_key_empty_value(self): cluster_autoscaler_profile = ["="] From bc7c74a3d114b6d0ae1cc7ae632582f81c718c18 Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Tue, 15 Jun 2021 00:43:27 -0700 Subject: [PATCH 28/29] removing redundant operation_group properties --- .../azure/cli/command_modules/acs/commands.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/commands.py b/src/azure-cli/azure/cli/command_modules/acs/commands.py index f391e3eafbc..6f83b5a903c 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/commands.py +++ b/src/azure-cli/azure/cli/command_modules/acs/commands.py @@ -80,7 +80,6 @@ def load_command_table(self, _): # ACS Kubernetes commands with self.command_group('acs kubernetes', container_services_sdk, - resource_type=ResourceType.MGMT_CONTAINERSERVICE, client_factory=cf_container_services) as g: g.custom_command('browse', 'k8s_browse') g.custom_command('get-credentials', 'k8s_get_credentials') @@ -88,8 +87,7 @@ def load_command_table(self, _): # AKS commands with self.command_group('aks', managed_clusters_sdk, - resource_type=ResourceType.MGMT_CONTAINERSERVICE, - operation_group='managed_clusters', client_factory=cf_managed_clusters) as g: + client_factory=cf_managed_clusters) as g: g.custom_command('browse', 'aks_browse') g.custom_command('create', 'aks_create', supports_no_wait=True) g.custom_command('update', 'aks_update', supports_no_wait=True) @@ -118,9 +116,9 @@ def load_command_table(self, _): g.custom_command('rotate-certs', 'aks_rotate_certs', supports_no_wait=True, confirmation='Kubernetes will be unavailable during certificate rotation process.\n' + 'Are you sure you want to perform this operation?') - g.wait_command('wait', operation_group='managed_clusters') - g.command('stop', 'stop', supports_no_wait=True, min_api='2020-09-01', client_factory=cf_managed_clusters) - g.command('start', 'start', supports_no_wait=True, min_api='2020-09-01', client_factory=cf_managed_clusters) + g.wait_command('wait') + g.command('stop', 'stop', supports_no_wait=True, min_api='2020-09-01') + g.command('start', 'start', supports_no_wait=True, min_api='2020-09-01') with self.command_group('aks', container_services_sdk, client_factory=cf_container_services) as g: g.custom_command('get-versions', 'aks_get_versions', From 668ad412103d8ee44619cffd876afc0e05c83644 Mon Sep 17 00:00:00 2001 From: Bhuvaneswari Santharam Date: Tue, 15 Jun 2021 02:00:29 -0700 Subject: [PATCH 29/29] Adding operation_group to acs loadbalancer --- .../cli/command_modules/acs/_loadbalancer.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py b/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py index de4776dc409..887d37aa9d9 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py @@ -42,7 +42,8 @@ def create_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, o return None ManagedClusterLoadBalancerProfile = cmd.get_models('ManagedClusterLoadBalancerProfile', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') profile = ManagedClusterLoadBalancerProfile() return configure_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, outbound_ports, idle_timeout, profile) @@ -65,21 +66,24 @@ def configure_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips if managed_outbound_ip_count: ManagedClusterLoadBalancerProfileManagedOutboundIPs = cmd.get_models( 'ManagedClusterLoadBalancerProfileManagedOutboundIPs', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') profile.managed_outbound_ips = ManagedClusterLoadBalancerProfileManagedOutboundIPs( count=managed_outbound_ip_count ) if outbound_ip_resources: ManagedClusterLoadBalancerProfileOutboundIPs = cmd.get_models( 'ManagedClusterLoadBalancerProfileOutboundIPs', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') profile.outbound_ips = ManagedClusterLoadBalancerProfileOutboundIPs( public_ips=outbound_ip_resources ) if outbound_ip_prefix_resources: ManagedClusterLoadBalancerProfileOutboundIPPrefixes = cmd.get_models( 'ManagedClusterLoadBalancerProfileOutboundIPPrefixes', - resource_type=ResourceType.MGMT_CONTAINERSERVICE) + resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') profile.outbound_ip_prefixes = ManagedClusterLoadBalancerProfileOutboundIPPrefixes( public_ip_prefixes=outbound_ip_prefix_resources ) @@ -102,7 +106,8 @@ def is_load_balancer_profile_provided(managed_outbound_ip_count, outbound_ips, i def _get_load_balancer_outbound_ips(cmd, load_balancer_outbound_ips): """parse load balancer profile outbound IP ids and return an array of references to the outbound IP resources""" load_balancer_outbound_ip_resources = None - ResourceReference = cmd.get_models('ResourceReference', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ResourceReference = cmd.get_models('ResourceReference', resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') if load_balancer_outbound_ips: load_balancer_outbound_ip_resources = \ [ResourceReference(id=x.strip()) @@ -114,7 +119,8 @@ def _get_load_balancer_outbound_ip_prefixes(cmd, load_balancer_outbound_ip_prefi """parse load balancer profile outbound IP prefix ids and return an array \ of references to the outbound IP prefix resources""" load_balancer_outbound_ip_prefix_resources = None - ResourceReference = cmd.get_models('ResourceReference', resource_type=ResourceType.MGMT_CONTAINERSERVICE) + ResourceReference = cmd.get_models('ResourceReference', resource_type=ResourceType.MGMT_CONTAINERSERVICE, + operation_group='managed_clusters') if load_balancer_outbound_ip_prefixes: load_balancer_outbound_ip_prefix_resources = \ [ResourceReference(id=x.strip())