Skip to content

Commit b9fab84

Browse files
committed
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
1 parent c5a0c3a commit b9fab84

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

openstackclient/compute/v2/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ def take_action(self, parsed_args):
12261226
# Create a dict that maps image_id to image object.
12271227
# Needed so that we can display the "Image Name" column.
12281228
# "Image Name" is not crucial, so we swallow any exceptions.
1229-
if not parsed_args.no_name_lookup:
1229+
if data and not parsed_args.no_name_lookup:
12301230
try:
12311231
images_list = self.app.client_manager.image.images.list()
12321232
for i in images_list:
@@ -1238,7 +1238,7 @@ def take_action(self, parsed_args):
12381238
# Create a dict that maps flavor_id to flavor object.
12391239
# Needed so that we can display the "Flavor Name" column.
12401240
# "Flavor Name" is not crucial, so we swallow any exceptions.
1241-
if not parsed_args.no_name_lookup:
1241+
if data and not parsed_args.no_name_lookup:
12421242
try:
12431243
flavors_list = compute_client.flavors.list(is_public=None)
12441244
for i in flavors_list:

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,6 +1947,25 @@ def test_server_list_no_option(self):
19471947
self.assertEqual(self.columns, columns)
19481948
self.assertEqual(tuple(self.data), tuple(data))
19491949

1950+
def test_server_list_no_servers(self):
1951+
arglist = []
1952+
verifylist = [
1953+
('all_projects', False),
1954+
('long', False),
1955+
('deleted', False),
1956+
]
1957+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1958+
self.servers_mock.list.return_value = []
1959+
self.data = ()
1960+
1961+
columns, data = self.cmd.take_action(parsed_args)
1962+
1963+
self.servers_mock.list.assert_called_with(**self.kwargs)
1964+
self.assertEqual(0, self.images_mock.list.call_count)
1965+
self.assertEqual(0, self.flavors_mock.list.call_count)
1966+
self.assertEqual(self.columns, columns)
1967+
self.assertEqual(tuple(self.data), tuple(data))
1968+
19501969
def test_server_list_long_option(self):
19511970
arglist = [
19521971
'--long',

0 commit comments

Comments
 (0)