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 <sfinucan@redhat.com>
This commit is contained in:
parent
57dec524c8
commit
7561e062eb
@ -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='<server>',
|
||||
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='<server>',
|
||||
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)")
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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.
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user