-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[POSTGRESQL] az postgres flexible-server restore: Add --sku-name and --tier arguments to allow changing compute during point-in-time restore
#33992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Gabriel Lobo (thegabrielobo)
wants to merge
1
commit into
Azure:dev
Choose a base branch
from
thegabrielobo:pg-flex-restore-sku
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
.../cli/command_modules/postgresql/tests/latest/test_postgres_flexible_restore_sku_params.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| import inspect | ||
| import unittest | ||
| from unittest import mock | ||
|
|
||
| from azure.cli.core.azclierror import ValidationError | ||
| from azure.cli.core.mock import DummyCli | ||
| from azure.cli.command_modules.postgresql import PostgreSQLCommandsLoader | ||
| from azure.cli.command_modules.postgresql.commands.custom_commands import flexible_server_restore | ||
| from azure.cli.command_modules.postgresql.utils.validators import pg_restore_tier_validator | ||
|
|
||
| RESTORE_COMMAND = 'postgres flexible-server restore' | ||
|
|
||
| # Shape mirrors the 'sku_info' entry returned by get_postgres_location_capability_info. | ||
| SKU_INFO = { | ||
| 'Burstable': {'skus': {'Standard_B1ms', 'Standard_B2s'}}, | ||
| 'GeneralPurpose': {'skus': {'Standard_D2s_v3', 'Standard_D4s_v3'}}, | ||
| 'MemoryOptimized': {'skus': {'Standard_E2ds_v4', 'Standard_E4ds_v4'}}, | ||
| } | ||
|
|
||
|
|
||
| def _load_command_and_arguments(command): | ||
| cli = DummyCli(commands_loader_cls=PostgreSQLCommandsLoader) | ||
| loader = PostgreSQLCommandsLoader(cli) | ||
| cli.invocation = mock.MagicMock() | ||
| cli.invocation.commands_loader = loader | ||
| loader.command_name = command | ||
| loader.load_command_table(None) | ||
| loader.load_arguments(command) | ||
| loader._update_command_definitions() | ||
| return loader | ||
|
|
||
|
|
||
| class RestoreSkuArgumentsTest(unittest.TestCase): | ||
| """`az postgres flexible-server restore` must expose --sku-name and --tier.""" | ||
|
|
||
| def test_sku_name_and_tier_are_registered(self): | ||
| loader = _load_command_and_arguments(RESTORE_COMMAND) | ||
| arguments = loader.argument_registry.arguments.get(RESTORE_COMMAND, {}) | ||
|
|
||
| for dest, option in (('sku_name', '--sku-name'), ('tier', '--tier')): | ||
| arg = arguments.get(dest) | ||
| self.assertIsNotNone(arg, "'{}' not found in argument registry".format(dest)) | ||
| self.assertIn(option, arg.settings.get('options_list')) | ||
|
|
||
| def test_registered_arguments_are_accepted_by_the_custom_command(self): | ||
| """An argument registered for a dest the custom command does not accept is silently dropped.""" | ||
| loader = _load_command_and_arguments(RESTORE_COMMAND) | ||
| accepted = set(inspect.signature(flexible_server_restore).parameters) | ||
| registered = set(loader.argument_registry.arguments.get(RESTORE_COMMAND, {})) | ||
|
|
||
| self.assertEqual(registered - accepted, set()) | ||
|
|
||
|
|
||
| class RestoreTierValidatorTest(unittest.TestCase): | ||
|
|
||
| def test_upgrading_tier_is_allowed(self): | ||
| pg_restore_tier_validator('MemoryOptimized', 'GeneralPurpose', SKU_INFO) | ||
|
|
||
| def test_same_tier_is_allowed(self): | ||
| pg_restore_tier_validator('GeneralPurpose', 'GeneralPurpose', SKU_INFO) | ||
|
|
||
| def test_downgrading_tier_is_rejected(self): | ||
| with self.assertRaises(ValidationError) as context: | ||
| pg_restore_tier_validator('GeneralPurpose', 'MemoryOptimized', SKU_INFO) | ||
| self.assertIn('must not go below the source server compute tier', str(context.exception)) | ||
|
|
||
| def test_downgrading_to_burstable_is_rejected(self): | ||
| with self.assertRaises(ValidationError): | ||
| pg_restore_tier_validator('Burstable', 'GeneralPurpose', SKU_INFO) | ||
|
|
||
| def test_unknown_tier_is_rejected(self): | ||
| with self.assertRaises(Exception) as context: | ||
| pg_restore_tier_validator('NotATier', 'GeneralPurpose', SKU_INFO) | ||
| self.assertIn('Invalid value for --tier', str(context.exception)) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead add new args to restore test already in project and re-record results