diff --git a/src/azure-cli/azure/cli/command_modules/postgresql/commands/migration_commands.py b/src/azure-cli/azure/cli/command_modules/postgresql/commands/migration_commands.py index 038759a9f69..85e4285ecd6 100644 --- a/src/azure-cli/azure/cli/command_modules/postgresql/commands/migration_commands.py +++ b/src/azure-cli/azure/cli/command_modules/postgresql/commands/migration_commands.py @@ -145,7 +145,7 @@ def migration_update_func(cmd, client, resource_group_name, server_name, migrati migration_resource = migration_show_func(cmd, client, resource_group_name, server_name, migration_name) if migration_resource.migration_mode == "Offline": raise BadRequestError("Cutover is not possible for migration {} if the migration_mode set to offline. The migration will cutover automatically".format(migration_name)) - parameters = postgresql_flexibleservers.models.MigrationResourceForPatch(trigger_cutover="True", dbs_to_trigger_cutover_migration_on=migration_resource.dbs_to_migrate) + parameters = postgresql_flexibleservers.models.MigrationResourceForPatch(trigger_cutover="True", dbs_to_trigger_cutover_on=migration_resource.dbs_to_migrate) if cancel is not None: if operationSpecified is True: diff --git a/src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_migration_commands.py b/src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_migration_commands.py new file mode 100644 index 00000000000..70fd347ee67 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_migration_commands.py @@ -0,0 +1,40 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +import unittest +from unittest.mock import MagicMock, patch + +from azure.cli.command_modules.postgresql.commands import migration_commands +from azure.mgmt.postgresqlflexibleservers.models import Migration + + +class MigrationCommandsTest(unittest.TestCase): + + def test_postgresql_migration_cutover_submits_all_databases(self): + cmd = MagicMock() + client = MagicMock() + client.get.return_value = Migration( + location='eastus', + migration_mode='Online', + dbs_to_migrate=['db1', 'db2'], + ) + + with patch.object(migration_commands, 'validate_citus_cluster'): + result = migration_commands.migration_update_func( + cmd, client, 'test-rg', 'test-server', 'test-migration', cutover=True, + ) + + client.get.assert_called_once_with('test-rg', 'test-server', 'test-migration') + client.update.assert_called_once() + resource_group, server_name, migration_name, parameters = client.update.call_args.args + self.assertEqual((resource_group, server_name, migration_name), + ('test-rg', 'test-server', 'test-migration')) + self.assertEqual(parameters.as_dict(), { + 'properties': { + 'triggerCutover': 'True', + 'dbsToTriggerCutoverOn': ['db1', 'db2'], + }, + }) + self.assertIs(result, client.update.return_value)