diff --git a/src/spring/HISTORY.md b/src/spring/HISTORY.md index f44daad424e..21773824bbb 100644 --- a/src/spring/HISTORY.md +++ b/src/spring/HISTORY.md @@ -6,6 +6,7 @@ Release History * Add new argument `--server-version` in `az spring app deploy` and `az spring app deployment create` to support WAR file deployment in Standard tier. * Add argument `--enable-auto-sync` in `az spring certificate add`. * Add new command `az spring certificate update` to update a certificate. +* Add new command `az spring list-support-server-versions` to list all supported server versions. 1.14.3 --- diff --git a/src/spring/azext_spring/_help.py b/src/spring/azext_spring/_help.py index 64d9acc58f1..a03a6795993 100644 --- a/src/spring/azext_spring/_help.py +++ b/src/spring/azext_spring/_help.py @@ -49,6 +49,14 @@ text: az spring list-marketplace-plan -o table """ +helps['spring list-support-server-versions'] = """ + type: command + short-summary: (Standard and Basic Tier Only) List supported server versions. + examples: + - name: List supported server versions. + text: az spring list-support-server-versions -o table -s MyService -g MyResourceGroup +""" + helps['spring update'] = """ type: command short-summary: Update an Azure Spring Apps. diff --git a/src/spring/azext_spring/_params.py b/src/spring/azext_spring/_params.py index e982d36fd3a..30ed5a2c872 100644 --- a/src/spring/azext_spring/_params.py +++ b/src/spring/azext_spring/_params.py @@ -31,7 +31,7 @@ validate_acs_ssh_or_warn, validate_apm_properties, validate_apm_secrets, validate_apm_not_exist, validate_apm_update, validate_apm_reference, validate_apm_reference_and_enterprise_tier, validate_cert_reference, - validate_build_cert_reference, validate_acs_create) + validate_build_cert_reference, validate_acs_create, not_support_enterprise) from ._app_validator import (fulfill_deployment_param, active_deployment_exist, ensure_not_active_deployment, validate_deloy_path, validate_deloyment_create_path, validate_cpu, validate_build_cpu, validate_memory, validate_build_memory, @@ -259,6 +259,9 @@ def load_arguments(self, _): c.argument('type', type=str, arg_type=get_enum_type( TestKeyType), help='Type of test-endpoint key') + with self.argument_context('spring list-support-server-versions') as c: + c.argument('service', service_name_type, validator=not_support_enterprise) + with self.argument_context('spring app') as c: c.argument('service', service_name_type) c.argument('name', name_type, help='The name of app running in the specified Azure Spring Apps instance.') @@ -528,7 +531,7 @@ def prepare_logs_argument(c): c.argument('build_certificates', nargs='*', help='(Enterprise Tier Only) Space-separated certificate names, the certificates are used during build time.', validator=validate_build_cert_reference) - c.argument('server_version', help='(Standard and Basic Tiers Only) Tomcat server version. This feature is in public preview.', validator=validate_server_version) + c.argument('server_version', help='(Standard and Basic Tiers Only) Tomcat server version. List all supported server versions by running `az spring list-support-server-versions -o table`. This feature is in public preview.', validator=validate_server_version) with self.argument_context('spring app deploy') as c: c.argument('source_path', arg_type=source_path_type, validator=validate_deloy_path) diff --git a/src/spring/azext_spring/_transformers.py b/src/spring/azext_spring/_transformers.py index 34be143d271..2bafb3d8001 100644 --- a/src/spring/azext_spring/_transformers.py +++ b/src/spring/azext_spring/_transformers.py @@ -365,3 +365,17 @@ def transform_apm_type_output(result): item['Name'] = item['name'] return result if is_list else result[0] + + +def transform_support_server_versions_output(result): + is_list = isinstance(result, list) + + if not is_list: + result = [result] + + for item in result: + item['Value'] = item['value'] + item['Server'] = item['server'] + item['Version'] = item['version'] + + return result if is_list else result[0] diff --git a/src/spring/azext_spring/commands.py b/src/spring/azext_spring/commands.py index eb3a042b0a3..1fe265aa24d 100644 --- a/src/spring/azext_spring/commands.py +++ b/src/spring/azext_spring/commands.py @@ -27,7 +27,8 @@ transform_build_result_output, transform_apm_output, transform_apm_type_output, - transform_container_registry_output) + transform_container_registry_output, + transform_support_server_versions_output) from ._validators import validate_app_insights_command_not_supported_tier from ._marketplace import (transform_marketplace_plan_output) from ._validators_enterprise import (validate_gateway_update, validate_api_portal_update, validate_dev_tool_portal, validate_customized_accelerator, validate_central_build_instance) @@ -123,6 +124,9 @@ def load_command_table(self, _): g.custom_command('list-marketplace-plan', 'spring_list_marketplace_plan', is_preview=True, table_transformer=transform_marketplace_plan_output) + g.custom_command('list-support-server-versions', 'spring_list_support_server_versions', + is_preview=True, + table_transformer=transform_support_server_versions_output) with self.command_group('spring', client_factory=cf_spring, exception_handler=handle_asc_exception) as g: diff --git a/src/spring/azext_spring/spring_instance.py b/src/spring/azext_spring/spring_instance.py index 0009b1fb8fe..c5510fa01f5 100644 --- a/src/spring/azext_spring/spring_instance.py +++ b/src/spring/azext_spring/spring_instance.py @@ -263,3 +263,7 @@ def _enable_app_insights(cmd, client, resource_group, name, location, app_insigh def spring_list_marketplace_plan(cmd, client): return _spring_list_marketplace_plan(cmd, client) + + +def spring_list_support_server_versions(cmd, client, resource_group, service): + return client.services.list_supported_server_versions(resource_group, service) diff --git a/src/spring/azext_spring/tests/latest/recordings/test_list_support_server_versions.yaml b/src/spring/azext_spring/tests/latest/recordings/test_list_support_server_versions.yaml new file mode 100644 index 00000000000..a17478dfb77 --- /dev/null +++ b/src/spring/azext_spring/tests/latest/recordings/test_list_support_server_versions.yaml @@ -0,0 +1,100 @@ +interactions: +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - spring list-support-server-versions + Connection: + - keep-alive + ParameterSetName: + - -g -s + User-Agent: + - AZURECLI/2.52.0 azsdk-python-mgmt-appplatform/6.1.0 Python/3.8.10 (Windows-10-10.0.22621-SP0) + method: GET + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.AppPlatform/Spring/clitest000002?api-version=2023-09-01-preview + response: + body: + string: '{"properties":{"provisioningState":"Succeeded","zoneRedundant":false,"version":3,"serviceId":"56e88126a961459ca367bb6223cf4a16","networkProfile":{"outboundIPs":{"publicIPs":["20.219.181.209","20.219.183.20"]},"outboundType":"loadBalancer"},"powerState":"Running","fqdn":"clitest000002.azuremicroservices.io"},"type":"Microsoft.AppPlatform/Spring","sku":{"name":"S0","tier":"Standard"},"location":"centralindia","tags":{},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.AppPlatform/Spring/clitest000002","name":"clitest000002","systemData":{"createdBy":"pensh@microsoft.com","createdByType":"User","createdAt":"2023-03-23T02:52:58.6146926Z","lastModifiedBy":"pensh@microsoft.com","lastModifiedByType":"User","lastModifiedAt":"2023-03-23T02:57:49.439147Z"}}' + headers: + cache-control: + - no-cache + content-length: + - '817' + content-type: + - application/json; charset=utf-8 + date: + - Sat, 16 Sep 2023 03:09:06 GMT + expires: + - '-1' + pragma: + - no-cache + request-context: + - appId=cid-v1:797d7e4e-8180-497e-a254-780fbd39ba4d + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-resource-requests: + - '11999' + x-rp-server-mvid: + - a6ee70bd-e6ad-4c20-a59d-a8ecffac8ef4 + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - spring list-support-server-versions + Connection: + - keep-alive + ParameterSetName: + - -g -s + User-Agent: + - AZURECLI/2.52.0 azsdk-python-mgmt-appplatform/6.1.0 Python/3.8.10 (Windows-10-10.0.22621-SP0) + method: GET + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.AppPlatform/Spring/clitest000002/supportedServerVersions?api-version=2023-09-01-preview + response: + body: + string: '{"value":[{"value":"Tomcat_9","server":"Tomcat","version":"9"},{"value":"Tomcat_10","server":"Tomcat","version":"10"}]}' + headers: + cache-control: + - no-cache + content-length: + - '119' + content-type: + - application/json; charset=utf-8 + date: + - Sat, 16 Sep 2023 03:09:07 GMT + expires: + - '-1' + pragma: + - no-cache + request-context: + - appId=cid-v1:797d7e4e-8180-497e-a254-780fbd39ba4d + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + x-rp-server-mvid: + - a6ee70bd-e6ad-4c20-a59d-a8ecffac8ef4 + status: + code: 200 + message: OK +version: 1 diff --git a/src/spring/azext_spring/tests/latest/test_asa_server_version.py b/src/spring/azext_spring/tests/latest/test_asa_server_version.py new file mode 100644 index 00000000000..62c386c81c9 --- /dev/null +++ b/src/spring/azext_spring/tests/latest/test_asa_server_version.py @@ -0,0 +1,45 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +# pylint: disable=line-too-long +# pylint: disable=too-many-lines + +from azure.cli.testsdk import (ScenarioTest) +from azure.cli.testsdk.reverse_dependency import ( + get_dummy_cli, +) + +from .custom_dev_setting_constant import SpringTestEnvironmentEnum +from .custom_preparers import (SpringPreparer, SpringResourceGroupPreparer, SpringSubResourceWrapper) + + +class TearDown(SpringSubResourceWrapper): + def __init__(self, + resource_group_parameter_name='resource_group', + spring_parameter_name='spring'): + super(TearDown, self).__init__() + self.cli_ctx = get_dummy_cli() + self.resource_group_parameter_name = resource_group_parameter_name + self.spring_parameter_name = spring_parameter_name + + def create_resource(self, *_, **kwargs): + self.resource_group = self._get_resource_group(**kwargs) + self.spring = self._get_spring(**kwargs) + + +class ServerVersionTest(ScenarioTest): + + @SpringResourceGroupPreparer( + dev_setting_name=SpringTestEnvironmentEnum.STANDARD['resource_group_name']) + @SpringPreparer(**SpringTestEnvironmentEnum.STANDARD['spring']) + @TearDown() + def test_list_support_server_versions(self, resource_group, spring): + + self.kwargs.update({ + 'serviceName': spring, + 'rg': resource_group, + }) + results = self.cmd('spring list-support-server-versions -g {rg} -s {serviceName}').get_output_in_json() + self.assertTrue(len(results) > 0)