Removing pod argument for activate_vif method.

PodVIFDriver base class defines activate_vif method, which currently
accepts two arguments - pod and vif. While vif argument is utilized for
most of the time, pod is not.

It was discovered during development, where there is a need for calling
activate_vif method from within a CRD resource rather than pod.

Change-Id: I6367bd93d5c0abe9a2ee6d018d997209f23f5318
This commit is contained in:
Roman Dobosz 2020-06-23 13:36:44 +02:00
parent 258c708b85
commit 8b92062593
12 changed files with 19 additions and 26 deletions

View File

@ -388,7 +388,7 @@ class PodVIFDriver(DriverBase, metaclass=abc.ABCMeta):
raise NotImplementedError() raise NotImplementedError()
@abc.abstractmethod @abc.abstractmethod
def activate_vif(self, pod, vif): def activate_vif(self, vif):
"""Updates VIF to become active. """Updates VIF to become active.
Implementing drivers should update the specified `vif` object's Implementing drivers should update the specified `vif` object's
@ -403,7 +403,6 @@ class PodVIFDriver(DriverBase, metaclass=abc.ABCMeta):
This method may be called before, after or while the VIF is being This method may be called before, after or while the VIF is being
plugged by the CNI plugin. plugged by the CNI plugin.
:param pod: dict containing Kubernetes Pod object
:param vif: VIF object as returned by `PodVIFDriver.request_vif` :param vif: VIF object as returned by `PodVIFDriver.request_vif`
""" """
raise NotImplementedError() raise NotImplementedError()

View File

@ -64,7 +64,7 @@ class NestedDpdkPodVIFDriver(nested_vif.NestedPodVIFDriver):
vif.id, vm_id) vif.id, vm_id)
raise raise
def activate_vif(self, pod, vif): def activate_vif(self, vif):
# NOTE(danil): new virtual interface was created in nova instance # NOTE(danil): new virtual interface was created in nova instance
# during request_vif call, thus if it was not created successfully # during request_vif call, thus if it was not created successfully
# an exception o_exc.SDKException would be throwed. During binding # an exception o_exc.SDKException would be throwed. During binding

View File

@ -85,7 +85,7 @@ class NestedMacvlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
LOG.warning("Unable to release port %s as it no longer exists.", LOG.warning("Unable to release port %s as it no longer exists.",
vif.id) vif.id)
def activate_vif(self, pod, vif): def activate_vif(self, vif):
# NOTE(mchiappe): there is no way to get feedback on the actual # NOTE(mchiappe): there is no way to get feedback on the actual
# interface creation or activation as no plugging can happen for this # interface creation or activation as no plugging can happen for this
# interface type. However the status of the port is not relevant as # interface type. However the status of the port is not relevant as

View File

@ -77,7 +77,7 @@ class NeutronPodVIFDriver(base.PodVIFDriver):
def release_vif(self, pod, vif, project_id=None, security_groups=None): def release_vif(self, pod, vif, project_id=None, security_groups=None):
clients.get_network_client().delete_port(vif.id) clients.get_network_client().delete_port(vif.id)
def activate_vif(self, pod, vif): def activate_vif(self, vif):
if vif.active: if vif.active:
return return

View File

@ -69,7 +69,7 @@ class SriovVIFDriver(neutron_vif.NeutronPodVIFDriver):
self._reduce_remaining_sriov_vfs(pod, physnet) self._reduce_remaining_sriov_vfs(pod, physnet)
return vif return vif
def activate_vif(self, pod, vif): def activate_vif(self, vif):
vif.active = True vif.active = True
def _get_physnet_subnet_mapping(self): def _get_physnet_subnet_mapping(self):

View File

