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
This commit is contained in:

committed by
Stephen Finucane

parent
c6065c7a47
commit
1f63034441
@@ -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 = {}
|
||||
|
||||
|
@@ -5781,6 +5781,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 = [
|
||||
|
Reference in New Issue
Block a user