Skip to content

Commit 1f63034

Browse files
rajatherestephenfin
authored andcommitted
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
1 parent c6065c7 commit 1f63034

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

openstackclient/compute/v2/server.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3111,13 +3111,21 @@ def _show_progress(progress):
31113111
server = utils.find_resource(
31123112
compute_client.servers, parsed_args.server)
31133113

3114-
# If parsed_args.image is not set, default to the currently used one.
3114+
# If parsed_args.image is not set and if the instance is image backed,
3115+
# default to the currently used one. If the instance is volume backed,
3116+
# it is not trivial to fetch the current image and probably better
3117+
# to error out in this case and ask user to supply the image.
31153118
if parsed_args.image:
31163119
image = image_client.find_image(
31173120
parsed_args.image, ignore_missing=False)
31183121
else:
3119-
image_id = server.to_dict().get('image', {}).get('id')
3120-
image = image_client.get_image(image_id)
3122+
if not server.image:
3123+
msg = _(
3124+
'The --image option is required when rebuilding a '
3125+
'volume-backed server'
3126+
)
3127+
raise exceptions.CommandError(msg)
3128+
image = image_client.get_image(server.image['id'])
31213129

31223130
kwargs = {}
31233131

openstackclient/tests/unit/compute/v2/test_server.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5781,6 +5781,25 @@ def test_rebuild_with_current_image(self):
57815781
self.get_image_mock.assert_called_with(self.image.id)
57825782
self.server.rebuild.assert_called_with(self.image, None)
57835783

5784+
def test_rebuild_with_volume_backed_server_no_image(self):
5785+
# the volume-backed server will have the image attribute set to an
5786+
# empty string, not null/None
5787+
self.server.image = ''
5788+
5789+
arglist = [
5790+
self.server.id,
5791+
]
5792+
verifylist = [
5793+
('server', self.server.id),
5794+
]
5795+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
5796+
5797+
exc = self.assertRaises(
5798+
exceptions.CommandError,
5799+
self.cmd.take_action,
5800+
parsed_args)
5801+
self.assertIn('The --image option is required', str(exc))
5802+
57845803
def test_rebuild_with_name(self):
57855804
name = 'test-server-xxx'
57865805
arglist = [

0 commit comments

Comments
 (0)