]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
DHCP: protect against case when device name is None
authorGary Kotton <gkotton@vmware.com>
Sun, 27 Sep 2015 07:24:31 +0000 (00:24 -0700)
committerGary Kotton <gkotton@vmware.com>
Tue, 6 Oct 2015 09:59:20 +0000 (02:59 -0700)
There are edge cases when the agent attempts to unplug an interface and
the device does not exist.

Change-Id: I6917ec94f685f3dd3bff6aa1d43dc56aab76274a
Closes-bug: #1498370

neutron/agent/linux/dhcp.py
neutron/tests/unit/agent/dhcp/test_agent.py

index 9e8b53f20dc724a8203d12f9f9572aaca38d6dc7..279d2ca7bed33f729075e45246eb363e26c6624d 100644 (file)
@@ -1225,7 +1225,10 @@ class DeviceManager(object):
 
     def destroy(self, network, device_name):
         """Destroy the device used for the network's DHCP on this host."""
-        self.driver.unplug(device_name, namespace=network.namespace)
+        if device_name:
+            self.driver.unplug(device_name, namespace=network.namespace)
+        else:
+            LOG.debug('No interface exists for network %s', network.id)
 
         self.plugin.release_dhcp_port(network.id,
                                       self.get_device_id(network))
index ae5594a8ef2653ae6b8e009e0e96db10fcdc2d63..89ff045f553fda1e2c3f2c2bbdc637f1a7cb54e4 100644 (file)
@@ -1393,6 +1393,26 @@ class TestDeviceManager(base.BaseTestCase):
             plugin.assert_has_calls(
                 [mock.call.release_dhcp_port(fake_net.id, mock.ANY)])
 
+    def test_destroy_with_none(self):
+        fake_net = dhcp.NetModel(
+            True, dict(id=FAKE_NETWORK_UUID,
+                       tenant_id='aaaaaaaa-aaaa-aaaa-aaaaaaaaaaaa'))
+
+        with mock.patch('neutron.agent.linux.interface.NullDriver') as dvr_cls:
+            mock_driver = mock.MagicMock()
+            mock_driver.get_device_name.return_value = 'tap12345678-12'
+            dvr_cls.return_value = mock_driver
+
+            plugin = mock.Mock()
+
+            dh = dhcp.DeviceManager(cfg.CONF, plugin)
+            dh.destroy(fake_net, None)
+
+            dvr_cls.assert_called_once_with(cfg.CONF)
+            plugin.assert_has_calls(
+                [mock.call.release_dhcp_port(fake_net.id, mock.ANY)])
+            self.assertFalse(mock_driver.called)
+
     def test_get_interface_name(self):
         fake_net = dhcp.NetModel(
             True, dict(id='12345678-1234-5678-1234567890ab',