Skip to content

Commit e8c56c9

Browse files
author
Matthew Boentoro
committed
[RDBMS] az postgres flexible-server upgrade: Add server capability API check to the --version parameter
1 parent c25c29d commit e8c56c9

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/azure-cli/azure/cli/command_modules/rdbms/_flexible_server_location_capabilities_util.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from azure.cli.core.azclierror import InvalidArgumentValueError
88
from azure.core.paging import ItemPaged
99
from ._client_factory import cf_postgres_flexible_location_capabilities, cf_postgres_flexible_server_capabilities
10-
10+
from collections import defaultdict
1111

1212
def get_postgres_location_capability_info(cmd, location):
1313
list_location_capability_client = cf_postgres_flexible_location_capabilities(cmd.cli_ctx, '_')
@@ -98,13 +98,18 @@ def _postgres_parse_list_capability(result):
9898
versions = set()
9999
for version in result[0].supported_server_versions:
100100
versions.add(version.name)
101+
102+
supported_server_versions = defaultdict(list)
103+
for version in result[0].supported_server_versions:
104+
supported_server_versions[version.name] = version.supported_versions_to_upgrade
101105

102106
return {
103107
'sku_info': tiers_dict,
104108
'single_az': single_az,
105109
'geo_backup_supported': geo_backup_supported,
106110
'zones': zones,
107111
'server_versions': versions,
112+
'supported_server_versions': supported_server_versions,
108113
'index_tuning_supported': index_tuning_supported
109114
}
110115

src/azure-cli/azure/cli/command_modules/rdbms/_params.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,6 @@ def _flexible_server_params(command_group):
459459
)
460460

461461
pg_version_upgrade_arg_type = CLIArgumentType(
462-
arg_type=get_enum_type(['12', '13', '14', '15', '16']),
463462
options_list=['--version', '-v'],
464463
help='Server major version.'
465464
)

src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from ._client_factory import cf_postgres_flexible_replica
1717
from ._flexible_server_util import run_subprocess, \
1818
fill_action_template, get_git_root_dir, resolve_poller, GITHUB_ACTION_PATH
19+
from ._flexible_server_location_capabilities_util import get_postgres_server_capability_info
1920
from .validators import validate_public_access_server, validate_resource_group, check_resource_group, validate_citus_cluster
2021

2122
logger = get_logger(__name__)
@@ -303,6 +304,20 @@ def flexible_server_version_upgrade(cmd, client, resource_group_name, server_nam
303304
"the option to select version 12 will be removed in the near future. "
304305
"We recommend selecting PostgreSQL 13 or a later version for "
305306
"all future operations.")
307+
308+
list_server_capability_info = get_postgres_server_capability_info(cmd, resource_group_name, server_name)
309+
eligible_versions = list_server_capability_info['supported_server_versions'][str(current_version)]
310+
if version not in eligible_versions:
311+
error_message = ""
312+
if len(eligible_versions) > 0:
313+
error_message = "The version to upgrade to must be one of the supported versions for the current server version from this list: {}. ".format(eligible_versions)
314+
else:
315+
error_message = "Your server is up-to-date with the latest version. "
316+
317+
if "17" in eligible_versions:
318+
error_message += "Note that version 17 is still in preview."
319+
raise CLIError(error_message)
320+
306321

307322
replica_operations_client = cf_postgres_flexible_replica(cmd.cli_ctx, '_')
308323
version_mapped = version

0 commit comments

Comments
 (0)