From 7561e062ebd80a28655523320cbe1a49e94ee509 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 13 Jun 2019 17:44:28 +0100 Subject: [PATCH] Add 'openstack server resize (confirm|revert)' commands These are currently exposed as flags on the 'openstack server resize' command but they are in fact operation and should be exposed as commands in their own right. The old flag-based variants are deprecated for removal in 4.0. Change-Id: I733796d3bda6c3755a3d3548bbe695abb474a6a0 Signed-off-by: Stephen Finucane --- openstackclient/compute/v2/server.py | 55 +++++++++++++ .../tests/unit/compute/v2/test_server.py | 82 ++++++++++++++++++- ...firm-revert-commands-98854ca98965432a.yaml | 12 +++ setup.cfg | 2 + 4 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/add-server-resize-confirm-revert-commands-98854ca98965432a.yaml diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index 3e1deed59a..9882922643 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -2096,11 +2096,66 @@ the new server and restart the old one.""") self.app.stdout.write(_('Error resizing server\n')) raise SystemExit elif parsed_args.confirm: + self.log.warning(_( + "The --confirm option has been deprecated. Please use the " + "'openstack server resize confirm' command instead.")) compute_client.servers.confirm_resize(server) elif parsed_args.revert: + self.log.warning(_( + "The --revert option has been deprecated. Please use the " + "'openstack server resize revert' command instead.")) compute_client.servers.revert_resize(server) +class ResizeConfirm(command.Command): + _description = _("""Confirm server resize. + +Confirm (verify) success of resize operation and release the old server.""") + + def get_parser(self, prog_name): + parser = super(ResizeConfirm, self).get_parser(prog_name) + parser.add_argument( + 'server', + metavar='', + help=_('Server (name or ID)'), + ) + return parser + + def take_action(self, parsed_args): + + compute_client = self.app.client_manager.compute + server = utils.find_resource( + compute_client.servers, + parsed_args.server, + ) + server.confirm_resize() + + +class ResizeRevert(command.Command): + _description = _("""Revert server resize. + +Revert the resize operation. Release the new server and restart the old +one.""") + + def get_parser(self, prog_name): + parser = super(ResizeRevert, self).get_parser(prog_name) + parser.add_argument( + 'server', + metavar='', + help=_('Server (name or ID)'), + ) + return parser + + def take_action(self, parsed_args): + + compute_client = self.app.client_manager.compute + server = utils.find_resource( + compute_client.servers, + parsed_args.server, + ) + server.revert_resize() + + class RestoreServer(command.Command): _description = _("Restore server(s)") diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py index 4a37a81216..974be24c45 100644 --- a/openstackclient/tests/unit/compute/v2/test_server.py +++ b/openstackclient/tests/unit/compute/v2/test_server.py @@ -3603,13 +3603,18 @@ class TestServerResize(TestServer): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - result = self.cmd.take_action(parsed_args) + with mock.patch.object(self.cmd.log, 'warning') as mock_warning: + result = self.cmd.take_action(parsed_args) self.servers_mock.get.assert_called_with(self.server.id) self.assertNotCalled(self.servers_mock.resize) self.servers_mock.confirm_resize.assert_called_with(self.server) self.assertNotCalled(self.servers_mock.revert_resize) self.assertIsNone(result) + # A warning should have been logged for using --confirm. + mock_warning.assert_called_once() + self.assertIn('The --confirm option has been deprecated.', + six.text_type(mock_warning.call_args[0][0])) def test_server_resize_revert(self): arglist = [ @@ -3623,13 +3628,18 @@ class TestServerResize(TestServer): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - result = self.cmd.take_action(parsed_args) + with mock.patch.object(self.cmd.log, 'warning') as mock_warning: + result = self.cmd.take_action(parsed_args) self.servers_mock.get.assert_called_with(self.server.id) self.assertNotCalled(self.servers_mock.resize) self.assertNotCalled(self.servers_mock.confirm_resize) self.servers_mock.revert_resize.assert_called_with(self.server) self.assertIsNone(result) + # A warning should have been logged for using --revert. + mock_warning.assert_called_once() + self.assertIn('The --revert option has been deprecated.', + six.text_type(mock_warning.call_args[0][0])) @mock.patch.object(common_utils, 'wait_for_status', return_value=True) def test_server_resize_with_wait_ok(self, mock_wait_for_status): @@ -3710,6 +3720,74 @@ class TestServerResize(TestServer): ) +class TestServerResizeConfirm(TestServer): + + def setUp(self): + super(TestServerResizeConfirm, self).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.ResizeConfirm(self.app, None) + + def test_resize_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): + super(TestServerResizeRevert, self).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.ResizeRevert(self.app, None) + + def test_resize_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/add-server-resize-confirm-revert-commands-98854ca98965432a.yaml b/releasenotes/notes/add-server-resize-confirm-revert-commands-98854ca98965432a.yaml new file mode 100644 index 0000000000..2399a1a659 --- /dev/null +++ b/releasenotes/notes/add-server-resize-confirm-revert-commands-98854ca98965432a.yaml @@ -0,0 +1,12 @@ +--- +features: + - | + Add ``server resize confirm`` and ``server resize revert`` commands. + These replace the now deprecated ``--confirm`` and ``--revert`` + options to the ``server resize`` commands, respectively. +deprecations: + - | + Deprecate the ``--confirm`` and ``--revert`` options for the + ``server resize`` command. They have been replaced with the + ``server resize confirm`` and `server resize revert`` commands, + respectively. diff --git a/setup.cfg b/setup.cfg index db03c48423..aa72637184 100644 --- a/setup.cfg +++ b/setup.cfg @@ -124,6 +124,8 @@ openstack.compute.v2 = server_remove_volume = openstackclient.compute.v2.server:RemoveServerVolume server_rescue = openstackclient.compute.v2.server:RescueServer server_resize = openstackclient.compute.v2.server:ResizeServer + server_resize_confirm = openstackclient.compute.v2.server:ResizeConfirm + server_resize_revert = openstackclient.compute.v2.server:ResizeRevert server_restore = openstackclient.compute.v2.server:RestoreServer server_resume = openstackclient.compute.v2.server:ResumeServer server_set = openstackclient.compute.v2.server:SetServer