Skip to content

Commit a0e9c6a

Browse files
authored
{RDBMS} Update Python SDK for PostgreSQL flexible servers to stable version API to 2024-08-01 (#30151)
* Update to azure-mgmt-postgresqlflexibleservers * Update test * mitigate subprocess security issue and update tests * Update tests * retry test after merge
1 parent 5076a27 commit a0e9c6a

41 files changed

Lines changed: 87033 additions & 67763 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def get_postgresql_management_client(cli_ctx, **_):
111111

112112
def get_postgresql_flexible_management_client(cli_ctx, subscription_id=None, **_):
113113
from os import getenv
114-
from azure.mgmt.rdbms.postgresql_flexibleservers import PostgreSQLManagementClient
114+
from azure.mgmt.postgresqlflexibleservers import PostgreSQLManagementClient
115115
# Allow overriding resource manager URI using environment variable
116116
# for testing purposes. Subscription id is also determined by environment
117117
# variable.

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from knack.log import get_logger
1717
from knack.prompting import prompt_y_n, NoTTYException
1818
from azure.mgmt.core.tools import parse_resource_id
19-
from azure.cli.core.util import CLIError
19+
from azure.cli.core.util import CLIError, run_cmd
2020
from azure.cli.core.azclierror import AuthenticationError
2121
from azure.core.exceptions import HttpResponseError
2222
from azure.core.paging import ItemPaged
@@ -325,13 +325,6 @@ def run_subprocess(command, stdout_show=None):
325325
logger.warning(process.stderr.read().strip().decode('UTF-8'))
326326

327327

328-
def run_subprocess_get_output(command):
329-
commands = command.split()
330-
process = subprocess.Popen(commands, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
331-
process.wait()
332-
return process
333-
334-
335328
def register_credential_secrets(cmd, database_engine, server, repository):
336329
logger.warning('Adding secret "AZURE_CREDENTIALS" to github repository')
337330
resource_group = parse_resource_id(server.id)["resource_group"]
@@ -375,8 +368,8 @@ def fill_action_template(cmd, database_engine, server, database_name, administra
375368
if not os.path.exists(action_dir):
376369
os.makedirs(action_dir)
377370

378-
process = run_subprocess_get_output("gh secret list --repo {}".format(repository))
379-
github_secrets = process.stdout.read().strip().decode('UTF-8')
371+
process = run_cmd(["gh", "secret", "list", "--repo", repository], capture_output=True)
372+
github_secrets = process.stdout.strip().decode('UTF-8')
380373
# connection_string = AZURE_POSTGRESQL_CONNECTION_STRING if database_engine == 'postgresql' else AZURE_MYSQL_CONNECTION_STRING
381374

382375
if AZURE_CREDENTIALS not in github_secrets:
@@ -417,8 +410,8 @@ def fill_action_template(cmd, database_engine, server, database_name, administra
417410

418411

419412
def get_git_root_dir():
420-
process = run_subprocess_get_output("git rev-parse --show-toplevel")
421-
return process.stdout.read().strip().decode('UTF-8')
413+
process = run_cmd(["git", "rev-parse", "--show-toplevel"], capture_output=True)
414+
return process.stdout.strip().decode('UTF-8')
422415

423416

424417
def get_user_confirmation(message, yes=False):

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@
3939
def load_flexibleserver_command_table(self, _):
4040
# Flexible server SDKs:
4141
postgres_flexible_servers_sdk = CliCommandType(
42-
operations_tmpl='azure.mgmt.rdbms.postgresql_flexibleservers.operations#ServersOperations.{}',
42+
operations_tmpl='azure.mgmt.postgresqlflexibleservers.operations#ServersOperations.{}',
4343
client_factory=cf_postgres_flexible_servers
4444
)
4545

4646
postgres_flexible_firewall_rule_sdk = CliCommandType(
47-
operations_tmpl='azure.mgmt.rdbms.postgresql_flexibleservers.operations#FirewallRulesOperations.{}',
47+
operations_tmpl='azure.mgmt.postgresqlflexibleservers.operations#FirewallRulesOperations.{}',
4848
client_factory=cf_postgres_flexible_firewall_rules
4949
)
5050

5151
postgres_flexible_config_sdk = CliCommandType(
52-
operations_tmpl='azure.mgmt.rdbms.postgresql_flexibleservers.operations#ConfigurationsOperations.{}',
52+
operations_tmpl='azure.mgmt.postgresqlflexibleservers.operations#ConfigurationsOperations.{}',
5353
client_factory=cf_postgres_flexible_config
5454
)
5555

5656
postgres_flexible_db_sdk = CliCommandType(
57-
operations_tmpl='azure.mgmt.rdbms.postgresql_flexibleservers.operations#DatabasesOperations.{}',
57+
operations_tmpl='azure.mgmt.postgresqlflexibleservers.operations#DatabasesOperations.{}',
5858
client_factory=cf_postgres_flexible_db
5959
)
6060

@@ -64,52 +64,52 @@ def load_flexibleserver_command_table(self, _):
6464
)
6565

6666
postgres_flexible_backups_sdk = CliCommandType(
67-
operations_tmpl='azure.mgmt.rdbms.postgresql_flexibleservers.operations#BackupsOperations.{}',
67+
operations_tmpl='azure.mgmt.postgresqlflexibleservers.operations#BackupsOperations.{}',
6868
client_factory=cf_postgres_flexible_backups
6969
)
7070

7171
postgres_flexible_replica_sdk = CliCommandType(
72-
operations_tmpl='azure.mgmt.rdbms.postgresql_flexibleservers.operations#ReplicasOperations.{}',
72+
operations_tmpl='azure.mgmt.postgresqlflexibleservers.operations#ReplicasOperations.{}',
7373
client_factory=cf_postgres_flexible_replica
7474
)
7575

7676
postgres_flexible_adadmin_sdk = CliCommandType(
77-
operations_tmpl='azure.mgmt.rdbms.postgresql_flexibleservers.operations#AdministratorsOperations.{}',
77+
operations_tmpl='azure.mgmt.postgresqlflexibleservers.operations#AdministratorsOperations.{}',
7878
client_factory=cf_postgres_flexible_adadmin
7979
)
8080

8181
postgres_flexible_migrations_sdk = CliCommandType(
82-
operations_tmpl='azure.mgmt.rdbms.postgresql_flexibleservers.operations#MigrationsOperations.{}',
82+
operations_tmpl='azure.mgmt.postgresqlflexibleservers.operations#MigrationsOperations.{}',
8383
client_factory=cf_postgres_flexible_migrations
8484
)
8585

8686
postgres_flexible_virtual_endpoints_sdk = CliCommandType(
87-
operations_tmpl='azure.mgmt.rdbms.postgresql_flexibleservers.operations#VirtualEndpointsOperations.{}',
87+
operations_tmpl='azure.mgmt.postgresqlflexibleservers.operations#VirtualEndpointsOperations.{}',
8888
client_factory=cf_postgres_flexible_virtual_endpoints
8989
)
9090

9191
postgres_flexible_server_threat_protection_settings_sdk = CliCommandType(
92-
operations_tmpl='azure.mgmt.rdbms.postgresql_flexibleservers.operations#ServerThreatProtectionSettingsOperations.{}',
92+
operations_tmpl='azure.mgmt.postgresqlflexibleservers.operations#ServerThreatProtectionSettingsOperations.{}',
9393
client_factory=cf_postgres_flexible_server_threat_protection_settings
9494
)
9595

9696
postgres_flexible_server_log_files_sdk = CliCommandType(
97-
operations_tmpl='azure.mgmt.rdbms.postgresql_flexibleservers.operations#LogFilesOperations.{}',
97+
operations_tmpl='azure.mgmt.postgresqlflexibleservers.operations#LogFilesOperations.{}',
9898
client_factory=cf_postgres_flexible_server_log_files
9999
)
100100

101101
postgres_flexible_server_private_endpoint_connection_sdk = CliCommandType(
102-
operations_tmpl='azure.mgmt.rdbms.postgresql_flexibleservers.operations#PrivateEndpointConnectionOperations.{}',
102+
operations_tmpl='azure.mgmt.postgresqlflexibleservers.operations#PrivateEndpointConnectionOperations.{}',
103103
client_factory=cf_postgres_flexible_private_endpoint_connection
104104
)
105105

106106
postgres_flexible_server_private_endpoint_connections_sdk = CliCommandType(
107-
operations_tmpl='azure.mgmt.rdbms.postgresql_flexibleservers.operations#PrivateEndpointConnectionsOperations.{}',
107+
operations_tmpl='azure.mgmt.postgresqlflexibleservers.operations#PrivateEndpointConnectionsOperations.{}',
108108
client_factory=cf_postgres_flexible_private_endpoint_connections
109109
)
110110

111111
postgres_flexible_server_private_link_resources_sdk = CliCommandType(
112-
operations_tmpl='azure.mgmt.rdbms.postgresql_flexibleservers.operations#PrivateLinkResourcesOperations.{}',
112+
operations_tmpl='azure.mgmt.postgresqlflexibleservers.operations#PrivateLinkResourcesOperations.{}',
113113
client_factory=cf_postgres_flexible_private_link_resources
114114
)
115115

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
from knack.log import get_logger
1212
from knack.util import CLIError
1313
from urllib.request import urlretrieve
14-
from azure.cli.core.util import sdk_no_wait
15-
from azure.cli.core.util import user_confirmation
14+
from azure.cli.core.util import sdk_no_wait, user_confirmation, run_cmd
1615
from azure.cli.core.azclierror import ClientRequestError, RequiredArgumentMissingError
1716
from ._client_factory import cf_postgres_flexible_replica
18-
from ._flexible_server_util import run_subprocess, run_subprocess_get_output, \
17+
from ._flexible_server_util import run_subprocess, \
1918
fill_action_template, get_git_root_dir, resolve_poller, GITHUB_ACTION_PATH
2019
from .validators import validate_public_access_server, validate_resource_group, check_resource_group
2120

@@ -228,11 +227,11 @@ def github_actions_run(action_name, branch):
228227

229228

230229
def gitcli_check_and_login():
231-
output = run_subprocess_get_output("gh")
230+
output = run_cmd(["gh"], capture_output=True)
232231
if output.returncode:
233232
raise ClientRequestError('Please install "Github CLI" to run this command.')
234233

235-
output = run_subprocess_get_output("gh auth status")
234+
output = run_cmd(["gh", "auth", "status"], capture_output=True)
236235
if output.returncode:
237236
run_subprocess("gh auth login", stdout_show=True)
238237

src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/migrationOnPremise.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
"sourceServerPassword": "XXXXXXXXX",
77
"targetServerPassword": "XXXXXXXXX"
88
},
9-
"targetServerUsername": "target_user"
9+
"targetServerUsername": "portaltestuser"
1010
},
1111
"dbsToMigrate": [
12-
"dvdrental"
12+
"postgres"
1313
],
1414
"overwriteDbsinTarget": "true",
1515
"sourceType": "OnPremises",
1616
"sslMode": "Prefer"
1717
},
18-
"location": "eastus"
18+
"location": "eastus2euap"
1919
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
22
"properties": {
3-
"sourceDbServerResourceId": "/subscriptions/5c5037e5-d3f1-4e7b-b3a9-f6bf94902b30/resourceGroups/Sterling2MeruRG/providers/Microsoft.DBforPostgreSQL/servers/source-server-longhaul",
3+
"sourceDbServerResourceId": "/subscriptions/ac0271d6-426b-4b0d-b88d-0d0e4bd693ae/resourceGroups/autobot-singleserver-resourcegroup/providers/Microsoft.DBforPostgreSQL/servers/autobot-orcas-postgresql-ss",
44
"secretParameters": {
55
"adminCredentials": {
66
"sourceServerPassword": "XXXXXXXXX",
77
"targetServerPassword": "XXXXXXXXX"
88
},
9-
"sourceServerUsername": "migration_user@source-server-longhaul",
10-
"targetServerUsername": "target_user"
9+
"sourceServerUsername": "autobot@autobot-orcas-postgresql-ss",
10+
"targetServerUsername": "portaltestuser"
1111
},
1212
"dbsToMigrate": [
13-
"dvdrental"
13+
"postgres"
1414
],
1515
"setupLogicalReplicationOnSourceDbIfNeeded": "false",
1616
"overwriteDbsinTarget": "true"
1717
},
18-
"location": "eastus"
18+
"location": "eastus2euap"
1919
}

0 commit comments

Comments
 (0)