Skip to content

Commit da7572a

Browse files
committed
Fix server show for microversion 2.47
Compute API version 2.47 embeds the server's internal flavor in the response. The original flavor id is not preserved since it could have changed if the flavor was deleted and re-created after the server was created, which was the dreaded Horizon "Edit Flavor" issue. So the flavor dict in the server response is a dict of information about the flavor representing the server "right now" excluding the id. The original flavor name is shown though along with the ram/disk/vcpu etc information. The server list command has a similar issue which will be fixed in a follow up change. Change-Id: I1a92999758006d02567c542b6be8902a049899cc Task: 13864 Story: 1751104
1 parent 752a2db commit da7572a

3 files changed

Lines changed: 52 additions & 7 deletions

File tree

openstackclient/compute/v2/server.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,18 @@ def _prep_server_detail(compute_client, image_client, server, refresh=True):
148148

149149
# Convert the flavor blob to a name
150150
flavor_info = info.get('flavor', {})
151-
flavor_id = flavor_info.get('id', '')
152-
try:
153-
flavor = utils.find_resource(compute_client.flavors, flavor_id)
154-
info['flavor'] = "%s (%s)" % (flavor.name, flavor_id)
155-
except Exception:
156-
info['flavor'] = flavor_id
151+
# Microversion 2.47 puts the embedded flavor into the server response
152+
# body but omits the id, so if not present we just expose the flavor
153+
# dict in the server output.
154+
if 'id' in flavor_info:
155+
flavor_id = flavor_info.get('id', '')
156+
try:
157+
flavor = utils.find_resource(compute_client.flavors, flavor_id)
158+
info['flavor'] = "%s (%s)" % (flavor.name, flavor_id)
159+
except Exception:
160+
info['flavor'] = flavor_id
161+
else:
162+
info['flavor'] = utils.format_dict(flavor_info)
157163

158164
if 'os-extended-volumes:volumes_attached' in info:
159165
info.update(
@@ -1257,6 +1263,10 @@ def take_action(self, parsed_args):
12571263
s.flavor_name = flavor.name
12581264
s.flavor_id = s.flavor['id']
12591265
else:
1266+
# TODO(mriedem): Fix this for microversion >= 2.47 where the
1267+
# flavor is embedded in the server response without the id.
1268+
# We likely need to drop the Flavor ID column in that case if
1269+
# --long is specified.
12601270
s.flavor_name = ''
12611271
s.flavor_id = ''
12621272

@@ -1994,7 +2004,9 @@ def take_action(self, parsed_args):
19942004

19952005

19962006
class ShowServer(command.ShowOne):
1997-
_description = _("Show server details")
2007+
_description = _(
2008+
"Show server details. Specify ``--os-compute-api-version 2.47`` "
2009+
"or higher to see the embedded flavor information for the server.")
19982010

19992011
def get_parser(self, prog_name):
20002012
parser = super(ShowServer, self).get_parser(prog_name)

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3217,6 +3217,33 @@ def test_show(self):
32173217
self.assertEqual(self.columns, columns)
32183218
self.assertEqual(self.data, data)
32193219

3220+
def test_show_embedded_flavor(self):
3221+
# Tests using --os-compute-api-version >= 2.47 where the flavor
3222+
# details are embedded in the server response body excluding the id.
3223+
arglist = [
3224+
self.server.name,
3225+
]
3226+
verifylist = [
3227+
('diagnostics', False),
3228+
('server', self.server.name),
3229+
]
3230+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
3231+
self.server.info['flavor'] = {
3232+
'ephemeral': 0,
3233+
'ram': 512,
3234+
'original_name': 'm1.tiny',
3235+
'vcpus': 1,
3236+
'extra_specs': {},
3237+
'swap': 0,
3238+
'disk': 1
3239+
}
3240+
columns, data = self.cmd.take_action(parsed_args)
3241+
3242+
self.assertEqual(self.columns, columns)
3243+
# Since the flavor details are in a dict we can't be sure of the
3244+
# ordering so just assert that one of the keys is in the output.
3245+
self.assertIn('original_name', data[2])
3246+
32203247
def test_show_diagnostics(self):
32213248
arglist = [
32223249
'--diagnostics',
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
The ``openstack server show`` command will now properly show the server's
5+
flavor information when using ``--os-compute-api-version 2.47`` or higher.
6+
See: https://storyboard.openstack.org/#!/story/1751104

0 commit comments

Comments
 (0)