File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 :
Original file line number Diff line number Diff 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' ,
You can’t perform that action at this time.
0 commit comments