Merge "Fix BFV server list handling with --name-lookup-one-by-one"
This commit is contained in:
commit
5b97dfa427
@ -1350,9 +1350,12 @@ class ListServer(command.Lister):
|
|||||||
# Create a dict that maps image_id to image object.
|
# Create a dict that maps image_id to image object.
|
||||||
# Needed so that we can display the "Image Name" column.
|
# Needed so that we can display the "Image Name" column.
|
||||||
# "Image Name" is not crucial, so we swallow any exceptions.
|
# "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:
|
if parsed_args.name_lookup_one_by_one or image_id:
|
||||||
for i_id in set(filter(lambda x: x is not None,
|
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:
|
try:
|
||||||
images[i_id] = image_client.images.get(i_id)
|
images[i_id] = image_client.images.get(i_id)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#
|
#
|
||||||
import argparse
|
import argparse
|
||||||
import collections
|
import collections
|
||||||
|
import copy
|
||||||
import getpass
|
import getpass
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
@ -65,9 +66,22 @@ class TestServer(compute_fakes.TestComputev2):
|
|||||||
self.methods = {}
|
self.methods = {}
|
||||||
|
|
||||||
def setup_servers_mock(self, count):
|
def setup_servers_mock(self, count):
|
||||||
servers = compute_fakes.FakeServer.create_servers(attrs=self.attrs,
|
# If we are creating more than one server, make one of them
|
||||||
methods=self.methods,
|
# boot-from-volume
|
||||||
count=count)
|
include_bfv = count > 1
|
||||||
|
servers = compute_fakes.FakeServer.create_servers(
|
||||||
|
attrs=self.attrs,
|
||||||
|
methods=self.methods,
|
||||||
|
count=count - 1 if include_bfv else count
|
||||||
|
)
|
||||||
|
if include_bfv:
|
||||||
|
attrs = copy.deepcopy(self.attrs)
|
||||||
|
attrs['image'] = ''
|
||||||
|
bfv_server = compute_fakes.FakeServer.create_one_server(
|
||||||
|
attrs=attrs,
|
||||||
|
methods=self.methods
|
||||||
|
)
|
||||||
|
servers.append(bfv_server)
|
||||||
|
|
||||||
# This is the return value for utils.find_resource()
|
# This is the return value for utils.find_resource()
|
||||||
self.servers_mock.get = compute_fakes.FakeServer.get_servers(servers,
|
self.servers_mock.get = compute_fakes.FakeServer.get_servers(servers,
|
||||||
@ -2129,7 +2143,8 @@ class TestServerList(TestServer):
|
|||||||
Image = collections.namedtuple('Image', 'id name')
|
Image = collections.namedtuple('Image', 'id name')
|
||||||
self.images_mock.list.return_value = [
|
self.images_mock.list.return_value = [
|
||||||
Image(id=s.image['id'], name=self.image.name)
|
Image(id=s.image['id'], name=self.image.name)
|
||||||
for s in self.servers
|
# Image will be an empty string if boot-from-volume
|
||||||
|
for s in self.servers if s.image
|
||||||
]
|
]
|
||||||
|
|
||||||
Flavor = collections.namedtuple('Flavor', 'id name')
|
Flavor = collections.namedtuple('Flavor', 'id name')
|
||||||
@ -2144,7 +2159,8 @@ class TestServerList(TestServer):
|
|||||||
s.name,
|
s.name,
|
||||||
s.status,
|
s.status,
|
||||||
server._format_servers_list_networks(s.networks),
|
server._format_servers_list_networks(s.networks),
|
||||||
self.image.name,
|
# Image will be an empty string if boot-from-volume
|
||||||
|
self.image.name if s.image else s.image,
|
||||||
self.flavor.name,
|
self.flavor.name,
|
||||||
))
|
))
|
||||||
self.data_long.append((
|
self.data_long.append((
|
||||||
@ -2156,8 +2172,9 @@ class TestServerList(TestServer):
|
|||||||
getattr(s, 'OS-EXT-STS:power_state')
|
getattr(s, 'OS-EXT-STS:power_state')
|
||||||
),
|
),
|
||||||
server._format_servers_list_networks(s.networks),
|
server._format_servers_list_networks(s.networks),
|
||||||
self.image.name,
|
# Image will be an empty string if boot-from-volume
|
||||||
s.image['id'],
|
self.image.name if s.image else s.image,
|
||||||
|
s.image['id'] if s.image else s.image,
|
||||||
self.flavor.name,
|
self.flavor.name,
|
||||||
s.flavor['id'],
|
s.flavor['id'],
|
||||||
getattr(s, 'OS-EXT-AZ:availability_zone'),
|
getattr(s, 'OS-EXT-AZ:availability_zone'),
|
||||||
@ -2169,7 +2186,8 @@ class TestServerList(TestServer):
|
|||||||
s.name,
|
s.name,
|
||||||
s.status,
|
s.status,
|
||||||
server._format_servers_list_networks(s.networks),
|
server._format_servers_list_networks(s.networks),
|
||||||
s.image['id'],
|
# Image will be an empty string if boot-from-volume
|
||||||
|
s.image['id'] if s.image else s.image,
|
||||||
s.flavor['id']
|
s.flavor['id']
|
||||||
))
|
))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user