Update sriov neutron ports with pci info

This commit updates neutron sriov ports when
POD that contains it is in Running state.
It makes request to neutron API to update ports
with binding:profile information.
Due to this it is required to make actions with
privileged user having admin rights.

Change-Id: Iade446cefd78b494291729939db7db75692392c9
Closes-Bug: 1818606
Signed-off-by: Danil Golov <d.golov@samsung.com>
This commit is contained in:
Danil Golov 2019-03-12 11:28:02 +03:00
parent b0ce30142e
commit 14a685d9e1
5 changed files with 52 additions and 2 deletions

View File

@ -132,6 +132,12 @@ We have to add to the sriov section following mapping:
physnet_resource_mappings = physnet1:numa0
6. Use privileged user
To make neutron ports active kuryr-k8s makes requests to neutron API to update
ports with binding:profile information. Due to this it is necessary to make
actions with privileged user with admin rights.
Reference
---------

View File

@ -61,6 +61,7 @@ CNI_TIMEOUT_CODE = 200
KURYR_PORT_NAME = 'kuryr-pool-port'
KURYR_L7_ROUTER_HTTP_PORT = '80'
KURYR_VIF_TYPE_SRIOV = 'sriov'
OCTAVIA_L2_MEMBER_MODE = "L2"
OCTAVIA_L3_MEMBER_MODE = "L3"

View File

@ -485,3 +485,36 @@ def get_namespace(namespace_name):
return kubernetes.get(
'{}/namespaces/{}'.format(
constants.K8S_API_BASE, namespace_name))
def update_port_pci_info(pod, vif):
node = get_host_id(pod)
annot_port_pci_info = get_port_annot_pci_info(node, vif.id)
neutron = clients.get_neutron_client()
LOG.debug("Neutron port %s is updated with binding:profile info %s",
vif.id, annot_port_pci_info)
neutron.update_port(
vif.id,
{
"port": {
'binding:profile': annot_port_pci_info
}
})
def get_port_annot_pci_info(nodename, neutron_port):
k8s = clients.get_kubernetes_client()
annot_name = constants.K8S_ANNOTATION_NODE_PCI_DEVICE_INFO
annot_name = annot_name + '-' + neutron_port
node_info = k8s.get('/api/v1/nodes/{}'.format(nodename))
annotations = node_info['metadata']['annotations']
try:
json_pci_info = annotations[annot_name]
pci_info = jsonutils.loads(json_pci_info)
except KeyError:
pci_info = {}
except Exception:
LOG.exception('Exception when reading annotations '
'%s and converting from json', annot_name)
return pci_info

View File

@ -121,6 +121,8 @@ class VIFHandler(k8s_base.ResourceEventHandler):
else:
changed = False
for ifname, vif in state.vifs.items():
if vif.plugin == constants.KURYR_VIF_TYPE_SRIOV:
driver_utils.update_port_pci_info(pod, vif)
if not vif.active:
self._drv_vif_pool.activate_vif(pod, vif)
changed = True

View File

@ -133,14 +133,18 @@ class TestVIFHandler(test_base.TestCase):
self.assertFalse(h_vif.VIFHandler._is_pending_node({'spec': {},
'status': {}}))
@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):
def test_on_present(self, m_get_pod_state, m_host_network, m_update_pci):
m_get_pod_state.return_value = self._state
m_host_network.return_value = False
self._vif.plugin = 'sriov'
h_vif.VIFHandler.on_present(self._handler, self._pod)
m_get_pod_state.assert_called_once_with(self._pod)
m_update_pci.assert_called_once_with(self._pod, self._vif)
self._request_vif.assert_not_called()
self._request_additional_vifs.assert_not_called()
self._activate_vif.assert_not_called()
@ -175,19 +179,23 @@ class TestVIFHandler(test_base.TestCase):
self._activate_vif.assert_not_called()
self._set_pod_state.assert_not_called()
@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_get_services, m_update_pci):
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'
h_vif.VIFHandler.on_present(self._handler, self._pod)
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._set_pod_state.assert_called_once_with(self._pod, self._state)
self._request_vif.assert_not_called()