Merge "Don't allow user to enable QAT chart"

This commit is contained in:
Zuul 2024-05-07 15:04:41 +00:00 committed by Gerrit Code Review
commit 9013af7035
3 changed files with 97 additions and 1 deletions

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2018 Wind River Systems, Inc.
# Copyright (c) 2018-2024 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@ -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,20 @@ 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'

View File

@ -553,3 +553,72 @@ class ApiHelmChartPatchTestSuiteMixin(ApiHelmChartTestCaseMixin):
# Verify that the helm override was updated
response = self.get_json(url, expect_errors=True)
self.assertEqual(response.json['user_overrides'], None)
class ApiHelmChartPatchTestSuiteQat(ApiHelmChartTestCaseMixin):
""" Helm Chart Attribute Modify Operations
"""
def setUp(self):
super(ApiHelmChartPatchTestSuiteQat, self).setUp()
self._create_db_app_qat()
def _create_db_app_qat(self, obj_id=None):
return dbutils.create_test_app(id=obj_id, name='intel-device-plugins-operator',
app_version='1.0-8',
manifest_name='intel-device-plugins-operator-manifest',
manifest_file='manifest.yaml',
status='applied',
active=True)
def _mock_returncode(self, returncode):
# mock returncode
mock_subprocess = mock.MagicMock()
mock_output = mock.MagicMock()
mock_output.returncode = returncode
p1 = mock.patch('subprocess.run', mock_subprocess)
p1.start().return_value = mock_output
self.addCleanup(p1.stop)
cmd = 'lspci -n | grep -E -c "{}:({}|{})"'.format(8086, 4940, 4942)
mock_subprocess(cmd)
def test_helm_chart_attribute_modify_qat_success(self):
self._mock_returncode(0)
# Return system apps
self.fake_helm_apps.return_value = ['intel-device-plugins-operator']
# Return helm chart overrides
self.fake_override.return_value = {"enabled": False}
# Pass a non existant field to be patched by the API
url = self.get_single_url_helm_override('intel-device-plugins-operator',
'intel-device-plugins-qat',
'intel-device-plugins-operator')
response = self.patch_json(url, {'attributes': {"enabled": "true"},
'flag': '', 'values': {}},
headers=self.API_HEADERS,
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, http_client.OK)
self.assertEqual(response.json['attributes'], {'enabled': True})
def test_helm_chart_attribute_modify_qat_failure(self):
self._mock_returncode(1)
# Return system apps
self.fake_helm_apps.return_value = ['intel-device-plugins-operator']
# Return helm chart overrides
self.fake_override.return_value = {"enabled": False}
# Pass a non existant field to be patched by the API
url = self.get_single_url_helm_override('intel-device-plugins-operator',
'intel-device-plugins-qat',
'intel-device-plugins-operator')
response = self.patch_json(url, {'attributes': {"enabled": "true"},
'flag': '', 'values': {}},
headers=self.API_HEADERS,
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, http_client.BAD_REQUEST)
self.assertIn("Unable to update the helm chart attributes for chart "
"intel-device-plugins-qat under Namespace "
"intel-device-plugins-operator. Error: QAT device not "
"found", response.json['error_message'])