2626from openstackclient .tests .unit import utils as tests_utils
2727
2828
29+ LIST_FIELDS_TO_RETRIEVE = ('id' , 'name' , 'mac_address' , 'fixed_ips' , 'status' )
30+ LIST_FIELDS_TO_RETRIEVE_LONG = ('security_group_ids' , 'device_owner' , 'tags' )
31+
32+
2933class TestPort (network_fakes .TestNetworkV2 ):
3034
3135 def setUp (self ):
@@ -883,7 +887,8 @@ def test_port_list_no_options(self):
883887
884888 columns , data = self .cmd .take_action (parsed_args )
885889
886- self .network .ports .assert_called_once_with ()
890+ self .network .ports .assert_called_once_with (
891+ fields = LIST_FIELDS_TO_RETRIEVE )
887892 self .assertEqual (self .columns , columns )
888893 self .assertListItemEqual (self .data , list (data ))
889894
@@ -901,7 +906,8 @@ def test_port_list_router_opt(self):
901906 columns , data = self .cmd .take_action (parsed_args )
902907
903908 self .network .ports .assert_called_once_with (** {
904- 'device_id' : 'fake-router-id'
909+ 'device_id' : 'fake-router-id' ,
910+ 'fields' : LIST_FIELDS_TO_RETRIEVE ,
905911 })
906912 self .assertEqual (self .columns , columns )
907913 self .assertListItemEqual (self .data , list (data ))
@@ -921,7 +927,8 @@ def test_port_list_with_server_option(self, mock_find):
921927 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
922928 columns , data = self .cmd .take_action (parsed_args )
923929 self .network .ports .assert_called_once_with (
924- device_id = fake_server .id )
930+ device_id = fake_server .id ,
931+ fields = LIST_FIELDS_TO_RETRIEVE )
925932 mock_find .assert_called_once_with (mock .ANY , 'fake-server-name' )
926933 self .assertEqual (self .columns , columns )
927934 self .assertListItemEqual (self .data , list (data ))
@@ -940,7 +947,8 @@ def test_port_list_device_id_opt(self):
940947 columns , data = self .cmd .take_action (parsed_args )
941948
942949 self .network .ports .assert_called_once_with (** {
943- 'device_id' : self ._ports [0 ].device_id
950+ 'device_id' : self ._ports [0 ].device_id ,
951+ 'fields' : LIST_FIELDS_TO_RETRIEVE ,
944952 })
945953 self .assertEqual (self .columns , columns )
946954 self .assertListItemEqual (self .data , list (data ))
@@ -959,7 +967,8 @@ def test_port_list_device_owner_opt(self):
959967 columns , data = self .cmd .take_action (parsed_args )
960968
961969 self .network .ports .assert_called_once_with (** {
962- 'device_owner' : self ._ports [0 ].device_owner
970+ 'device_owner' : self ._ports [0 ].device_owner ,
971+ 'fields' : LIST_FIELDS_TO_RETRIEVE ,
963972 })
964973 self .assertEqual (self .columns , columns )
965974 self .assertListItemEqual (self .data , list (data ))
@@ -987,7 +996,8 @@ def test_port_list_all_opt(self):
987996 'device_owner' : self ._ports [0 ].device_owner ,
988997 'device_id' : 'fake-router-id' ,
989998 'network_id' : 'fake-network-id' ,
990- 'mac_address' : self ._ports [0 ].mac_address
999+ 'mac_address' : self ._ports [0 ].mac_address ,
1000+ 'fields' : LIST_FIELDS_TO_RETRIEVE ,
9911001 })
9921002 self .assertEqual (self .columns , columns )
9931003 self .assertListItemEqual (self .data , list (data ))
@@ -1006,7 +1016,8 @@ def test_port_list_mac_address_opt(self):
10061016 columns , data = self .cmd .take_action (parsed_args )
10071017
10081018 self .network .ports .assert_called_once_with (** {
1009- 'mac_address' : self ._ports [0 ].mac_address
1019+ 'mac_address' : self ._ports [0 ].mac_address ,
1020+ 'fields' : LIST_FIELDS_TO_RETRIEVE ,
10101021 })
10111022 self .assertEqual (self .columns , columns )
10121023 self .assertListItemEqual (self .data , list (data ))
@@ -1025,7 +1036,9 @@ def test_port_list_fixed_ip_opt_ip_address(self):
10251036 columns , data = self .cmd .take_action (parsed_args )
10261037
10271038 self .network .ports .assert_called_once_with (** {
1028- 'fixed_ips' : ['ip_address=%s' % ip_address ]})
1039+ 'fixed_ips' : ['ip_address=%s' % ip_address ],
1040+ 'fields' : LIST_FIELDS_TO_RETRIEVE ,
1041+ })
10291042 self .assertEqual (self .columns , columns )
10301043 self .assertListItemEqual (self .data , list (data ))
10311044
@@ -1043,7 +1056,9 @@ def test_port_list_fixed_ip_opt_ip_address_substr(self):
10431056 columns , data = self .cmd .take_action (parsed_args )
10441057
10451058 self .network .ports .assert_called_once_with (** {
1046- 'fixed_ips' : ['ip_address_substr=%s' % ip_address_ss ]})
1059+ 'fixed_ips' : ['ip_address_substr=%s' % ip_address_ss ],
1060+ 'fields' : LIST_FIELDS_TO_RETRIEVE ,
1061+ })
10471062 self .assertEqual (self .columns , columns )
10481063 self .assertListItemEqual (self .data , list (data ))
10491064
@@ -1063,7 +1078,9 @@ def test_port_list_fixed_ip_opt_subnet_id(self):
10631078 columns , data = self .cmd .take_action (parsed_args )
10641079
10651080 self .network .ports .assert_called_once_with (** {
1066- 'fixed_ips' : ['subnet_id=%s' % subnet_id ]})
1081+ 'fixed_ips' : ['subnet_id=%s' % subnet_id ],
1082+ 'fields' : LIST_FIELDS_TO_RETRIEVE ,
1083+ })
10671084 self .assertEqual (self .columns , columns )
10681085 self .assertListItemEqual (self .data , list (data ))
10691086
@@ -1087,7 +1104,9 @@ def test_port_list_fixed_ip_opts(self):
10871104
10881105 self .network .ports .assert_called_once_with (** {
10891106 'fixed_ips' : ['subnet_id=%s' % subnet_id ,
1090- 'ip_address=%s' % ip_address ]})
1107+ 'ip_address=%s' % ip_address ],
1108+ 'fields' : LIST_FIELDS_TO_RETRIEVE ,
1109+ })
10911110 self .assertEqual (self .columns , columns )
10921111 self .assertListItemEqual (self .data , list (data ))
10931112
@@ -1103,15 +1122,19 @@ def test_port_list_fixed_ips(self):
11031122 {'ip-address' : ip_address }])
11041123 ]
11051124
1106- self .fake_subnet = network_fakes .FakeSubnet .create_one_subnet (
1107- {'id' : subnet_id })
1125+ self .fake_subnet = network_fakes .FakeSubnet .create_one_subnet ({
1126+ 'id' : subnet_id ,
1127+ 'fields' : LIST_FIELDS_TO_RETRIEVE ,
1128+ })
11081129 self .network .find_subnet = mock .Mock (return_value = self .fake_subnet )
11091130 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
11101131 columns , data = self .cmd .take_action (parsed_args )
11111132
11121133 self .network .ports .assert_called_once_with (** {
11131134 'fixed_ips' : ['subnet_id=%s' % subnet_id ,
1114- 'ip_address=%s' % ip_address ]})
1135+ 'ip_address=%s' % ip_address ],
1136+ 'fields' : LIST_FIELDS_TO_RETRIEVE ,
1137+ })
11151138 self .assertEqual (self .columns , columns )
11161139 self .assertListItemEqual (self .data , list (data ))
11171140
@@ -1128,7 +1151,8 @@ def test_list_port_with_long(self):
11281151
11291152 columns , data = self .cmd .take_action (parsed_args )
11301153
1131- self .network .ports .assert_called_once_with ()
1154+ self .network .ports .assert_called_once_with (
1155+ fields = LIST_FIELDS_TO_RETRIEVE + LIST_FIELDS_TO_RETRIEVE_LONG )
11321156 self .assertEqual (self .columns_long , columns )
11331157 self .assertListItemEqual (self .data_long , list (data ))
11341158
@@ -1142,7 +1166,10 @@ def test_port_list_host(self):
11421166 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
11431167
11441168 columns , data = self .cmd .take_action (parsed_args )
1145- filters = {'binding:host_id' : 'foobar' }
1169+ filters = {
1170+ 'binding:host_id' : 'foobar' ,
1171+ 'fields' : LIST_FIELDS_TO_RETRIEVE ,
1172+ }
11461173
11471174 self .network .ports .assert_called_once_with (** filters )
11481175 self .assertEqual (self .columns , columns )
@@ -1160,7 +1187,11 @@ def test_port_list_project(self):
11601187 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
11611188
11621189 columns , data = self .cmd .take_action (parsed_args )
1163- filters = {'tenant_id' : project .id , 'project_id' : project .id }
1190+ filters = {
1191+ 'tenant_id' : project .id ,
1192+ 'project_id' : project .id ,
1193+ 'fields' : LIST_FIELDS_TO_RETRIEVE ,
1194+ }
11641195
11651196 self .network .ports .assert_called_once_with (** filters )
11661197 self .assertEqual (self .columns , columns )
@@ -1180,7 +1211,11 @@ def test_port_list_project_domain(self):
11801211 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
11811212
11821213 columns , data = self .cmd .take_action (parsed_args )
1183- filters = {'tenant_id' : project .id , 'project_id' : project .id }
1214+ filters = {
1215+ 'tenant_id' : project .id ,
1216+ 'project_id' : project .id ,
1217+ 'fields' : LIST_FIELDS_TO_RETRIEVE ,
1218+ }
11841219
11851220 self .network .ports .assert_called_once_with (** filters )
11861221 self .assertEqual (self .columns , columns )
@@ -1206,7 +1241,8 @@ def test_list_with_tag_options(self):
12061241 ** {'tags' : 'red,blue' ,
12071242 'any_tags' : 'red,green' ,
12081243 'not_tags' : 'orange,yellow' ,
1209- 'not_any_tags' : 'black,white' }
1244+ 'not_any_tags' : 'black,white' ,
1245+ 'fields' : LIST_FIELDS_TO_RETRIEVE }
12101246 )
12111247 self .assertEqual (self .columns , columns )
12121248 self .assertListItemEqual (self .data , list (data ))
0 commit comments