summaryrefslogtreecommitdiff
path: root/openstackclient/compute
diff options
context:
space:
mode:
authormelanie witt <melwittt@gmail.com>2019-06-28 18:17:10 +0000
committermelanie witt <melwittt@gmail.com>2019-06-28 22:06:39 +0000
commitbfc34e11b3437506508b3e120accc0e212268ac6 (patch)
treef7766cdb1b7fc58831851379c243379a0d340dec /openstackclient/compute
parenteada2db332caa3dc042650437a1536e589505c2b (diff)
downloadpython-openstackclient-bfc34e11b3437506508b3e120accc0e212268ac6.tar.gz
Fix BFV server list handling with --name-lookup-one-by-one
When the --name-lookup-one-by-one option passed to the 'server list' command, the image and flavor names will be looked up for each server being listed instead of fetching all image/flavor names. The current code assumes all servers have an image attribute, but servers booted from volumes have no image, so the following error is raised when listing BFV servers with --name-lookup-one-by-one: AttributeError: ('unicode'|'str') object has no attribute 'get' The error occurs when the code attempts server.image.get('id'). This fixes the --name-lookup-one-by-one code not to assume an image for a server. The unit tests for 'server list' have also been robustified to feature one BFV server to enhance our test coverage. Story: #2006063 Task: #34777 Change-Id: I312c971346c7ded93f6fcaa515098554b8580295
Diffstat (limited to 'openstackclient/compute')
-rw-r--r--openstackclient/compute/v2/server.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py
index 2792e315..a4216e65 100644
--- a/openstackclient/compute/v2/server.py
+++ b/openstackclient/compute/v2/server.py
@@ -1350,9 +1350,12 @@ class ListServer(command.Lister):
# Create a dict that maps image_id to image object.
# Needed so that we can display the "Image Name" column.
# "Image Name" is not crucial, so we swallow any exceptions.
+ # The 'image' attribute can be an empty string if the server was
+ # booted from a volume.
if parsed_args.name_lookup_one_by_one or image_id:
for i_id in set(filter(lambda x: x is not None,
- (s.image.get('id') for s in data))):
+ (s.image.get('id') for s in data
+ if s.image))):
try:
images[i_id] = image_client.images.get(i_id)
except Exception: