@@ -5248,7 +5248,8 @@ def test_get_preexisting_port_ids(self, mock_get_nw_info):
5248
5248
self .assertEqual (['2' , '3' ], result , "Invalid preexisting ports" )
5249
5249
5250
5250
@mock .patch ('nova.network.neutron.API._show_port' )
5251
- def _test_unbind_ports_get_client (self , mock_neutron , mock_show ):
5251
+ @mock .patch ('nova.network.neutron.get_client' )
5252
+ def test_unbind_ports_get_client (self , mock_neutron , mock_show ):
5252
5253
mock_ctx = mock .Mock (is_admin = False )
5253
5254
ports = ["1" , "2" , "3" ]
5254
5255
@@ -5264,25 +5265,18 @@ def _test_unbind_ports_get_client(self, mock_neutron, mock_show):
5264
5265
self .assertEqual (1 , mock_neutron .call_count )
5265
5266
mock_neutron .assert_has_calls (get_client_calls , True )
5266
5267
5267
- @mock .patch ('nova.network.neutron.get_client' )
5268
- def test_unbind_ports_get_client_binding_extension (self ,
5269
- mock_neutron ):
5270
- self ._test_unbind_ports_get_client (mock_neutron )
5271
-
5272
- @mock .patch ('nova.network.neutron.get_client' )
5273
- def test_unbind_ports_get_client (self , mock_neutron ):
5274
- self ._test_unbind_ports_get_client (mock_neutron )
5275
-
5276
5268
@mock .patch ('nova.network.neutron.API.has_dns_extension' ,
5277
5269
new = mock .Mock (return_value = False ))
5278
5270
@mock .patch ('nova.network.neutron.API._show_port' )
5279
- def _test_unbind_ports (self , mock_neutron , mock_show ):
5271
+ @mock .patch ('nova.network.neutron.get_client' )
5272
+ def test_unbind_ports (self , mock_neutron , mock_show ):
5280
5273
mock_client = mock .Mock ()
5281
5274
mock_update_port = mock .Mock ()
5282
5275
mock_client .update_port = mock_update_port
5283
5276
mock_ctx = mock .Mock (is_admin = False )
5284
5277
ports = ["1" , "2" , "3" ]
5285
5278
mock_show .side_effect = [{"id" : "1" }, {"id" : "2" }, {"id" : "3" }]
5279
+
5286
5280
api = neutronapi .API ()
5287
5281
api ._unbind_ports (mock_ctx , ports , mock_neutron , mock_client )
5288
5282
@@ -5296,14 +5290,6 @@ def _test_unbind_ports(self, mock_neutron, mock_show):
5296
5290
self .assertEqual (3 , mock_update_port .call_count )
5297
5291
mock_update_port .assert_has_calls (update_port_calls )
5298
5292
5299
- @mock .patch ('nova.network.neutron.get_client' )
5300
- def test_unbind_ports_binding_ext (self , mock_neutron ):
5301
- self ._test_unbind_ports (mock_neutron )
5302
-
5303
- @mock .patch ('nova.network.neutron.get_client' )
5304
- def test_unbind_ports (self , mock_neutron ):
5305
- self ._test_unbind_ports (mock_neutron )
5306
-
5307
5293
def test_unbind_ports_no_port_ids (self ):
5308
5294
# Tests that None entries in the ports list are filtered out.
5309
5295
mock_client = mock .Mock ()
@@ -6068,7 +6054,6 @@ def test_get_instance_id_by_floating_address_port_not_found(self,
6068
6054
def test_unbind_ports_port_show_portnotfound (self , mock_log , mock_show ):
6069
6055
api = neutronapi .API ()
6070
6056
neutron_client = mock .Mock ()
6071
- mock_show .return_value = {'id' : uuids .port }
6072
6057
api ._unbind_ports (self .context , [uuids .port_id ],
6073
6058
neutron_client , neutron_client )
6074
6059
mock_show .assert_called_once_with (
@@ -6077,6 +6062,63 @@ def test_unbind_ports_port_show_portnotfound(self, mock_log, mock_show):
6077
6062
neutron_client = mock .ANY )
6078
6063
mock_log .assert_not_called ()
6079
6064
6065
+ @mock .patch (
6066
+ 'nova.network.neutron.API.has_dns_extension' ,
6067
+ new = mock .Mock (return_value = False ),
6068
+ )
6069
+ @mock .patch ('nova.network.neutron.API._show_port' )
6070
+ @mock .patch .object (neutronapi , 'LOG' )
6071
+ def test_unbind_ports_port_show_portnotfound_multiple_ports (
6072
+ self , mock_log , mock_show ,
6073
+ ):
6074
+ """Ensure we continue unbinding ports even when one isn't found."""
6075
+ mock_show .side_effect = [
6076
+ exception .PortNotFound (port_id = uuids .port_a ),
6077
+ {'id' : uuids .port_b },
6078
+ ]
6079
+ api = neutronapi .API ()
6080
+ neutron_client = mock .Mock ()
6081
+
6082
+ api ._unbind_ports (
6083
+ self .context ,
6084
+ [uuids .port_a , uuids .port_b ],
6085
+ neutron_client ,
6086
+ neutron_client ,
6087
+ )
6088
+
6089
+ mock_show .assert_has_calls (
6090
+ [
6091
+ mock .call (
6092
+ self .context ,
6093
+ uuids .port_a ,
6094
+ fields = ['binding:profile' , 'network_id' ],
6095
+ neutron_client = neutron_client ,
6096
+ ),
6097
+ mock .call (
6098
+ self .context ,
6099
+ uuids .port_b ,
6100
+ fields = ['binding:profile' , 'network_id' ],
6101
+ neutron_client = neutron_client ,
6102
+ ),
6103
+ ]
6104
+ )
6105
+ # Only the port that exists should be updated
6106
+ neutron_client .update_port .assert_called_once_with (
6107
+ uuids .port_b ,
6108
+ {
6109
+ 'port' : {
6110
+ 'device_id' : '' ,
6111
+ 'device_owner' : '' ,
6112
+ 'binding:profile' : {},
6113
+ 'binding:host_id' : None ,
6114
+ }
6115
+ }
6116
+ )
6117
+ mock_log .exception .assert_not_called ()
6118
+ mock_log .debug .assert_called_with (
6119
+ 'Unable to show port %s as it no longer exists.' , uuids .port_a ,
6120
+ )
6121
+
6080
6122
@mock .patch ('nova.network.neutron.API.has_dns_extension' ,
6081
6123
new = mock .Mock (return_value = False ))
6082
6124
@mock .patch ('nova.network.neutron.API._show_port' ,
@@ -6100,7 +6142,7 @@ def test_unbind_ports_port_show_unexpected_error(self,
6100
6142
new = mock .Mock (return_value = False ))
6101
6143
@mock .patch ('nova.network.neutron.API._show_port' )
6102
6144
@mock .patch .object (neutronapi .LOG , 'exception' )
6103
- def test_unbind_ports_portnotfound (self , mock_log , mock_show ):
6145
+ def test_unbind_ports_port_update_portnotfound (self , mock_log , mock_show ):
6104
6146
api = neutronapi .API ()
6105
6147
neutron_client = mock .Mock ()
6106
6148
neutron_client .update_port = mock .Mock (
@@ -6118,7 +6160,9 @@ def test_unbind_ports_portnotfound(self, mock_log, mock_show):
6118
6160
new = mock .Mock (return_value = False ))
6119
6161
@mock .patch ('nova.network.neutron.API._show_port' )
6120
6162
@mock .patch .object (neutronapi .LOG , 'exception' )
6121
- def test_unbind_ports_unexpected_error (self , mock_log , mock_show ):
6163
+ def test_unbind_ports_port_update_unexpected_error (
6164
+ self , mock_log , mock_show ,
6165
+ ):
6122
6166
api = neutronapi .API ()
6123
6167
neutron_client = mock .Mock ()
6124
6168
neutron_client .update_port = mock .Mock (
0 commit comments