Don't allow user to enable QAT chart

This commit adds the code to raise the error for the following command,
if the hardware does not have 4940 or 4942 QAT devices.
Command: "helm-chart-attribute-modify  --enabled true
intel-device-plugins-operator intel-device-plugins-qat
intel-device-plugins-operator"

TEST CASES:

PASSED: Build is success.
PASSED: Bootstrap is success.
PASSED: Upload the package using command system application-upload.
PASSED: Check chart enabled status using command
        "system helm-override-list intel-device-plugins-operator --long"
PASSED: Enable the QAT chart using command "system
        helm-chart-attribute-modify", raises error in non QAT system.
PASSED: Enable the QAT chart using command "system
        helm-chart-attribute-modify", it should success on QAT system.
PASSED: Disable the QAT chart using command "system
        helm-chart-attribute-modify", it should success in both QAT and
        non QAT system.
PASSED: Apply app intel-device-plugins-operator on both QAT and non QAT
        system is successful.

Story: 2010604
Task: 50027

Change-Id: Ied634cf35b53421bcaa2f8307e76a0fc87d3bb1f
Signed-off-by: Md Irshad Sheikh <mdirshad.sheikh@windriver.com>
This commit is contained in:
Md Irshad Sheikh 2024-05-02 10:30:36 -04:00
parent 159039de4c
commit 02abcb8196
2 changed files with 26 additions and 0 deletions

View File

@ -7,6 +7,7 @@
import pecan
from pecan import rest
import six
import subprocess
import wsme
from wsme import types as wtypes
import wsmeext.pecan as wsme_pecan
@ -15,6 +16,7 @@ import yaml
from oslo_log import log
from sysinv._i18n import _
from sysinv import objects
from sysinv.common import constants
from sysinv.common import exception
from sysinv.helm import common
@ -230,6 +232,13 @@ class HelmChartsController(rest.RestController):
(k, ','.join(common.HELM_CHART_ATTRS)))
if k == common.HELM_CHART_ATTR_ENABLED:
if attributes[k] in ['true', 'True'] and \
name == constants.HELM_APP_INTEL_DEVICE_PLUGIN_QAT:
if (not self._is_qat_device_present(name, namespace)):
raise wsme.exc.ClientSideError(
_("Unable to update the helm chart attributes "
"for chart %s under Namespace %s. "
"Error: QAT device not found." % (name, namespace)))
attributes[k] = attributes[k] in ['true', 'True']
# update the attribute changes
@ -263,3 +272,19 @@ class HelmChartsController(rest.RestController):
raise wsme.exc.ClientSideError(_("Application %s not found." % app_name))
except exception.HelmOverrideNotFound:
pass
def _is_qat_device_present(self, name, namespace):
"""
Check whether the system has QAT device or not.
"""
try:
cmd = 'lspci -n | grep -E -c "{}:({}|{})"'.format(constants.PCI_ALIAS_QAT_VENDOR,
constants.PCI_ALIAS_QAT_4XXX_PF_DEVICE, constants.PCI_ALIAS_QAT_401XX_PF_DEVICE)
output = subprocess.run(cmd, shell=True, check=False, capture_output=True, text=True)
if output.returncode == 0:
return True
return False
except Exception:
raise wsme.exc.ClientSideError(
_("Failed to update the helm chart attributes for chart %s under "
"Namespace %s." % (name, namespace)))

View File

@ -1790,6 +1790,7 @@ HELM_APP_ROOK_CEPH = 'rook-ceph-apps'
HELM_APP_SNMP = 'snmp'
HELM_APP_PTP_NOTIFICATION = 'ptp-notification'
HELM_APP_PORTIERIS = 'portieris'
HELM_APP_INTEL_DEVICE_PLUGIN_QAT = "intel-device-plugins-qat"
# Apply mode for openstack app
OPENSTACK_RESTORE_DB = 'restore_db'