Add container_id to connect method of BaseBindingDriver

container_id is necessary for VHostUserDriver, binding driver
writes its configuration to file which contains part of container id,
to be able to distinguish conf files inside containers (for case when
vhostuser socket dir mounted to several pods).

Partially-Implements: support-vhost-user-port-type-on-bm-installation
Change-Id: I328585dc6d596371d8511a3cb5ccef907d955c76
Signed-off-by: Alexey Perevalov <a.perevalov@samsung.com>
This commit is contained in:
Alexey Perevalov 2018-08-28 03:39:06 -04:00
parent 3086c34c0f
commit 0478a47502
6 changed files with 31 additions and 23 deletions

View File

@ -30,11 +30,11 @@ class BaseBindingDriver(object):
"""Interface to attach ports to pods.""" """Interface to attach ports to pods."""
@abc.abstractmethod @abc.abstractmethod
def connect(self, vif, ifname, netns): def connect(self, vif, ifname, netns, container_id):
raise NotImplementedError() raise NotImplementedError()
@abc.abstractmethod @abc.abstractmethod
def disconnect(self, vif, ifname, netns): def disconnect(self, vif, ifname, netns, container_id):
raise NotImplementedError() raise NotImplementedError()
@ -92,19 +92,19 @@ def _configure_l3(vif, ifname, netns, is_default_gateway):
def connect(vif, instance_info, ifname, netns=None, report_health=None, def connect(vif, instance_info, ifname, netns=None, report_health=None,
is_default_gateway=True): is_default_gateway=True, container_id=None):
driver = _get_binding_driver(vif) driver = _get_binding_driver(vif)
if report_health: if report_health:
report_health(driver.is_healthy()) report_health(driver.is_healthy())
os_vif.plug(vif, instance_info) os_vif.plug(vif, instance_info)
driver.connect(vif, ifname, netns) driver.connect(vif, ifname, netns, container_id)
_configure_l3(vif, ifname, netns, is_default_gateway) _configure_l3(vif, ifname, netns, is_default_gateway)
def disconnect(vif, instance_info, ifname, netns=None, report_health=None, def disconnect(vif, instance_info, ifname, netns=None, report_health=None,
**kwargs): container_id=None, **kwargs):
driver = _get_binding_driver(vif) driver = _get_binding_driver(vif)
if report_health: if report_health:
report_health(driver.is_healthy()) report_health(driver.is_healthy())
driver.disconnect(vif, ifname, netns) driver.disconnect(vif, ifname, netns, container_id)
os_vif.unplug(vif, instance_info) os_vif.unplug(vif, instance_info)

View File

@ -29,7 +29,7 @@ class BaseBridgeDriver(health.HealthHandler, b_base.BaseBindingDriver):
def __init__(self): def __init__(self):
super(BaseBridgeDriver, self).__init__() super(BaseBridgeDriver, self).__init__()
def connect(self, vif, ifname, netns): def connect(self, vif, ifname, netns, container_id):
host_ifname = vif.vif_name host_ifname = vif.vif_name
with b_base.get_ipdb() as h_ipdb: with b_base.get_ipdb() as h_ipdb:
@ -67,7 +67,7 @@ class BaseBridgeDriver(health.HealthHandler, b_base.BaseBindingDriver):
h_iface.mtu = interface_mtu h_iface.mtu = interface_mtu
h_iface.up() h_iface.up()
def disconnect(self, vif, ifname, netns): def disconnect(self, vif, ifname, netns, container_id):
pass pass
@ -75,8 +75,8 @@ class BridgeDriver(BaseBridgeDriver):
def __init__(self): def __init__(self):
super(BridgeDriver, self).__init__() super(BridgeDriver, self).__init__()
def connect(self, vif, ifname, netns): def connect(self, vif, ifname, netns, container_id):
super(BridgeDriver, self).connect(vif, ifname, netns) super(BridgeDriver, self).connect(vif, ifname, netns, container_id)
host_ifname = vif.vif_name host_ifname = vif.vif_name
bridge_name = vif.bridge_name bridge_name = vif.bridge_name
@ -84,7 +84,7 @@ class BridgeDriver(BaseBridgeDriver):
with h_ipdb.interfaces[bridge_name] as h_br: with h_ipdb.interfaces[bridge_name] as h_br:
h_br.add_port(host_ifname) h_br.add_port(host_ifname)
def disconnect(self, vif, ifname, netns): def disconnect(self, vif, ifname, netns, container_id):
# NOTE(ivc): veth pair is destroyed automatically along with the # NOTE(ivc): veth pair is destroyed automatically along with the
# container namespace # container namespace
pass pass
@ -95,16 +95,18 @@ class VIFOpenVSwitchDriver(BaseBridgeDriver):
def __init__(self): def __init__(self):
super(VIFOpenVSwitchDriver, self).__init__() super(VIFOpenVSwitchDriver, self).__init__()
def connect(self, vif, ifname, netns): def connect(self, vif, ifname, netns, container_id):
super(VIFOpenVSwitchDriver, self).connect(vif, ifname, netns) super(VIFOpenVSwitchDriver, self).connect(vif, ifname, netns,
container_id)
# FIXME(irenab) use pod_id (neutron port device_id) # FIXME(irenab) use pod_id (neutron port device_id)
instance_id = 'kuryr' instance_id = 'kuryr'
net_utils.create_ovs_vif_port(vif.bridge_name, vif.vif_name, net_utils.create_ovs_vif_port(vif.bridge_name, vif.vif_name,
vif.port_profile.interface_id, vif.port_profile.interface_id,
vif.address, instance_id) vif.address, instance_id)
def disconnect(self, vif, ifname, netns): def disconnect(self, vif, ifname, netns, container_id):
super(VIFOpenVSwitchDriver, self).disconnect(vif, ifname, netns) super(VIFOpenVSwitchDriver, self).disconnect(vif, ifname, netns,
container_id)
net_utils.delete_ovs_vif_port(vif.bridge_name, vif.vif_name) net_utils.delete_ovs_vif_port(vif.bridge_name, vif.vif_name)
def is_healthy(self): def is_healthy(self):

