diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-07-14 03:32:18 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-07-14 03:32:19 +0000 |
commit | f6f4003dfdac83d1decad56cdf39258e9dc75ec0 (patch) | |
tree | bfaecc220cd727ecc5367f7fbf0913e38c2d3801 | |
parent | 78c6c3b58643d0d5a69ba8acfb459fd0423688f1 (diff) | |
parent | 92a388a1e34559b2ce69d31fdef996ff029495a6 (diff) | |
download | nova-f6f4003dfdac83d1decad56cdf39258e9dc75ec0.tar.gz |
Merge "neutron: delete VIFs when deallocating networking"14.0.0.0b2
-rw-r--r-- | nova/network/neutronv2/api.py | 13 | ||||
-rw-r--r-- | nova/tests/unit/network/test_neutronv2.py | 11 |
2 files changed, 23 insertions, 1 deletions
diff --git a/nova/network/neutronv2/api.py b/nova/network/neutronv2/api.py index 4acc275804..cc211e3ca1 100644 --- a/nova/network/neutronv2/api.py +++ b/nova/network/neutronv2/api.py @@ -1033,6 +1033,10 @@ class API(base_api.NetworkAPI): # Delete the rest of the ports self._delete_ports(neutron, instance, ports, raise_if_fail=True) + # deallocate vifs (mac addresses) + objects.VirtualInterface.delete_by_instance_uuid( + context, instance.uuid) + # NOTE(arosen): This clears out the network_cache only if the instance # hasn't already been deleted. This is needed when an instance fails to # launch and is rescheduled onto another compute node. If the instance @@ -1065,6 +1069,15 @@ class API(base_api.NetworkAPI): else: self._delete_ports(neutron, instance, [port_id], raise_if_fail=True) + + # Delete the VirtualInterface for the given port_id. + vif = objects.VirtualInterface.get_by_uuid(context, port_id) + if vif: + vif.destroy() + else: + LOG.debug('VirtualInterface not found for port: %s', + port_id, instance=instance) + return self.get_instance_nw_info(context, instance) def list_ports(self, context, **search_opts): diff --git a/nova/tests/unit/network/test_neutronv2.py b/nova/tests/unit/network/test_neutronv2.py index 287626f899..82b6a61e33 100644 --- a/nova/tests/unit/network/test_neutronv2.py +++ b/nova/tests/unit/network/test_neutronv2.py @@ -3737,7 +3737,9 @@ class TestNeutronv2WithMock(test.TestCase): @mock.patch('nova.network.neutronv2.api.API._unbind_ports') @mock.patch('nova.network.neutronv2.api.API._get_preexisting_port_ids') @mock.patch('nova.network.neutronv2.api.get_client') - def test_preexisting_deallocate_for_instance(self, mock_ntrn, + @mock.patch.object(objects.VirtualInterface, 'delete_by_instance_uuid') + def test_preexisting_deallocate_for_instance(self, mock_delete_vifs, + mock_ntrn, mock_gppids, mock_unbind, mock_deletep, @@ -3772,12 +3774,15 @@ class TestNeutronv2WithMock(test.TestCase): mock_inst, set([uuids.portid_2]), raise_if_fail=True) + mock_delete_vifs.assert_called_once_with(mock.sentinel.ctx, 'inst-1') @mock.patch('nova.network.neutronv2.api.API.get_instance_nw_info') @mock.patch('nova.network.neutronv2.api.API._unbind_ports') @mock.patch('nova.network.neutronv2.api.compute_utils') @mock.patch('nova.network.neutronv2.api.get_client') + @mock.patch.object(objects.VirtualInterface, 'get_by_uuid') def test_preexisting_deallocate_port_for_instance(self, + mock_get_vif_by_uuid, mock_ntrn, mock_comp_utils, mock_unbind, @@ -3791,10 +3796,14 @@ class TestNeutronv2WithMock(test.TestCase): uuid='inst-1') mock_client = mock.Mock() mock_ntrn.return_value = mock_client + mock_vif = mock.MagicMock(spec=objects.VirtualInterface) + mock_get_vif_by_uuid.return_value = mock_vif self.api.deallocate_port_for_instance(mock.sentinel.ctx, mock_inst, '2') mock_unbind.assert_called_once_with(mock.sentinel.ctx, ['2'], mock_client) + mock_get_vif_by_uuid.assert_called_once_with(mock.sentinel.ctx, '2') + mock_vif.destroy.assert_called_once_with() @mock.patch('nova.network.neutronv2.api.API.' '_check_external_network_attach') |