compute: Migrate 'server evacuate' to SDK
Change-Id: I8ea2da0921c5fd306271f03fa733c0f9787afb82 Signed-off-by: Stephen Finucane <stephenfin@redhat.com> Depends-on: https://review.opendev.org/c/openstack/openstacksdk/+/918745
This commit is contained in:
parent
b9b5e7615a
commit
e6dc0f39c0
@ -3693,7 +3693,6 @@ class RebuildServer(command.ShowOne):
|
||||
return zip(*sorted(data.items()))
|
||||
|
||||
|
||||
# TODO(stephenfin): Migrate to SDK
|
||||
class EvacuateServer(command.ShowOne):
|
||||
_description = _(
|
||||
"""Evacuate a server to a different host.
|
||||
@ -3719,7 +3718,6 @@ host."""
|
||||
metavar='<server>',
|
||||
help=_('Server (name or ID)'),
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--wait',
|
||||
action='store_true',
|
||||
@ -3766,11 +3764,11 @@ host."""
|
||||
self.app.stdout.write('\rProgress: %s' % progress)
|
||||
self.app.stdout.flush()
|
||||
|
||||
compute_client = self.app.client_manager.compute
|
||||
compute_client = self.app.client_manager.sdk_connection.compute
|
||||
image_client = self.app.client_manager.image
|
||||
|
||||
if parsed_args.host:
|
||||
if compute_client.api_version < api_versions.APIVersion('2.29'):
|
||||
if not sdk_utils.supports_microversion(compute_client, '2.29'):
|
||||
msg = _(
|
||||
'--os-compute-api-version 2.29 or later is required '
|
||||
'to specify a preferred host.'
|
||||
@ -3778,7 +3776,7 @@ host."""
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
if parsed_args.shared_storage:
|
||||
if compute_client.api_version > api_versions.APIVersion('2.13'):
|
||||
if sdk_utils.supports_microversion(compute_client, '2.14'):
|
||||
msg = _(
|
||||
'--os-compute-api-version 2.13 or earlier is required '
|
||||
'to specify shared-storage.'
|
||||
@ -3790,18 +3788,17 @@ host."""
|
||||
'password': parsed_args.password,
|
||||
}
|
||||
|
||||
if compute_client.api_version <= api_versions.APIVersion('2.13'):
|
||||
if not sdk_utils.supports_microversion(compute_client, '2.14'):
|
||||
kwargs['on_shared_storage'] = parsed_args.shared_storage
|
||||
|
||||
server = utils.find_resource(
|
||||
compute_client.servers, parsed_args.server
|
||||
server = compute_client.find_server(
|
||||
parsed_args.server, ignore_missing=False
|
||||
)
|
||||
|
||||
server.evacuate(**kwargs)
|
||||
compute_client.evacuate_server(server, **kwargs)
|
||||
|
||||
if parsed_args.wait:
|
||||
if utils.wait_for_status(
|
||||
compute_client.servers.get,
|
||||
compute_client.get_server,
|
||||
server.id,
|
||||
callback=_show_progress,
|
||||
):
|
||||
@ -3810,8 +3807,6 @@ host."""
|
||||
msg = _('Error evacuating server: %s') % server.id
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
# TODO(stephenfin): Remove when the whole command is using SDK
|
||||
compute_client = self.app.client_manager.sdk_connection.compute
|
||||
data = _prep_server_detail(compute_client, image_client, server)
|
||||
return zip(*sorted(data.items()))
|
||||
|
||||
|
@ -7105,46 +7105,37 @@ class TestServerEvacuate(TestServer):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
# Return value for utils.find_resource for image
|
||||
self.image = image_fakes.create_one_image()
|
||||
self.image_client.get_image.return_value = self.image
|
||||
|
||||
# Fake the rebuilt new server.
|
||||
attrs = {
|
||||
'image': {'id': self.image.id},
|
||||
'image': self.image,
|
||||
'networks': {},
|
||||
'adminPass': 'passw0rd',
|
||||
}
|
||||
new_server = compute_fakes.create_one_server(attrs=attrs)
|
||||
|
||||
# Fake the server to be rebuilt. The IDs of them should be the same.
|
||||
attrs['id'] = new_server.id
|
||||
methods = {
|
||||
'evacuate': new_server,
|
||||
}
|
||||
self.server = compute_fakes.create_one_server(
|
||||
attrs=attrs, methods=methods
|
||||
)
|
||||
self.server = compute_fakes.create_one_sdk_server(attrs=attrs)
|
||||
attrs['id'] = self.server.id
|
||||
self.new_server = compute_fakes.create_one_sdk_server(attrs=attrs)
|
||||
|
||||
# Return value for utils.find_resource for server.
|
||||
self.servers_mock.get.return_value = self.server
|
||||
|
||||
# We need an SDK-style server object also for the get_server call in
|
||||
# _prep_server_detail
|
||||
# TODO(stephenfin): Remove when the whole command is using SDK
|
||||
self.sdk_server = compute_fakes.create_one_sdk_server(attrs=attrs)
|
||||
self.compute_sdk_client.get_server.return_value = self.sdk_server
|
||||
self.compute_sdk_client.find_server.return_value = self.server
|
||||
self.compute_sdk_client.get_server.return_value = self.server
|
||||
|
||||
self.cmd = server.EvacuateServer(self.app, None)
|
||||
|
||||
def _test_evacuate(self, args, verify_args, evac_args):
|
||||
parsed_args = self.check_parser(self.cmd, args, verify_args)
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.servers_mock.get.assert_called_with(self.server.id)
|
||||
self.server.evacuate.assert_called_with(**evac_args)
|
||||
self.compute_sdk_client.find_server.assert_called_once_with(
|
||||
self.server.id, ignore_missing=False
|
||||
)
|
||||
self.compute_sdk_client.evacuate_server.assert_called_once_with(
|
||||
self.server, **evac_args
|
||||
)
|
||||
self.compute_sdk_client.get_server.assert_called_once_with(
|
||||
self.server.id
|
||||
)
|
||||
|
||||
def test_evacuate(self):
|
||||
args = [
|
||||
@ -7258,7 +7249,7 @@ class TestServerEvacuate(TestServer):
|
||||
}
|
||||
self._test_evacuate(args, verify_args, evac_args)
|
||||
mock_wait_for_status.assert_called_once_with(
|
||||
self.servers_mock.get,
|
||||
self.compute_sdk_client.get_server,
|
||||
self.server.id,
|
||||
callback=mock.ANY,
|
||||
)
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
upgrade:
|
||||
- |
|
||||
The ``server evacuate`` command has been migrated to SDK.
|
Loading…
Reference in New Issue
Block a user