Browse Source

Extend the IPoIBInterfaceDriver to support link_up parameter

The neutron dhcp agent plug_new function was changed to have
a link_up parameter, this patch add the support for the new
parameter.

Change-Id: I2c79c262ac2761569b598ee4506bdfae4461e2eb
tags/16.0.0
abdallahyas 3 months ago
parent
commit
ce293ab496
2 changed files with 29 additions and 15 deletions
  1. +7
    -4
      networking_mlnx/linux/interface_drivers/interface.py
  2. +22
    -11
      networking_mlnx/tests/unit/linux/interface_drivers/test_interface.py

+ 7
- 4
networking_mlnx/linux/interface_drivers/interface.py View File

@@ -48,7 +48,8 @@ class IPoIBInterfaceDriver(n_interface.LinuxInterfaceDriver):
LOG.error("IPoIB root device %s does not exist.", self.root_dev)

def plug_new(self, network_id, port_id, device_name, mac_address,
bridge=None, namespace=None, prefix=None, mtu=None):
bridge=None, namespace=None, prefix=None, mtu=None,
link_up=True):
"""Plugin the interface."""
ip = ip_lib.IPoIBWrapper(namespace=namespace)
try:
@@ -56,7 +57,8 @@ class IPoIBInterfaceDriver(n_interface.LinuxInterfaceDriver):
fields=[constants.SEGMENTATION_ID])[0]
segmentation_id = net.get(constants.SEGMENTATION_ID)
dev = ip.add_ipoib(device_name, self.root_dev, segmentation_id)
dev.link.set_up()
if link_up:
dev.link.set_up()
except RuntimeError as e:
LOG.error("Failed plugging interface '%s' - %s",
device_name, str(e))
@@ -257,7 +259,8 @@ class MultiInterfaceDriver(n_interface.LinuxInterfaceDriver):
return None

def plug_new(self, network_id, port_id, device_name, mac_address,
bridge=None, namespace=None, prefix=None, mtu=None):
bridge=None, namespace=None, prefix=None, mtu=None,
link_up=True):
"""Plugin the interface."""
network = MultiInterfaceDriver.network_cache.get(network_id)
physnet = network.get(constants.PHYSICAL_NETWORK)
@@ -267,7 +270,7 @@ class MultiInterfaceDriver(n_interface.LinuxInterfaceDriver):
try:
driver = self.drivers[physnet]
driver.plug_new(network_id, port_id, device_name, mac_address,
bridge, namespace, prefix, mtu)
bridge, namespace, prefix, mtu, link_up)
except KeyError:
LOG.error("Interface driver not found for physnet: %s", physnet)



+ 22
- 11
networking_mlnx/tests/unit/linux/interface_drivers/test_interface.py View File

@@ -72,17 +72,23 @@ class TestIPoIBInterfaceDriver(base.TestCase):
self.addCleanup(patcher.stop)
return ip_mock_inst

def _test_plug_new(self, net_id, dev_name):
def _test_plug_new(self, net_id, dev_name, link_up=True):
ip_mock = self._mock_ipoib_wrapper()
ip_dev_mock = mock.Mock()
ip_mock.add_ipoib.return_value = ip_dev_mock
return
self.driver.plug_new(net_id, uuids.port_id, dev_name,
None)
ip_mock.add_ipoib.assert_called_with(
dev_name, self.root_dev,
int(network_db[uuids.uuids.vlan_net][constants.SEGMENTATION_ID]))
ip_dev_mock.link.set_up.asset_called_once()
None, link_up)
if net_id == uuids.flat_net:
ip_mock.add_ipoib.assert_called_with(
dev_name, self.root_dev, None)
else:
ip_mock.add_ipoib.assert_called_with(
dev_name, self.root_dev,
network_db[uuids.vlan_net][constants.SEGMENTATION_ID])
if link_up:
ip_dev_mock.link.set_up.asset_called_once()
else:
ip_dev_mock.link.asset_not_called()

def test_plug_new_vlan_network(self):
self._test_plug_new(uuids.vlan_net, "my-ipoib-netdev")
@@ -90,6 +96,9 @@ class TestIPoIBInterfaceDriver(base.TestCase):
def test_plug_new_flat_network(self):
self._test_plug_new(uuids.flat_net, "my-ipoib-netdev")

def test_plug_new_link_unchanged(self):
self._test_plug_new(uuids.vlan_net, "my-ipoib-netdev", False)

@mock.patch("networking_mlnx.linux.interface_drivers.interface.LOG")
def test_plug_new_ip_lib_raises(self, log_mock):
ip_mock = self._mock_ipoib_wrapper()
@@ -403,13 +412,15 @@ class TestMultiInterfaceDriver(base.TestCase):
ns = 'test-ns'
# network with physnet
driver.plug_new(uuids.vlan_net, uuids.vlan_port, device_name, mac,
bridge=None, namespace=ns, prefix=None, mtu=None)
bridge=None, namespace=ns, prefix=None, mtu=None,
link_up=True)
driver.drivers['datacenter'].plug_new.assert_called_once_with(
uuids.vlan_net, uuids.vlan_port, device_name, mac, None, ns, None,
None)
None, True)
# network without physnet
driver.plug_new(uuids.vxlan_net, uuids.vxlan_port, device_name, mac,
bridge=None, namespace=ns, prefix=None, mtu=None)
bridge=None, namespace=ns, prefix=None, mtu=None,
link_up=True)
driver.drivers['nil'].plug_new.assert_called_once_with(
uuids.vxlan_net, uuids.vxlan_port, device_name, mac, None, ns,
None, None)
None, None, True)

Loading…
Cancel
Save