From bfc34e11b3437506508b3e120accc0e212268ac6 Mon Sep 17 00:00:00 2001 From: melanie witt Date: Fri, 28 Jun 2019 18:17:10 +0000 Subject: 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 --- openstackclient/compute/v2/server.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'openstackclient/compute') 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: -- cgit v1.2.1