Merge "add semantic validation for label "intelgpu:enabled"" into r/stx.3.0
This commit is contained in:
commit
19c5060234
|
@ -3,6 +3,8 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
import json
|
||||
import os
|
||||
import pecan
|
||||
from pecan import rest
|
||||
import wsme
|
||||
|
@ -204,6 +206,8 @@ class LabelController(rest.RestController):
|
|||
|
||||
_semantic_check_worker_labels(body)
|
||||
|
||||
_semantic_check_k8s_plugins_labels(host, body)
|
||||
|
||||
existing_labels = {}
|
||||
for label_key in body.keys():
|
||||
label = None
|
||||
|
@ -348,3 +352,35 @@ def _semantic_check_worker_labels(body):
|
|||
raise wsme.exc.ClientSideError(
|
||||
_(
|
||||
"Invalid value for %s label." % constants.KUBE_CPU_MANAGER_LABEL))
|
||||
|
||||
|
||||
def _get_system_enabled_k8s_plugins():
|
||||
if not os.path.isfile(constants.ENABLED_KUBE_PLUGINS):
|
||||
return None
|
||||
|
||||
with open(constants.ENABLED_KUBE_PLUGINS) as f:
|
||||
return json.loads(f.read())
|
||||
|
||||
|
||||
def _semantic_check_intel_gpu_plugins_labels(host):
|
||||
pci_devices = pecan.request.dbapi.pci_device_get_by_host(host.id)
|
||||
for pci_device in pci_devices:
|
||||
if ("VGA" in pci_device.pclass and pci_device.driver == "i915"):
|
||||
return
|
||||
|
||||
raise wsme.exc.ClientSideError("Host %s does not support Intel GPU device plugin." % (host.hostname))
|
||||
|
||||
|
||||
def _semantic_check_k8s_plugins_labels(host, body):
|
||||
"""
|
||||
Perform hardware checks to ensure k8s plugins labels are valid on particular node.
|
||||
"""
|
||||
plugins = _get_system_enabled_k8s_plugins()
|
||||
if plugins is None:
|
||||
return
|
||||
|
||||
for label_key, label_value in body.items():
|
||||
label = label_key + "=" + label_value
|
||||
if label in plugins.values():
|
||||
if label == constants.KUBE_INTEL_GPU_DEVICE_PLUGIN_LABEL:
|
||||
_semantic_check_intel_gpu_plugins_labels(host)
|
||||
|
|
|
@ -1549,3 +1549,7 @@ HOST_BM_VALID_TYPE_LIST = [HOST_BM_TYPE_DEPROVISIONED,
|
|||
HOST_BM_VALID_PROVISIONED_TYPE_LIST = [HOST_BM_TYPE_DYNAMIC,
|
||||
HOST_BM_TYPE_IPMI,
|
||||
HOST_BM_TYPE_REDFISH]
|
||||
# K8s device plugins
|
||||
DEVICE_PLUGINS_FILE = "enabled_kube_plugins"
|
||||
ENABLED_KUBE_PLUGINS = os.path.join(tsc.CONFIG_PATH, DEVICE_PLUGINS_FILE)
|
||||
KUBE_INTEL_GPU_DEVICE_PLUGIN_LABEL = "intelgpu=enabled"
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
import mock
|
||||
import platform
|
||||
|
||||
from six.moves import http_client
|
||||
|
@ -157,3 +158,46 @@ class LabelAssignTestCase(LabelTestCase):
|
|||
'kube-topology-mgr-policy': 'invalid',
|
||||
}
|
||||
self.assign_labels_failure(host_uuid, topology_mgr_label)
|
||||
|
||||
def mock_get_system_enabled_k8s_plugins_return_plugins():
|
||||
return {"intel-gpu-plugin": "intelgpu=enabled",
|
||||
"intel-qat-plugin": "intelqat=enabled"}
|
||||
|
||||
def mock_get_system_enabled_k8s_plugins_return_none():
|
||||
return None
|
||||
|
||||
@mock.patch('sysinv.api.controllers.v1.label._get_system_enabled_k8s_plugins',
|
||||
mock_get_system_enabled_k8s_plugins_return_plugins)
|
||||
def test_create_plugin_labels_on_supported_node(self):
|
||||
dbutils.create_test_pci_devices(
|
||||
host_id=self.worker.id,
|
||||
pclass='VGA compatible controller',
|
||||
driver='i915',)
|
||||
|
||||
test_plugin_label = {'intelgpu': 'enabled', }
|
||||
self.assign_labels(self.worker.uuid, test_plugin_label)
|
||||
|
||||
response_data = self.get_host_labels(self.worker.uuid)
|
||||
self.validate_labels(test_plugin_label, response_data)
|
||||
|
||||
@mock.patch('sysinv.api.controllers.v1.label._get_system_enabled_k8s_plugins',
|
||||
mock_get_system_enabled_k8s_plugins_return_plugins)
|
||||
def test_create_plugin_labels_on_unsupported_node(self):
|
||||
dbutils.create_test_pci_devices(
|
||||
host_id=self.worker.id,
|
||||
pclass='VGA compatible controller',
|
||||
driver='',)
|
||||
|
||||
test_plugin_label = {'intelgpu': 'enabled', }
|
||||
|
||||
self.assign_labels_failure(self.worker.uuid, test_plugin_label)
|
||||
|
||||
@mock.patch('sysinv.api.controllers.v1.label._get_system_enabled_k8s_plugins',
|
||||
mock_get_system_enabled_k8s_plugins_return_none)
|
||||
def test_create_plugin_labels_on_non_plugin_system(self):
|
||||
test_plugin_label = {'intelgpu': 'enabled', }
|
||||
|
||||
self.assign_labels(self.worker.uuid, test_plugin_label)
|
||||
|
||||
response_data = self.get_host_labels(self.worker.uuid)
|
||||
self.validate_labels(test_plugin_label, response_data)
|
||||
|
|
Loading…
Reference in New Issue