mirror of
https://opendev.org/openstack/python-openstackclient.git
synced 2026-01-17 07:20:45 +00:00
compute: Require image when rebuilding a volume-backed server
A volume-backed server will have no image attribute (or rather the image
property will be set to the empty string). As such, if you want to try
rebuild you will need to specify an image [*]. Enforce this.
[*] Before microversion 2.93, this must be the same image. However, we
don't touch on that here. This will be addressed later.
Change-Id: I6842dabd7acb4e3a78f894e55e616625757eb6a4
Story: 2010297
Task: 46290
(cherry picked from commit 1f63034441)
This commit is contained in:
parent
d28c2584e9
commit
0118d57c02
2 changed files with 30 additions and 3 deletions
|
|
@ -3111,13 +3111,21 @@ class RebuildServer(command.ShowOne):
|
|||
server = utils.find_resource(
|
||||
compute_client.servers, parsed_args.server)
|
||||
|
||||
# If parsed_args.image is not set, default to the currently used one.
|
||||
# If parsed_args.image is not set and if the instance is image backed,
|
||||
# default to the currently used one. If the instance is volume backed,
|
||||
# it is not trivial to fetch the current image and probably better
|
||||
# to error out in this case and ask user to supply the image.
|
||||
if parsed_args.image:
|
||||
image = image_client.find_image(
|
||||
parsed_args.image, ignore_missing=False)
|
||||
else:
|
||||
image_id = server.to_dict().get('image', {}).get('id')
|
||||
image = image_client.get_image(image_id)
|
||||
if not server.image:
|
||||
msg = _(
|
||||
'The --image option is required when rebuilding a '
|
||||
'volume-backed server'
|
||||
)
|
||||
raise exceptions.CommandError(msg)
|
||||
image = image_client.get_image(server.image['id'])
|
||||
|
||||
kwargs = {}
|
||||
|
||||
|
|
|
|||
|
|
@ -5773,6 +5773,25 @@ class TestServerRebuild(TestServer):
|
|||
self.get_image_mock.assert_called_with(self.image.id)
|
||||
self.server.rebuild.assert_called_with(self.image, None)
|
||||
|
||||
def test_rebuild_with_volume_backed_server_no_image(self):
|
||||
# the volume-backed server will have the image attribute set to an
|
||||
# empty string, not null/None
|
||||
self.server.image = ''
|
||||
|
||||
arglist = [
|
||||
self.server.id,
|
||||
]
|
||||
verifylist = [
|
||||
('server', self.server.id),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
exc = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
self.assertIn('The --image option is required', str(exc))
|
||||
|
||||
def test_rebuild_with_name(self):
|
||||
name = 'test-server-xxx'
|
||||
arglist = [
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue