From 8b920625931b8482bfe415a35899e1150905f8b6 Mon Sep 17 00:00:00 2001 From: Roman Dobosz Date: Tue, 23 Jun 2020 13:36:44 +0200 Subject: [PATCH] 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 --- kuryr_kubernetes/controller/drivers/base.py | 3 +-- .../controller/drivers/nested_dpdk_vif.py | 2 +- .../controller/drivers/nested_macvlan_vif.py | 2 +- kuryr_kubernetes/controller/drivers/neutron_vif.py | 2 +- kuryr_kubernetes/controller/drivers/sriov.py | 2 +- kuryr_kubernetes/controller/drivers/vif_pool.py | 12 ++++++------ kuryr_kubernetes/controller/handlers/vif.py | 2 +- .../unit/controller/drivers/test_nested_dpdk.py | 3 +-- .../controller/drivers/test_nested_macvlan_vif.py | 3 +-- .../unit/controller/drivers/test_neutron_vif.py | 9 +++------ .../tests/unit/controller/drivers/test_sriov.py | 3 +-- .../tests/unit/controller/handlers/test_vif.py | 2 +- 12 files changed, 19 insertions(+), 26 deletions(-) diff --git a/kuryr_kubernetes/controller/drivers/base.py b/kuryr_kubernetes/controller/drivers/base.py index e7303c644..7121044b4 100644 --- a/kuryr_kubernetes/controller/drivers/base.py +++ b/kuryr_kubernetes/controller/drivers/base.py @@ -388,7 +388,7 @@ class PodVIFDriver(DriverBase, metaclass=abc.ABCMeta): raise NotImplementedError() @abc.abstractmethod - def activate_vif(self, pod, vif): + def activate_vif(self, vif): """Updates VIF to become active. 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 plugged by the CNI plugin. - :param pod: dict containing Kubernetes Pod object :param vif: VIF object as returned by `PodVIFDriver.request_vif` """ raise NotImplementedError() diff --git a/kuryr_kubernetes/controller/drivers/nested_dpdk_vif.py b/kuryr_kubernetes/controller/drivers/nested_dpdk_vif.py index 6a5a2c60d..2d977d6df 100644 --- a/kuryr_kubernetes/controller/drivers/nested_dpdk_vif.py +++ b/kuryr_kubernetes/controller/drivers/nested_dpdk_vif.py @@ -64,7 +64,7 @@ class NestedDpdkPodVIFDriver(nested_vif.NestedPodVIFDriver): vif.id, vm_id) raise - def activate_vif(self, pod, vif): + def activate_vif(self, vif): # NOTE(danil): new virtual interface was created in nova instance # during request_vif call, thus if it was not created successfully # an exception o_exc.SDKException would be throwed. During binding diff --git a/kuryr_kubernetes/controller/drivers/nested_macvlan_vif.py b/kuryr_kubernetes/controller/drivers/nested_macvlan_vif.py index 3ea3f05f1..f7dd623fc 100755 --- a/kuryr_kubernetes/controller/drivers/nested_macvlan_vif.py +++ b/kuryr_kubernetes/controller/drivers/nested_macvlan_vif.py @@ -85,7 +85,7 @@ class NestedMacvlanPodVIFDriver(nested_vif.NestedPodVIFDriver): LOG.warning("Unable to release port %s as it no longer exists.", 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 # interface creation or activation as no plugging can happen for this # interface type. However the status of the port is not relevant as diff --git a/kuryr_kubernetes/controller/drivers/neutron_vif.py b/kuryr_kubernetes/controller/drivers/neutron_vif.py index d420441b9..2ffd352f5 100644 --- a/kuryr_kubernetes/controller/drivers/neutron_vif.py +++ b/kuryr_kubernetes/controller/drivers/neutron_vif.py @@ -77,7 +77,7 @@ class NeutronPodVIFDriver(base.PodVIFDriver): def release_vif(self, pod, vif, project_id=None, security_groups=None): clients.get_network_client().delete_port(vif.id) - def activate_vif(self, pod, vif): + def activate_vif(self, vif): if vif.active: return diff --git a/kuryr_kubernetes/controller/drivers/sriov.py b/kuryr_kubernetes/controller/drivers/sriov.py index 7e19578c3..d3411417f 100644 --- a/kuryr_kubernetes/controller/drivers/sriov.py +++ b/kuryr_kubernetes/controller/drivers/sriov.py @@ -69,7 +69,7 @@ class SriovVIFDriver(neutron_vif.NeutronPodVIFDriver): self._reduce_remaining_sriov_vfs(pod, physnet) return vif - def activate_vif(self, pod, vif): + def activate_vif(self, vif): vif.active = True def _get_physnet_subnet_mapping(self): diff --git a/kuryr_kubernetes/controller/drivers/vif_pool.py b/kuryr_kubernetes/controller/drivers/vif_pool.py index 98d544885..809002a97 100644 --- a/kuryr_kubernetes/controller/drivers/vif_pool.py +++ b/kuryr_kubernetes/controller/drivers/vif_pool.py @@ -117,8 +117,8 @@ class NoopVIFPool(base.VIFPoolDriver): def release_vif(self, pod, vif, *argv): self._drv_vif.release_vif(pod, vif, *argv) - def activate_vif(self, pod, vif): - self._drv_vif.activate_vif(pod, vif) + def activate_vif(self, vif): + self._drv_vif.activate_vif(vif) def update_vif_sgs(self, 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): self._drv_vif = driver - def activate_vif(self, pod, vif): - self._drv_vif.activate_vif(pod, vif) + def activate_vif(self, vif): + self._drv_vif.activate_vif(vif) def update_vif_sgs(self, 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) 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) - 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): pod_vif_type = self._get_pod_vif_type(pod) diff --git a/kuryr_kubernetes/controller/handlers/vif.py b/kuryr_kubernetes/controller/handlers/vif.py index 3bee857f2..9ea5cd117 100644 --- a/kuryr_kubernetes/controller/handlers/vif.py +++ b/kuryr_kubernetes/controller/handlers/vif.py @@ -145,7 +145,7 @@ class VIFHandler(k8s_base.ResourceEventHandler): driver_utils.update_port_pci_info(pod, vif) if not vif.active: try: - self._drv_vif_pool.activate_vif(pod, vif) + self._drv_vif_pool.activate_vif(vif) changed = True except os_exc.ResourceNotFound: LOG.debug("Port not found, possibly already " diff --git a/kuryr_kubernetes/tests/unit/controller/drivers/test_nested_dpdk.py b/kuryr_kubernetes/tests/unit/controller/drivers/test_nested_dpdk.py index dfbbf2378..8f0fd4eee 100644 --- a/kuryr_kubernetes/tests/unit/controller/drivers/test_nested_dpdk.py +++ b/kuryr_kubernetes/tests/unit/controller/drivers/test_nested_dpdk.py @@ -219,10 +219,9 @@ class TestNestedDpdkVIFDriver(test_base.TestCase): def test_activate_vif(self, active_value): cls = nested_dpdk_vif.NestedDpdkPodVIFDriver m_driver = mock.Mock(spec=cls) - pod = mock.sentinel.pod vif = mock.Mock() vif.active = active_value - cls.activate_vif(m_driver, pod, vif) + cls.activate_vif(m_driver, vif) self.assertEqual(vif.active, True) diff --git a/kuryr_kubernetes/tests/unit/controller/drivers/test_nested_macvlan_vif.py b/kuryr_kubernetes/tests/unit/controller/drivers/test_nested_macvlan_vif.py index c81764c27..04e578d1b 100644 --- a/kuryr_kubernetes/tests/unit/controller/drivers/test_nested_macvlan_vif.py +++ b/kuryr_kubernetes/tests/unit/controller/drivers/test_nested_macvlan_vif.py @@ -230,11 +230,10 @@ class TestNestedMacvlanPodVIFDriver(test_base.TestCase): def test_activate_vif(self, active_value): cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver m_driver = mock.Mock(spec=cls) - pod = mock.sentinel.pod vif = mock.Mock() vif.active = active_value - cls.activate_vif(m_driver, pod, vif) + cls.activate_vif(m_driver, vif) self.assertEqual(vif.active, True) diff --git a/kuryr_kubernetes/tests/unit/controller/drivers/test_neutron_vif.py b/kuryr_kubernetes/tests/unit/controller/drivers/test_neutron_vif.py index a21e5bfca..33bb35813 100644 --- a/kuryr_kubernetes/tests/unit/controller/drivers/test_neutron_vif.py +++ b/kuryr_kubernetes/tests/unit/controller/drivers/test_neutron_vif.py @@ -184,7 +184,6 @@ class NeutronPodVIFDriver(test_base.TestCase): m_driver = mock.Mock(spec=cls) os_net = self.useFixture(k_fix.MockNetworkClient()).client - pod = mock.sentinel.pod vif = mock.Mock() vif.active = False port = mock.MagicMock() @@ -192,7 +191,7 @@ class NeutronPodVIFDriver(test_base.TestCase): port.__getitem__.return_value = kl_const.PORT_STATUS_ACTIVE 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) self.assertTrue(vif.active) @@ -202,11 +201,10 @@ class NeutronPodVIFDriver(test_base.TestCase): m_driver = mock.Mock(spec=cls) os_net = self.useFixture(k_fix.MockNetworkClient()).client - pod = mock.sentinel.pod vif = mock.Mock() vif.active = True - cls.activate_vif(m_driver, pod, vif) + cls.activate_vif(m_driver, vif) os_net.get_port.assert_not_called() @@ -215,7 +213,6 @@ class NeutronPodVIFDriver(test_base.TestCase): m_driver = mock.Mock(spec=cls) os_net = self.useFixture(k_fix.MockNetworkClient()).client - pod = mock.sentinel.pod vif = mock.Mock() vif.active = False port = mock.MagicMock() @@ -224,7 +221,7 @@ class NeutronPodVIFDriver(test_base.TestCase): os_net.get_port.return_value = port 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, m_get_device_id, m_get_port_name, m_get_host_id, diff --git a/kuryr_kubernetes/tests/unit/controller/drivers/test_sriov.py b/kuryr_kubernetes/tests/unit/controller/drivers/test_sriov.py index 84927c785..abcf05386 100644 --- a/kuryr_kubernetes/tests/unit/controller/drivers/test_sriov.py +++ b/kuryr_kubernetes/tests/unit/controller/drivers/test_sriov.py @@ -71,11 +71,10 @@ class TestSriovVIFDriver(test_base.TestCase): cls = drvs.SriovVIFDriver m_driver = mock.Mock(spec=cls) - pod = mock.sentinel.pod vif = mock.Mock() vif.active = False - cls.activate_vif(m_driver, pod, vif) + cls.activate_vif(m_driver, vif) self.assertEqual(True, vif.active) @mock.patch('kuryr_kubernetes.os_vif_util.osvif_to_neutron_fixed_ips') diff --git a/kuryr_kubernetes/tests/unit/controller/handlers/test_vif.py b/kuryr_kubernetes/tests/unit/controller/handlers/test_vif.py index fd47c14b7..68e66163b 100644 --- a/kuryr_kubernetes/tests/unit/controller/handlers/test_vif.py +++ b/kuryr_kubernetes/tests/unit/controller/handlers/test_vif.py @@ -247,7 +247,7 @@ class TestVIFHandler(test_base.TestCase): m_get_pod_state.assert_called_once_with(self._pod) 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._request_vif.assert_not_called() self._request_additional_vifs.assert_not_called()