From d1e9a502a0e13af688fdbab3c1f8d1363dcd050b Mon Sep 17 00:00:00 2001 From: Keyan Song Date: Fri, 30 Oct 2026 19:13:14 -0700 Subject: [PATCH 1/4] [Batch] Update outdated help text and examples; remove dead code - `az batch pool create`: remove the Cloud Services Configuration text (Cloud Services pools retired on 2024-02-29). `--image` now describes Azure Compute Gallery image IDs (VHD and managed image pools retired on 2026-03-31) and uses an Ubuntu 24.04 example instead of Windows Server 2012 R2 (retired). Add an example that creates a pool with arguments. - `az batch pool supported-images list`: explain that a Batch account is needed and add examples (#31201). - `az batch account create/set`: show the example key identifier in `--encryption-key-identifier` as code, so reference docs don't treat it as a link (#29622). - Remove unused code: certificate validators, the node agent SKU table formatter, and a Cloud Services parameter entry. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../azure/cli/command_modules/batch/_format.py | 13 ------------- .../azure/cli/command_modules/batch/_help.py | 15 +++++++++++++-- .../command_modules/batch/_parameter_format.py | 1 - .../azure/cli/command_modules/batch/_params.py | 6 +++--- .../cli/command_modules/batch/_validators.py | 16 ---------------- 5 files changed, 16 insertions(+), 35 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/batch/_format.py b/src/azure-cli/azure/cli/command_modules/batch/_format.py index 5675eaffdef..f60815e3c21 100644 --- a/src/azure-cli/azure/cli/command_modules/batch/_format.py +++ b/src/azure-cli/azure/cli/command_modules/batch/_format.py @@ -168,19 +168,6 @@ def node_list_table_format(result): return table_output -def pool_node_agent_skus_list_table_format(result): - """Format pool node-agent-skus list as a table.""" - table_output = [] - for item in result: - table_row = OrderedDict() - table_row['Agent Id'] = item.get('id', None) - table_row['Publisher'] = item.get('publisher', None) - table_row['Offer'] = item.get('offer', None) - table_row['Sku'] = item.get('sku', None) - table_output.append(table_row) - return table_output - - def pool_list_table_format(result): """Format pool list as a table.""" table_output = [] diff --git a/src/azure-cli/azure/cli/command_modules/batch/_help.py b/src/azure-cli/azure/cli/command_modules/batch/_help.py index bca4a1d2a49..0b669318f41 100644 --- a/src/azure-cli/azure/cli/command_modules/batch/_help.py +++ b/src/azure-cli/azure/cli/command_modules/batch/_help.py @@ -533,11 +533,14 @@ helps['batch pool create'] = """ type: command -short-summary: Create a Batch pool in an account. When creating a pool, choose arguments from either Cloud Services Configuration or Virtual Machine Configuration. +short-summary: Create a Batch pool in an account. examples: - - name: Create a Batch pool in an account. When creating a pool, choose arguments from either Cloud Services Configuration or Virtual Machine Configuration. + - name: Create a Batch pool from a JSON file. text: > az batch pool create --json-file batch-pool-create.json --account-name clibatch --account-key BatchAccountKey + - name: Create a Batch pool of two Ubuntu 24.04 compute nodes. + text: > + az batch pool create --id mypool --vm-size Standard_D4ds_v5 --target-dedicated-nodes 2 --image canonical:ubuntu-24_04-lts:server --node-agent-sku-id "batch.node.ubuntu 24.04" --account-name clibatch --account-key BatchAccountKey """ helps['batch pool node-counts'] = """ @@ -568,6 +571,14 @@ helps['batch pool supported-images list'] = """ type: command short-summary: Lists all Virtual Machine Images supported by the Azure Batch service. +long-summary: This command needs a Batch account. Select one with 'az batch account login', or pass --account-name and --account-endpoint (and --account-key for Shared Key authentication). +examples: + - name: List the images supported by the Batch account selected with 'az batch account login'. + text: > + az batch pool supported-images list + - name: List the images supported by a Batch account, using your 'az login' credentials (Microsoft Entra ID). + text: > + az batch pool supported-images list --account-name mybatchaccount --account-endpoint https://mybatchaccount.eastus.batch.azure.com """ helps['batch pool usage-metrics'] = """ diff --git a/src/azure-cli/azure/cli/command_modules/batch/_parameter_format.py b/src/azure-cli/azure/cli/command_modules/batch/_parameter_format.py index 50d689a28de..edf0862fac5 100644 --- a/src/azure-cli/azure/cli/command_modules/batch/_parameter_format.py +++ b/src/azure-cli/azure/cli/command_modules/batch/_parameter_format.py @@ -86,7 +86,6 @@ 'network_configuration.public_ip_address_configuration', 'network_configuration.subnet_id', 'enable_auto_scale', - 'cloud_service_configuration.target_os_version', 'pool.auto_scale_evaluation_interval', # 'pool.start_task.environment_settings', # 'pool.start_task.max_task_retry_count', diff --git a/src/azure-cli/azure/cli/command_modules/batch/_params.py b/src/azure-cli/azure/cli/command_modules/batch/_params.py index f5d5fbe2f20..43846047899 100644 --- a/src/azure-cli/azure/cli/command_modules/batch/_params.py +++ b/src/azure-cli/azure/cli/command_modules/batch/_params.py @@ -85,7 +85,7 @@ def load_arguments(self, _): c.argument('public_network_access', help="The network access type for accessing Azure Batch account. Values can either be enabled or disabled.", arg_type=get_enum_type(PublicNetworkAccessType)) c.argument('encryption_key_source', help='Part of the encryption configuration for the Batch account. Type of the key source. Can be either Microsoft.Batch or Microsoft.KeyVault', arg_type=get_enum_type(KeySource)) c.argument('encryption_key_identifier', help='Part of the encryption configuration for the Batch account. ' - 'Full path to the versioned secret. Example https://mykeyvault.vault.azure.net/keys/testkey/6e34a81fef704045975661e297a4c053.') + 'Full path to the versioned secret. Example: `https://mykeyvault.vault.azure.net/keys/testkey/6e34a81fef704045975661e297a4c053`.') c.argument('identity_type', help="The type of identity used for the Batch account. Possible values include: 'SystemAssigned', 'None'.", arg_type=get_enum_type(ResourceIdentityType), deprecate_info=c.deprecate(hide=True)) c.argument('mi_user_assigned', help='Resource ID of the user assigned identity for the batch services account.', arg_group='Identity') c.argument('mi_system_assigned', help='Set the system managed identity on the batch services account.', arg_group='Identity') @@ -96,7 +96,7 @@ def load_arguments(self, _): c.argument('storage_account', help='The storage account name or resource ID to be used for auto storage.', validator=storage_account_id) c.argument('encryption_key_source', help='Part of the encryption configuration for the Batch account. Type of the key source. Can be either Microsoft.Batch or Microsoft.KeyVault') c.argument('public_network_access', help="The network access type for accessing Azure Batch account. Values can either be enabled or disabled.", arg_type=get_enum_type(PublicNetworkAccessType)) - c.argument('encryption_key_identifier', help='Part of the encryption configuration for the Batch account. Full path to the versioned secret. Example https://mykeyvault.vault.azure.net/keys/testkey/6e34a81fef704045975661e297a4c053.') + c.argument('encryption_key_identifier', help='Part of the encryption configuration for the Batch account. Full path to the versioned secret. Example: `https://mykeyvault.vault.azure.net/keys/testkey/6e34a81fef704045975661e297a4c053`.') c.argument('identity_type', help="The type of identity used for the Batch account. Possible values include: 'SystemAssigned', 'None'.", arg_type=get_enum_type(ResourceIdentityType), deprecate_info=c.deprecate(hide=True)) with self.argument_context('batch account identity assign') as c: @@ -419,7 +419,7 @@ def load_arguments(self, _): arg_group="Pool: Virtual Machine Configuration", help='A space separated list of DiskEncryptionTargets. current possible values include OsDisk and TemporaryDisk.', type=disk_encryption_configuration_format) c.extra('image', completer=load_supported_images, arg_group="Pool: Virtual Machine Configuration", - help="OS image reference. This can be either 'publisher:offer:sku[:version]' format, or a fully qualified ARM image id of the form '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/images/{imageName}'. If 'publisher:offer:sku[:version]' format, version is optional and if omitted latest will be used. Valid values can be retrieved via 'az batch pool supported-images list'. For example: 'MicrosoftWindowsServer:WindowsServer:2012-R2-Datacenter:latest'") + help="OS image reference. This can be either 'publisher:offer:sku[:version]' format, or the ARM resource identifier of an Azure Compute Gallery image of the form '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/galleries/{galleryName}/images/{imageDefinitionName}[/versions/{versionId}]'. If 'publisher:offer:sku[:version]' format, version is optional and if omitted latest will be used. Valid values can be retrieved via 'az batch pool supported-images list'. For example: 'canonical:ubuntu-24_04-lts:server'") c.argument('mode', options_list=['--upgrade-policy-mode'], help='The mode of the pool OS upgrade.') c.argument('enable_cross_zone_upgrade', arg_type=get_three_state_flag()) c.argument('prioritize_unhealthy_instances', arg_type=get_three_state_flag()) diff --git a/src/azure-cli/azure/cli/command_modules/batch/_validators.py b/src/azure-cli/azure/cli/command_modules/batch/_validators.py index b39b8d6472b..970f2c5f89b 100644 --- a/src/azure-cli/azure/cli/command_modules/batch/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/batch/_validators.py @@ -216,15 +216,6 @@ def validate_json_file(namespace): raise ValueError(f"Invalid JSON file: {err}") -def validate_cert_file(namespace): - """Validate the give cert file existing""" - try: - with open(namespace.certificate_file, "rb"): - pass - except OSError: - raise ValueError("Cannot access certificate file: " + namespace.certificate_file) - - def validate_options(namespace): """Validate any flattened request header option arguments.""" try: @@ -296,13 +287,6 @@ def validate_pool_settings(namespace, _): namespace.enable_auto_scale = True -def validate_cert_settings(namespace): - """Custom parsing for certificate commands - adds default thumbprint - algorithm. - """ - namespace.thumbprint_algorithm = 'sha1' - - def validate_client_parameters(cmd, namespace): """Retrieves Batch connection parameters from environment variables""" from azure.mgmt.batch import BatchManagementClient From 5704ffd078c4d4337979ff4110bf9bc922e3fb67 Mon Sep 17 00:00:00 2001 From: Keyan Song Date: Mon, 2 Nov 2026 14:05:34 -0800 Subject: [PATCH 2/4] {Batch} Add --account-endpoint to the az batch pool create examples Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/azure-cli/azure/cli/command_modules/batch/_help.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/batch/_help.py b/src/azure-cli/azure/cli/command_modules/batch/_help.py index 0b669318f41..5916f11b328 100644 --- a/src/azure-cli/azure/cli/command_modules/batch/_help.py +++ b/src/azure-cli/azure/cli/command_modules/batch/_help.py @@ -537,10 +537,10 @@ examples: - name: Create a Batch pool from a JSON file. text: > - az batch pool create --json-file batch-pool-create.json --account-name clibatch --account-key BatchAccountKey + az batch pool create --json-file batch-pool-create.json --account-name clibatch --account-key BatchAccountKey --account-endpoint https://clibatch.eastus.batch.azure.com - name: Create a Batch pool of two Ubuntu 24.04 compute nodes. text: > - az batch pool create --id mypool --vm-size Standard_D4ds_v5 --target-dedicated-nodes 2 --image canonical:ubuntu-24_04-lts:server --node-agent-sku-id "batch.node.ubuntu 24.04" --account-name clibatch --account-key BatchAccountKey + az batch pool create --id mypool --vm-size Standard_D4ds_v5 --target-dedicated-nodes 2 --image canonical:ubuntu-24_04-lts:server --node-agent-sku-id "batch.node.ubuntu 24.04" --account-name clibatch --account-key BatchAccountKey --account-endpoint https://clibatch.eastus.batch.azure.com """ helps['batch pool node-counts'] = """ From 7b740a12b679ec4ad3b6079dd18de533bf27d761 Mon Sep 17 00:00:00 2001 From: Keyan Song Date: Mon, 2 Nov 2026 14:28:16 -0800 Subject: [PATCH 3/4] {Batch} Remove leftover identity_type argument settings --identity-type was removed from az batch account create/set in #23032 (Jul 2022); these settings had no effect. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/azure-cli/azure/cli/command_modules/batch/_params.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/batch/_params.py b/src/azure-cli/azure/cli/command_modules/batch/_params.py index 43846047899..18753cc25aa 100644 --- a/src/azure-cli/azure/cli/command_modules/batch/_params.py +++ b/src/azure-cli/azure/cli/command_modules/batch/_params.py @@ -12,7 +12,6 @@ AccountKeyType, KeySource, PublicNetworkAccessType, - ResourceIdentityType, EndpointAccessDefaultAction) from azure.batch.models import ( CachingType, @@ -86,7 +85,6 @@ def load_arguments(self, _): c.argument('encryption_key_source', help='Part of the encryption configuration for the Batch account. Type of the key source. Can be either Microsoft.Batch or Microsoft.KeyVault', arg_type=get_enum_type(KeySource)) c.argument('encryption_key_identifier', help='Part of the encryption configuration for the Batch account. ' 'Full path to the versioned secret. Example: `https://mykeyvault.vault.azure.net/keys/testkey/6e34a81fef704045975661e297a4c053`.') - c.argument('identity_type', help="The type of identity used for the Batch account. Possible values include: 'SystemAssigned', 'None'.", arg_type=get_enum_type(ResourceIdentityType), deprecate_info=c.deprecate(hide=True)) c.argument('mi_user_assigned', help='Resource ID of the user assigned identity for the batch services account.', arg_group='Identity') c.argument('mi_system_assigned', help='Set the system managed identity on the batch services account.', arg_group='Identity') c.ignore('keyvault_url') @@ -97,7 +95,6 @@ def load_arguments(self, _): c.argument('encryption_key_source', help='Part of the encryption configuration for the Batch account. Type of the key source. Can be either Microsoft.Batch or Microsoft.KeyVault') c.argument('public_network_access', help="The network access type for accessing Azure Batch account. Values can either be enabled or disabled.", arg_type=get_enum_type(PublicNetworkAccessType)) c.argument('encryption_key_identifier', help='Part of the encryption configuration for the Batch account. Full path to the versioned secret. Example: `https://mykeyvault.vault.azure.net/keys/testkey/6e34a81fef704045975661e297a4c053`.') - c.argument('identity_type', help="The type of identity used for the Batch account. Possible values include: 'SystemAssigned', 'None'.", arg_type=get_enum_type(ResourceIdentityType), deprecate_info=c.deprecate(hide=True)) with self.argument_context('batch account identity assign') as c: c.argument('resource_group_name', resource_group_name_type, help='Name of the resource group. If not specified will display currently set account.') From e0de3033336a47b53b91da765c5f4a0faabd22cb Mon Sep 17 00:00:00 2001 From: Keyan Song Date: Wed, 4 Nov 2026 10:17:37 -0800 Subject: [PATCH 4/4] {Batch} Add mocked tests for the new az batch pool create examples Run the two-node Ubuntu 24.04 example through az batch pool create with the SDK's create_pool mocked and check the pool request. Check the missing-endpoint error with Batch environment variables and config cleared. Check that versioned and versionless Azure Compute Gallery image IDs reach virtualMachineImageId unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../batch/tests/latest/test_batch_commands.py | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/azure-cli/azure/cli/command_modules/batch/tests/latest/test_batch_commands.py b/src/azure-cli/azure/cli/command_modules/batch/tests/latest/test_batch_commands.py index 6d8a89eeffd..92fba4e2b9d 100644 --- a/src/azure-cli/azure/cli/command_modules/batch/tests/latest/test_batch_commands.py +++ b/src/azure-cli/azure/cli/command_modules/batch/tests/latest/test_batch_commands.py @@ -18,11 +18,13 @@ from azure.core import MatchConditions #from azure.batch._client import BatchClientOperationsMixin from azure.batch import models, BatchClient +from azure.batch._operations._patch import BatchClientOperationsMixin from azure.core.credentials import AzureNamedKeyCredential from azure.cli.core.mock import DummyCli from azure.cli.command_modules.batch import _validators from azure.cli.command_modules.batch import _command_type +from azure.cli.core.util import rmtree_with_retry class TestObj: # pylint: disable=too-few-public-methods @@ -775,3 +777,65 @@ def test_batch_task_create_environment_settings(self): self.assertEqual(exit_code, 2) create_task.assert_not_called() + + +class TestBatchPoolCreate(unittest.TestCase): + """Run 'az batch pool create' with the SDK's create_pool mocked, so nothing is sent to the service.""" + + # The "two Ubuntu 24.04 compute nodes" example in the 'az batch pool create' help + EXAMPLE_ARGS = ['batch', 'pool', 'create', '--id', 'mypool', '--vm-size', 'Standard_D4ds_v5', + '--target-dedicated-nodes', '2', '--image', 'canonical:ubuntu-24_04-lts:server', + '--node-agent-sku-id', 'batch.node.ubuntu 24.04', + '--account-name', 'clibatch', '--account-key', 'BatchAccountKey'] + ENDPOINT_ARGS = ['--account-endpoint', 'https://clibatch.eastus.batch.azure.com'] + + def setUp(self): + # No Batch settings from AZURE_BATCH_* environment variables or the CLI config + environ = {name: value for name, value in os.environ.items() if not name.startswith('AZURE_BATCH_')} + environ_patch = mock.patch.dict(os.environ, environ, clear=True) + environ_patch.start() + self.addCleanup(environ_patch.stop) + self.cli = DummyCli(random_config_dir=True) + self.addCleanup(self.cli.env_patch.stop) + self.addCleanup(rmtree_with_retry, self.cli.config.config_dir) + + # The CLI builds the command's arguments from the SDK method's docstring, so the mock keeps it + docstring = BatchClientOperationsMixin.create_pool.__doc__ + create_pool_patch = mock.patch.object(BatchClientOperationsMixin, 'create_pool', autospec=True, + return_value=None) + self.create_pool = create_pool_patch.start() + self.addCleanup(create_pool_patch.stop) + self.create_pool.__doc__ = docstring + + def test_batch_pool_create_missing_endpoint(self): + with self.assertLogs('cli.azure.cli.core.azclierror', 'ERROR') as logs, \ + self.assertRaises(SystemExit) as ex: + self.cli.invoke(self.EXAMPLE_ARGS, out_file=io.StringIO()) + self.assertEqual(ex.exception.code, 2) + self.assertIn('Specify batch endpoint in command line or environment variable.', + [record.getMessage() for record in logs.records]) + self.create_pool.assert_not_called() + + def test_batch_pool_create_ubuntu_example(self): + self.assertEqual(self.cli.invoke(self.EXAMPLE_ARGS + self.ENDPOINT_ARGS, out_file=io.StringIO()), 0) + self.create_pool.assert_called_once() + # The CLI passes the --target-dedicated-nodes value on as a string; the service accepts it + self.assertEqual(self.create_pool.call_args.kwargs['pool'], { + 'id': 'mypool', + 'vmSize': 'Standard_D4ds_v5', + 'targetDedicatedNodes': '2', + 'virtualMachineConfiguration': { + 'imageReference': {'publisher': 'canonical', 'offer': 'ubuntu-24_04-lts', 'sku': 'server'}, + 'nodeAgentSKUId': 'batch.node.ubuntu 24.04'}}) + + def test_batch_pool_create_gallery_image(self): + image = ('/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myresourcegroup/providers/' + 'Microsoft.Compute/galleries/mygallery/images/myimage') + for image_id in [image, image + '/versions/1.0.0']: + with self.subTest(image_id=image_id): + args = self.EXAMPLE_ARGS + self.ENDPOINT_ARGS + args[args.index('--image') + 1] = image_id + self.assertEqual(self.cli.invoke(args, out_file=io.StringIO()), 0) + self.assertEqual(self.create_pool.call_args.kwargs['pool']['virtualMachineConfiguration'], { + 'imageReference': {'virtualMachineImageId': image_id}, + 'nodeAgentSKUId': 'batch.node.ubuntu 24.04'})