Make node annotations with pci addresses optional
This patch adds new option to CM that enables annotations to nodes. Node annotations are useless before sriov-nic-agent is installed on nodes. By default this option is set to False, so annotations will not be set and direct ports will not be active in neutron. Change-Id: Ie6f141df59c601b74fb949a86e92d68115ffa5fb Signed-off-by: Danil Golov <d.golov@samsung.com>
This commit is contained in:
parent
04e61fb82c
commit
cacd08083b
|
@ -53,14 +53,16 @@ class VIFSriovDriver(health.HealthHandler, b_base.BaseBindingDriver):
|
|||
@release_lock_object
|
||||
def connect(self, vif, ifname, netns, container_id):
|
||||
pci_info = self._process_vif(vif, ifname, netns)
|
||||
self._save_pci_info(vif.id, pci_info)
|
||||
if config.CONF.sriov.enable_node_annotations:
|
||||
self._save_pci_info(vif.id, pci_info)
|
||||
|
||||
def disconnect(self, vif, ifname, netns, container_id):
|
||||
# NOTE(k.zaitsev): when netns is deleted the interface is
|
||||
# returned automatically to host netns. We may reset
|
||||
# it to all-zero state
|
||||
self._return_device_driver(vif)
|
||||
self._remove_pci_info(vif.id)
|
||||
if config.CONF.sriov.enable_node_annotations:
|
||||
self._remove_pci_info(vif.id)
|
||||
|
||||
def _process_vif(self, vif, ifname, netns):
|
||||
pr_client = clients.get_pod_resources_client()
|
||||
|
|
|
@ -310,6 +310,12 @@ sriov_opts = [
|
|||
"names. Expected that device of VIF related to "
|
||||
"exact physnet should be binded on specified driver."),
|
||||
default=DEFAULT_PHYSNET_SUBNET_MAPPINGS),
|
||||
cfg.BoolOpt('enable_node_annotations',
|
||||
help=_("Enable node annotations. This option allows to "
|
||||
"set annotations required by neutron to set active "
|
||||
"state of ports. This option is useless when "
|
||||
"sriov-nic-agent is not running on node."),
|
||||
default=False),
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -124,7 +124,8 @@ class VIFHandler(k8s_base.ResourceEventHandler):
|
|||
changed = False
|
||||
try:
|
||||
for ifname, vif in state.vifs.items():
|
||||
if vif.plugin == constants.KURYR_VIF_TYPE_SRIOV:
|
||||
if (vif.plugin == constants.KURYR_VIF_TYPE_SRIOV and
|
||||
oslo_cfg.CONF.sriov.enable_node_annotations):
|
||||
driver_utils.update_port_pci_info(pod, vif)
|
||||
if not vif.active:
|
||||
try:
|
||||
|
|
|
@ -262,6 +262,8 @@ class TestSriovDriver(TestDriverMixin, test_base.TestCase):
|
|||
group='sriov')
|
||||
CONF.set_override('resource_driver_mappings', 'sriov:igbvf',
|
||||
group='sriov')
|
||||
CONF.set_override('enable_node_annotations', True,
|
||||
group='sriov')
|
||||
|
||||
@mock.patch('kuryr_kubernetes.cni.binding.sriov.VIFSriovDriver.'
|
||||
'_save_pci_info')
|
||||
|
@ -273,6 +275,18 @@ class TestSriovDriver(TestDriverMixin, test_base.TestCase):
|
|||
self._test_connect()
|
||||
m_save_pci.assert_called_once_with(self.vif.id, self.pci_info)
|
||||
|
||||
@mock.patch('kuryr_kubernetes.cni.binding.sriov.VIFSriovDriver.'
|
||||
'_save_pci_info')
|
||||
@mock.patch('kuryr_kubernetes.cni.binding.sriov.VIFSriovDriver.'
|
||||
'_process_vif')
|
||||
def test_connect_no_annotations(self, m_proc_vif, m_save_pci):
|
||||
m_proc_vif.return_value = self.pci_info
|
||||
CONF.set_override('enable_node_annotations', False,
|
||||
group='sriov')
|
||||
|
||||
self._test_connect()
|
||||
m_save_pci.assert_not_called()
|
||||
|
||||
@mock.patch('kuryr_kubernetes.cni.binding.sriov.VIFSriovDriver.'
|
||||
'_return_device_driver')
|
||||
@mock.patch('kuryr_kubernetes.cni.binding.sriov.VIFSriovDriver.'
|
||||
|
@ -281,6 +295,19 @@ class TestSriovDriver(TestDriverMixin, test_base.TestCase):
|
|||
m_remove_pci.return_value = None
|
||||
m_return_device.return_value = None
|
||||
self._test_disconnect()
|
||||
m_remove_pci.assert_called_once_with(self.vif.id)
|
||||
|
||||
@mock.patch('kuryr_kubernetes.cni.binding.sriov.VIFSriovDriver.'
|
||||
'_return_device_driver')
|
||||
@mock.patch('kuryr_kubernetes.cni.binding.sriov.VIFSriovDriver.'
|
||||
'_remove_pci_info')
|
||||
def test_disconnect_no_annotations(self, m_remove_pci, m_return_device):
|
||||
m_return_device.return_value = None
|
||||
m_remove_pci.return_value = None
|
||||
CONF.set_override('enable_node_annotations', False,
|
||||
group='sriov')
|
||||
self._test_disconnect()
|
||||
m_remove_pci.assert_not_called()
|
||||
|
||||
@mock.patch('kuryr_kubernetes.clients.get_pod_resources_client')
|
||||
@mock.patch('kuryr_kubernetes.cni.binding.sriov.VIFSriovDriver.'
|
||||
|
|
|
@ -139,14 +139,17 @@ class TestVIFHandler(test_base.TestCase):
|
|||
self.assertFalse(h_vif.VIFHandler._is_pod_scheduled({'spec': {},
|
||||
'status': {}}))
|
||||
|
||||
@mock.patch('oslo_config.cfg.CONF')
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.'
|
||||
'update_port_pci_info')
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.is_host_network')
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_pod_state')
|
||||
def test_on_present(self, m_get_pod_state, m_host_network, m_update_pci):
|
||||
def test_on_present(self, m_get_pod_state, m_host_network, m_update_pci,
|
||||
m_conf):
|
||||
m_get_pod_state.return_value = self._state
|
||||
m_host_network.return_value = False
|
||||
self._vif.plugin = 'sriov'
|
||||
m_conf.sriov.enable_node_annotations = True
|
||||
h_vif.VIFHandler.on_present(self._handler, self._pod)
|
||||
|
||||
m_get_pod_state.assert_called_once_with(self._pod)
|
||||
|
@ -185,18 +188,20 @@ class TestVIFHandler(test_base.TestCase):
|
|||
self._activate_vif.assert_not_called()
|
||||
self._set_pod_state.assert_not_called()
|
||||
|
||||
@mock.patch('oslo_config.cfg.CONF')
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.'
|
||||
'update_port_pci_info')
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_services')
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.is_host_network')
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_pod_state')
|
||||
def test_on_present_activate(self, m_get_pod_state, m_host_network,
|
||||
m_get_services, m_update_pci):
|
||||
m_get_services, m_update_pci, m_conf):
|
||||
m_get_pod_state.return_value = self._state
|
||||
m_host_network.return_value = False
|
||||
m_get_services.return_value = {"items": []}
|
||||
self._vif.active = False
|
||||
self._vif.plugin = 'sriov'
|
||||
m_conf.sriov.enable_node_annotations = True
|
||||
|
||||
h_vif.VIFHandler.on_present(self._handler, self._pod)
|
||||
|
||||
|
|
Loading…
Reference in New Issue