Skip calls to glance and nova when got no servers
save (potentially many) HTTP calls to Glance API for image list and a call to Nova API for flavor list when the server list actually returned no servers. Change-Id: I93a56138c50b82fb4dce67a2f788107f71c5f423 Story: #2002039 Task: #19681
This commit is contained in:
parent
c5a0c3ad5d
commit
b9fab849f7
@ -1226,7 +1226,7 @@ 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.
|
||||||
if not parsed_args.no_name_lookup:
|
if data and not parsed_args.no_name_lookup:
|
||||||
try:
|
try:
|
||||||
images_list = self.app.client_manager.image.images.list()
|
images_list = self.app.client_manager.image.images.list()
|
||||||
for i in images_list:
|
for i in images_list:
|
||||||
@ -1238,7 +1238,7 @@ class ListServer(command.Lister):
|
|||||||
# Create a dict that maps flavor_id to flavor object.
|
# Create a dict that maps flavor_id to flavor object.
|
||||||
# Needed so that we can display the "Flavor Name" column.
|
# Needed so that we can display the "Flavor Name" column.
|
||||||
# "Flavor Name" is not crucial, so we swallow any exceptions.
|
# "Flavor Name" is not crucial, so we swallow any exceptions.
|
||||||
if not parsed_args.no_name_lookup:
|
if data and not parsed_args.no_name_lookup:
|
||||||
try:
|
try:
|
||||||
flavors_list = compute_client.flavors.list(is_public=None)
|
flavors_list = compute_client.flavors.list(is_public=None)
|
||||||
for i in flavors_list:
|
for i in flavors_list:
|
||||||
|
@ -1947,6 +1947,25 @@ class TestServerList(TestServer):
|
|||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(tuple(self.data), tuple(data))
|
self.assertEqual(tuple(self.data), tuple(data))
|
||||||
|
|
||||||
|
def test_server_list_no_servers(self):
|
||||||
|
arglist = []
|
||||||
|
verifylist = [
|
||||||
|
('all_projects', False),
|
||||||
|
('long', False),
|
||||||
|
('deleted', False),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
self.servers_mock.list.return_value = []
|
||||||
|
self.data = ()
|
||||||
|
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.servers_mock.list.assert_called_with(**self.kwargs)
|
||||||
|
self.assertEqual(0, self.images_mock.list.call_count)
|
||||||
|
self.assertEqual(0, self.flavors_mock.list.call_count)
|
||||||
|
self.assertEqual(self.columns, columns)
|
||||||
|
self.assertEqual(tuple(self.data), tuple(data))
|
||||||
|
|
||||||
def test_server_list_long_option(self):
|
def test_server_list_long_option(self):
|
||||||
arglist = [
|
arglist = [
|
||||||
'--long',
|
'--long',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user