Skip to content

Commit e4bbc3c

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Skip calls to glance and nova when got no servers"
2 parents 84755a8 + b9fab84 commit e4bbc3c

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)