@ -117,8 +117,8 @@ class NoopVIFPool(base.VIFPoolDriver):
def release_vif(self, pod, vif, *argv): def release_vif(self, pod, vif, *argv):
self._drv_vif.release_vif(pod, vif, *argv) self._drv_vif.release_vif(pod, vif, *argv)
def activate_vif(self, pod, vif): def activate_vif(self, vif):
self._drv_vif.activate_vif(pod, vif) self._drv_vif.activate_vif(vif)
def update_vif_sgs(self, pod, sgs): def update_vif_sgs(self, pod, sgs):
self._drv_vif.update_vif_sgs(pod, sgs) self._drv_vif.update_vif_sgs(pod, sgs)
@ -166,8 +166,8 @@ class BaseVIFPool(base.VIFPoolDriver, metaclass=abc.ABCMeta):
def set_vif_driver(self, driver): def set_vif_driver(self, driver):
self._drv_vif = driver self._drv_vif = driver
def activate_vif(self, pod, vif): def activate_vif(self, vif):
self._drv_vif.activate_vif(pod, vif) self._drv_vif.activate_vif(vif)
def update_vif_sgs(self, pod, sgs): def update_vif_sgs(self, pod, sgs):
self._drv_vif.update_vif_sgs(pod, sgs) self._drv_vif.update_vif_sgs(pod, sgs)
@ -1068,9 +1068,9 @@ class MultiVIFPool(base.VIFPoolDriver):
vif_drv_alias = self._get_vif_drv_alias(vif) vif_drv_alias = self._get_vif_drv_alias(vif)
self._vif_drvs[vif_drv_alias].release_vif(pod, vif, *argv) self._vif_drvs[vif_drv_alias].release_vif(pod, vif, *argv)
def activate_vif(self, pod, vif): def activate_vif(self, vif):
vif_drv_alias = self._get_vif_drv_alias(vif) vif_drv_alias = self._get_vif_drv_alias(vif)
self._vif_drvs[vif_drv_alias].activate_vif(pod, vif) self._vif_drvs[vif_drv_alias].activate_vif(vif)
def update_vif_sgs(self, pod, sgs): def update_vif_sgs(self, pod, sgs):
pod_vif_type = self._get_pod_vif_type(pod) pod_vif_type = self._get_pod_vif_type(pod)

View File

