From a52beacaa6fcc11d48f5b742c73aa2c0f87634ce Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 20 Jan 2021 10:19:19 +0000 Subject: [PATCH] compute: Rename 'server migrate (confirm|revert)' We're confirming or reverting a server migration, not a server migrate. We've a number of 'server migration *' commands now so it makes sense to move them under here. Change-Id: Ib95bb36511dad1aafe75f0c88d10ded382e4fa5c Signed-off-by: Stephen Finucane --- openstackclient/compute/v2/server.py | 41 ++++- .../tests/unit/compute/v2/test_server.py | 152 ++++++++++++++++++ ...firm-revert-commands-84fcb937721f5c4a.yaml | 7 + setup.cfg | 2 + 4 files changed, 198 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/rename-server-migrate-confirm-revert-commands-84fcb937721f5c4a.yaml diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index 3c598981f8..419ae4a5dd 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -3559,10 +3559,27 @@ Confirm (verify) success of resize operation and release the old server.""") server.confirm_resize() +# TODO(stephenfin): Remove in OSC 7.0 class MigrateConfirm(ResizeConfirm): - _description = _("""Confirm server migrate. + _description = _("""DEPRECATED: Confirm server migration. -Confirm (verify) success of migrate operation and release the old server.""") +Use 'server migration confirm' instead.""") + + def take_action(self, parsed_args): + msg = _( + "The 'server migrate confirm' command has been deprecated in " + "favour of the 'server migration confirm' command." + ) + self.log.warning(msg) + + super().take_action(parsed_args) + + +class ConfirmMigration(ResizeConfirm): + _description = _("""Confirm server migration. + +Confirm (verify) success of the migration operation and release the old +server.""") class ResizeRevert(command.Command): @@ -3590,10 +3607,26 @@ one.""") server.revert_resize() +# TODO(stephenfin): Remove in OSC 7.0 class MigrateRevert(ResizeRevert): - _description = _("""Revert server migrate. + _description = _("""Revert server migration. -Revert the migrate operation. Release the new server and restart the old +Use 'server migration revert' instead.""") + + def take_action(self, parsed_args): + msg = _( + "The 'server migrate revert' command has been deprecated in " + "favour of the 'server migration revert' command." + ) + self.log.warning(msg) + + super().take_action(parsed_args) + + +class RevertMigration(ResizeRevert): + _description = _("""Revert server migration. + +Revert the migration operation. Release the new server and restart the old one.""") diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py index 8d040472f0..ce04ea4ccd 100644 --- a/openstackclient/tests/unit/compute/v2/test_server.py +++ b/openstackclient/tests/unit/compute/v2/test_server.py @@ -6401,6 +6401,82 @@ class TestServerResizeConfirm(TestServer): self.server.confirm_resize.assert_called_with() +# TODO(stephenfin): Remove in OSC 7.0 +class TestServerMigrateConfirm(TestServer): + + def setUp(self): + super().setUp() + + methods = { + 'confirm_resize': None, + } + self.server = compute_fakes.FakeServer.create_one_server( + methods=methods) + + # This is the return value for utils.find_resource() + self.servers_mock.get.return_value = self.server + + self.servers_mock.confirm_resize.return_value = None + + # Get the command object to test + self.cmd = server.MigrateConfirm(self.app, None) + + def test_migrate_confirm(self): + arglist = [ + self.server.id, + ] + verifylist = [ + ('server', self.server.id), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + with mock.patch.object(self.cmd.log, 'warning') as mock_warning: + self.cmd.take_action(parsed_args) + + self.servers_mock.get.assert_called_with(self.server.id) + self.server.confirm_resize.assert_called_with() + + mock_warning.assert_called_once() + self.assertIn( + "The 'server migrate confirm' command has been deprecated", + str(mock_warning.call_args[0][0]) + ) + + +class TestServerConfirmMigration(TestServerResizeConfirm): + + def setUp(self): + super().setUp() + + methods = { + 'confirm_resize': None, + } + self.server = compute_fakes.FakeServer.create_one_server( + methods=methods) + + # This is the return value for utils.find_resource() + self.servers_mock.get.return_value = self.server + + self.servers_mock.confirm_resize.return_value = None + + # Get the command object to test + self.cmd = server.ConfirmMigration(self.app, None) + + def test_migration_confirm(self): + arglist = [ + self.server.id, + ] + verifylist = [ + ('server', self.server.id), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + + self.servers_mock.get.assert_called_with(self.server.id) + self.server.confirm_resize.assert_called_with() + + class TestServerResizeRevert(TestServer): def setUp(self): @@ -6435,6 +6511,82 @@ class TestServerResizeRevert(TestServer): self.server.revert_resize.assert_called_with() +# TODO(stephenfin): Remove in OSC 7.0 +class TestServerMigrateRevert(TestServer): + + def setUp(self): + super().setUp() + + methods = { + 'revert_resize': None, + } + self.server = compute_fakes.FakeServer.create_one_server( + methods=methods) + + # This is the return value for utils.find_resource() + self.servers_mock.get.return_value = self.server + + self.servers_mock.revert_resize.return_value = None + + # Get the command object to test + self.cmd = server.MigrateRevert(self.app, None) + + def test_migrate_revert(self): + arglist = [ + self.server.id, + ] + verifylist = [ + ('server', self.server.id), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + with mock.patch.object(self.cmd.log, 'warning') as mock_warning: + self.cmd.take_action(parsed_args) + + self.servers_mock.get.assert_called_with(self.server.id) + self.server.revert_resize.assert_called_with() + + mock_warning.assert_called_once() + self.assertIn( + "The 'server migrate revert' command has been deprecated", + str(mock_warning.call_args[0][0]) + ) + + +class TestServerRevertMigration(TestServer): + + def setUp(self): + super().setUp() + + methods = { + 'revert_resize': None, + } + self.server = compute_fakes.FakeServer.create_one_server( + methods=methods) + + # This is the return value for utils.find_resource() + self.servers_mock.get.return_value = self.server + + self.servers_mock.revert_resize.return_value = None + + # Get the command object to test + self.cmd = server.RevertMigration(self.app, None) + + def test_migration_revert(self): + arglist = [ + self.server.id, + ] + verifylist = [ + ('server', self.server.id), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + + self.servers_mock.get.assert_called_with(self.server.id) + self.server.revert_resize.assert_called_with() + + class TestServerRestore(TestServer): def setUp(self): diff --git a/releasenotes/notes/rename-server-migrate-confirm-revert-commands-84fcb937721f5c4a.yaml b/releasenotes/notes/rename-server-migrate-confirm-revert-commands-84fcb937721f5c4a.yaml new file mode 100644 index 0000000000..4c24d5f229 --- /dev/null +++ b/releasenotes/notes/rename-server-migrate-confirm-revert-commands-84fcb937721f5c4a.yaml @@ -0,0 +1,7 @@ +--- +upgrade: + - | + The ``server migrate confirm`` and ``server migrate revert`` commands, + introduced in OSC 5.0, have been deprecated in favour of + ``server migration confirm`` and ``server migration revert`` respectively. + The deprecated commands will be removed in a future major version. diff --git a/setup.cfg b/setup.cfg index ee412c050a..7c3eef8570 100644 --- a/setup.cfg +++ b/setup.cfg @@ -111,8 +111,10 @@ openstack.compute.v2 = server_migrate_confirm = openstackclient.compute.v2.server:MigrateConfirm server_migrate_revert = openstackclient.compute.v2.server:MigrateRevert server_migration_abort = openstackclient.compute.v2.server:AbortMigration + server_migration_confirm = openstackclient.compute.v2.server:ConfirmMigration server_migration_force_complete = openstackclient.compute.v2.server:ForceCompleteMigration server_migration_list = openstackclient.compute.v2.server:ListMigration + server_migration_revert = openstackclient.compute.v2.server:RevertMigration server_migration_show = openstackclient.compute.v2.server:ShowMigration server_pause = openstackclient.compute.v2.server:PauseServer server_reboot = openstackclient.compute.v2.server:RebootServer