Skip to content

Commit 4a3c520

Browse files
committed
Show words indicating booted from volume for server image
For a server booted from a volume, nova API does not store an image_id and instead returns an empty string. Currently, openstackclient similarly shows an empty string for Image Name and Image ID for servers booted from volumes. To aid CLI users in understanding the meaning of no image_id, we can display the string "N/A (booted from volume)" in the image field if the server was booted from a volume. Change-Id: I9c62cf6fe23b2e934dcbf5ebbf706b2705d2e424
1 parent 82ebddc commit 4a3c520

3 files changed

Lines changed: 35 additions & 8 deletions

File tree

openstackclient/compute/v2/server.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
LOG = logging.getLogger(__name__)
4040

41+
IMAGE_STRING_FOR_BFV = 'N/A (booted from volume)'
42+
4143

4244
def _format_servers_list_networks(networks):
4345
"""Return a formatted string of a server's networks
@@ -147,6 +149,12 @@ def _prep_server_detail(compute_client, image_client, server, refresh=True):
147149
info['image'] = "%s (%s)" % (image.name, image_id)
148150
except Exception:
149151
info['image'] = image_id
152+
else:
153+
# NOTE(melwitt): An server booted from a volume will have no image
154+
# associated with it. We fill in the image with "N/A (booted from
155+
# volume)" to help users who want to be able to grep for
156+
# boot-from-volume servers when using the CLI.
157+
info['image'] = IMAGE_STRING_FOR_BFV
150158

151159
# Convert the flavor blob to a name
152160
flavor_info = info.get('flavor', {})
@@ -1520,8 +1528,12 @@ def take_action(self, parsed_args):
15201528
s.image_name = image.name
15211529
s.image_id = s.image['id']
15221530
else:
1523-
s.image_name = ''
1524-
s.image_id = ''
1531+
# NOTE(melwitt): An server booted from a volume will have no
1532+
# image associated with it. We fill in the Image Name and ID
1533+
# with "N/A (booted from volume)" to help users who want to be
1534+
# able to grep for boot-from-volume servers when using the CLI.
1535+
s.image_name = IMAGE_STRING_FOR_BFV
1536+
s.image_id = IMAGE_STRING_FOR_BFV
15251537
if 'id' in s.flavor:
15261538
flavor = flavors.get(s.flavor['id'])
15271539
if flavor:

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from tempest.lib import exceptions
1818

19+
from openstackclient.compute.v2 import server as v2_server
1920
from openstackclient.tests.functional.compute.v2 import common
2021
from openstackclient.tests.functional.volume.v2 import common as volume_common
2122

@@ -509,6 +510,20 @@ def test_server_boot_from_volume(self):
509510
server['name'],
510511
)
511512

513+
# check that image indicates server "booted from volume"
514+
self.assertEqual(
515+
v2_server.IMAGE_STRING_FOR_BFV,
516+
server['image'],
517+
)
518+
# check server list too
519+
servers = json.loads(self.openstack(
520+
'server list -f json'
521+
))
522+
self.assertEqual(
523+
v2_server.IMAGE_STRING_FOR_BFV,
524+
servers[0]['Image']
525+
)
526+
512527
# check volumes
513528
cmd_output = json.loads(self.openstack(
514529
'volume show -f json ' +
@@ -779,8 +794,8 @@ def test_boot_from_volume(self):
779794
self.addCleanup(self.openstack, 'volume delete ' + attached_volume_id)
780795

781796
# Since the server is volume-backed the GET /servers/{server_id}
782-
# response will have image=''.
783-
self.assertEqual('', cmd_output['image'])
797+
# response will have image='N/A (booted from volume)'.
798+
self.assertEqual(v2_server.IMAGE_STRING_FOR_BFV, cmd_output['image'])
784799

785800
# check the volume that attached on server
786801
cmd_output = json.loads(self.openstack(

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,7 +2609,7 @@ def setUp(self):
26092609
s.status,
26102610
server._format_servers_list_networks(s.networks),
26112611
# Image will be an empty string if boot-from-volume
2612-
self.image.name if s.image else s.image,
2612+
self.image.name if s.image else server.IMAGE_STRING_FOR_BFV,
26132613
self.flavor.name,
26142614
))
26152615
self.data_long.append((
@@ -2622,8 +2622,8 @@ def setUp(self):
26222622
),
26232623
server._format_servers_list_networks(s.networks),
26242624
# Image will be an empty string if boot-from-volume
2625-
self.image.name if s.image else s.image,
2626-
s.image['id'] if s.image else s.image,
2625+
self.image.name if s.image else server.IMAGE_STRING_FOR_BFV,
2626+
s.image['id'] if s.image else server.IMAGE_STRING_FOR_BFV,
26272627
self.flavor.name,
26282628
s.flavor['id'],
26292629
getattr(s, 'OS-EXT-AZ:availability_zone'),
@@ -2636,7 +2636,7 @@ def setUp(self):
26362636
s.status,
26372637
server._format_servers_list_networks(s.networks),
26382638
# Image will be an empty string if boot-from-volume
2639-
s.image['id'] if s.image else s.image,
2639+
s.image['id'] if s.image else server.IMAGE_STRING_FOR_BFV,
26402640
s.flavor['id']
26412641
))
26422642

0 commit comments

Comments
 (0)