@ -145,7 +145,7 @@ class VIFHandler(k8s_base.ResourceEventHandler):
driver_utils.update_port_pci_info(pod, vif) driver_utils.update_port_pci_info(pod, vif)
if not vif.active: if not vif.active:
try: try:
self._drv_vif_pool.activate_vif(pod, vif) self._drv_vif_pool.activate_vif(vif)
changed = True changed = True
except os_exc.ResourceNotFound: except os_exc.ResourceNotFound:
LOG.debug("Port not found, possibly already " LOG.debug("Port not found, possibly already "

View File

@ -219,10 +219,9 @@ class TestNestedDpdkVIFDriver(test_base.TestCase):
def test_activate_vif(self, active_value): def test_activate_vif(self, active_value):
cls = nested_dpdk_vif.NestedDpdkPodVIFDriver cls = nested_dpdk_vif.NestedDpdkPodVIFDriver
m_driver = mock.Mock(spec=cls) m_driver = mock.Mock(spec=cls)
pod = mock.sentinel.pod
vif = mock.Mock() vif = mock.Mock()
vif.active = active_value vif.active = active_value
cls.activate_vif(m_driver, pod, vif) cls.activate_vif(m_driver, vif)
self.assertEqual(vif.active, True) self.assertEqual(vif.active, True)

View File

@ -230,11 +230,10 @@ class TestNestedMacvlanPodVIFDriver(test_base.TestCase):
def test_activate_vif(self, active_value): def test_activate_vif(self, active_value):
cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver
m_driver = mock.Mock(spec=cls) m_driver = mock.Mock(spec=cls)
pod = mock.sentinel.pod
vif = mock.Mock() vif = mock.Mock()
vif.active = active_value vif.active = active_value
cls.activate_vif(m_driver, pod, vif) cls.activate_vif(m_driver, vif)
self.assertEqual(vif.active, True) self.assertEqual(vif.active, True)

View File

@ -184,7 +184,6 @@ class NeutronPodVIFDriver(test_base.TestCase):
m_driver = mock.Mock(spec=cls) m_driver = mock.Mock(spec=cls)
os_net = self.useFixture(k_fix.MockNetworkClient()).client os_net = self.useFixture(k_fix.MockNetworkClient()).client
pod = mock.sentinel.pod
vif = mock.Mock() vif = mock.Mock()
vif.active = False vif.active = False
port = mock.MagicMock() port = mock.MagicMock()
@ -192,7 +191,7 @@ class NeutronPodVIFDriver(test_base.TestCase):
port.__getitem__.return_value = kl_const.PORT_STATUS_ACTIVE port.__getitem__.return_value = kl_const.PORT_STATUS_ACTIVE
os_net.get_port.return_value = port os_net.get_port.return_value = port
cls.activate_vif(m_driver, pod, vif) cls.activate_vif(m_driver, vif)
os_net.get_port.assert_called_once_with(vif.id) os_net.get_port.assert_called_once_with(vif.id)
self.assertTrue(vif.active) self.assertTrue(vif.active)
@ -202,11 +201,10 @@ class NeutronPodVIFDriver(test_base.TestCase):
m_driver = mock.Mock(spec=cls) m_driver = mock.Mock(spec=cls)
os_net = self.useFixture(k_fix.MockNetworkClient()).client os_net = self.useFixture(k_fix.MockNetworkClient()).client
pod = mock.sentinel.pod
vif = mock.Mock() vif = mock.Mock()
vif.active = True vif.active = True
cls.activate_vif(m_driver, pod, vif) cls.activate_vif(m_driver, vif)
os_net.get_port.assert_not_called() os_net.get_port.assert_not_called()
@ -215,7 +213,6 @@ class NeutronPodVIFDriver(test_base.TestCase):
m_driver = mock.Mock(spec=cls) m_driver = mock.Mock(spec=cls)
os_net = self.useFixture(k_fix.MockNetworkClient()).client os_net = self.useFixture(k_fix.MockNetworkClient()).client
pod = mock.sentinel.pod
vif = mock.Mock() vif = mock.Mock()
vif.active = False vif.active = False
port = mock.MagicMock() port = mock.MagicMock()
@ -224,7 +221,7 @@ class NeutronPodVIFDriver(test_base.TestCase):
os_net.get_port.return_value = port os_net.get_port.return_value = port
self.assertRaises(k_exc.ResourceNotReady, cls.activate_vif, self.assertRaises(k_exc.ResourceNotReady, cls.activate_vif,
m_driver, pod, vif) m_driver, vif)
def _test_get_port_request(self, m_to_fips, security_groups, def _test_get_port_request(self, m_to_fips, security_groups,
m_get_device_id, m_get_port_name, m_get_host_id, m_get_device_id, m_get_port_name, m_get_host_id,

View File

@ -71,11 +71,10 @@ class TestSriovVIFDriver(test_base.TestCase):
cls = drvs.SriovVIFDriver cls = drvs.SriovVIFDriver
m_driver = mock.Mock(spec=cls) m_driver = mock.Mock(spec=cls)
pod = mock.sentinel.pod
vif = mock.Mock() vif = mock.Mock()
vif.active = False vif.active = False
cls.activate_vif(m_driver, pod, vif) cls.activate_vif(m_driver, vif)
self.assertEqual(True, vif.active) self.assertEqual(True, vif.active)
@mock.patch('kuryr_kubernetes.os_vif_util.osvif_to_neutron_fixed_ips') @mock.patch('kuryr_kubernetes.os_vif_util.osvif_to_neutron_fixed_ips')

View File

@ -247,7 +247,7 @@ class TestVIFHandler(test_base.TestCase):
m_get_pod_state.assert_called_once_with(self._pod) m_get_pod_state.assert_called_once_with(self._pod)
m_update_pci.assert_called_once_with(self._pod, self._vif) m_update_pci.assert_called_once_with(self._pod, self._vif)
self._activate_vif.assert_called_once_with(self._pod, self._vif) self._activate_vif.assert_called_once_with(self._vif)
self._set_pod_state.assert_called_once_with(self._pod, self._state) self._set_pod_state.assert_called_once_with(self._pod, self._state)
self._request_vif.assert_not_called() self._request_vif.assert_not_called()
self._request_additional_vifs.assert_not_called() self._request_additional_vifs.assert_not_called()