View File

@ -35,7 +35,7 @@ class NestedDriver(health.HealthHandler, b_base.BaseBindingDriver):
def _get_iface_create_args(self, vif): def _get_iface_create_args(self, vif):
raise NotImplementedError() raise NotImplementedError()
def connect(self, vif, ifname, netns): def connect(self, vif, ifname, netns, container_id):
with b_base.get_ipdb() as h_ipdb: with b_base.get_ipdb() as h_ipdb:
# NOTE(vikasc): Ideally 'ifname' should be used here but instead a # NOTE(vikasc): Ideally 'ifname' should be used here but instead a
# temporary name is being used while creating the device for # temporary name is being used while creating the device for
@ -62,7 +62,7 @@ class NestedDriver(health.HealthHandler, b_base.BaseBindingDriver):
iface.address = str(vif.address) iface.address = str(vif.address)
iface.up() iface.up()
def disconnect(self, vif, ifname, netns): def disconnect(self, vif, ifname, netns, container_id):
# NOTE(vikasc): device will get deleted with container namespace, so # NOTE(vikasc): device will get deleted with container namespace, so
# nothing to be done here. # nothing to be done here.
pass pass

View File

@ -111,7 +111,8 @@ class AddHandler(CNIHandlerBase):
is_default_gateway = (ifname == self._cni.CNI_IFNAME) is_default_gateway = (ifname == self._cni.CNI_IFNAME)
b_base.connect(_vif, self._get_inst(pod), b_base.connect(_vif, self._get_inst(pod),
ifname, self._cni.CNI_NETNS, ifname, self._cni.CNI_NETNS,
is_default_gateway=is_default_gateway) is_default_gateway=is_default_gateway,
container_id=self._cni.CNI_CONTAINERID)
def should_callback(self, pod, vifs): def should_callback(self, pod, vifs):
"""Called after all vifs have been processed """Called after all vifs have been processed
@ -147,7 +148,8 @@ class DelHandler(CNIHandlerBase):
def on_vif(self, pod, vif, ifname): def on_vif(self, pod, vif, ifname):
b_base.disconnect(vif, self._get_inst(pod), b_base.disconnect(vif, self._get_inst(pod),
self._cni.CNI_IFNAME, self._cni.CNI_NETNS) self._cni.CNI_IFNAME, self._cni.CNI_NETNS,
container_id=self._cni.CNI_CONTAINERID)
def should_callback(self, pod, vifs): def should_callback(self, pod, vifs):
"""Called after all vifs have been processed """Called after all vifs have been processed

View File

@ -131,7 +131,8 @@ class K8sCNIRegistryPlugin(base_cni.CNIPlugin):
is_default_gateway = (ifname == params.CNI_IFNAME) is_default_gateway = (ifname == params.CNI_IFNAME)
fn(vif, self._get_inst(pod), ifname, params.CNI_NETNS, fn(vif, self._get_inst(pod), ifname, params.CNI_NETNS,
report_health=self.report_drivers_health, report_health=self.report_drivers_health,
is_default_gateway=is_default_gateway) is_default_gateway=is_default_gateway,
container_id=params.CNI_CONTAINERID)
return vifs return vifs
def _get_inst(self, pod): def _get_inst(self, pod):

View File

@ -45,7 +45,8 @@ class TestK8sCNIRegistryPlugin(base.TestCase):
m_lock.assert_called_with('default/foo', external=True) m_lock.assert_called_with('default/foo', external=True)
m_connect.assert_called_with(mock.ANY, mock.ANY, 'eth0', 123, m_connect.assert_called_with(mock.ANY, mock.ANY, 'eth0', 123,
report_health=mock.ANY, report_health=mock.ANY,
is_default_gateway=mock.ANY) is_default_gateway=mock.ANY,
container_id='cont_id')
self.assertEqual('cont_id', self.assertEqual('cont_id',
self.plugin.registry['default/foo']['containerid']) self.plugin.registry['default/foo']['containerid'])
@ -55,7 +56,8 @@ class TestK8sCNIRegistryPlugin(base.TestCase):
m_disconnect.assert_called_with(mock.ANY, mock.ANY, 'eth0', 123, m_disconnect.assert_called_with(mock.ANY, mock.ANY, 'eth0', 123,
report_health=mock.ANY, report_health=mock.ANY,
is_default_gateway=mock.ANY) is_default_gateway=mock.ANY,
container_id='cont_id')
@mock.patch('kuryr_kubernetes.cni.binding.base.disconnect') @mock.patch('kuryr_kubernetes.cni.binding.base.disconnect')
def test_del_wrong_container_id(self, m_disconnect): def test_del_wrong_container_id(self, m_disconnect):
@ -88,7 +90,8 @@ class TestK8sCNIRegistryPlugin(base.TestCase):
'containerid': 'cont_id'}) 'containerid': 'cont_id'})
m_connect.assert_called_with(mock.ANY, mock.ANY, 'eth0', 123, m_connect.assert_called_with(mock.ANY, mock.ANY, 'eth0', 123,
report_health=mock.ANY, report_health=mock.ANY,
is_default_gateway=mock.ANY) is_default_gateway=mock.ANY,
container_id='cont_id')
@mock.patch('time.sleep', mock.Mock()) @mock.patch('time.sleep', mock.Mock())
def test_add_not_present(self): def test_add_not_present(self):