From 97a2518aad6fe25821adcd8a3facdb2e6b4d093d Mon Sep 17 00:00:00 2001 From: Maram Srimannarayana Murthy Date: Tue, 25 Jun 2024 21:06:22 +0530 Subject: [PATCH 1/2] Added Redfish API for following operation Reading a BIOS attribute using Redfish API Set value to BIOS attribute using Redfish API IOEnlarger capacity BIOS attribute can be updated and read Added call for FSP to set IO enlarge capacity value Signed-off-by: Maram Srimannarayana Murthy --- common/OpTestEBMC.py | 92 ++++++++++++++++++++++++++++++++++++++ testcases/MachineConfig.py | 64 ++++++++++++++++++++++++-- 2 files changed, 153 insertions(+), 3 deletions(-) diff --git a/common/OpTestEBMC.py b/common/OpTestEBMC.py index aad104740..fd576127b 100644 --- a/common/OpTestEBMC.py +++ b/common/OpTestEBMC.py @@ -19,6 +19,7 @@ # permissions and limitations under the License. +import os import time import requests import json @@ -127,6 +128,97 @@ def wait_for_bmc_runtime(self, timeout=10): key=['Status', 'State'], minutes=timeout) return status + + def set_attribute_redfish(self, uri, attribute_name, attribute_value): + """ + Changing any attribute value using Redfish API + + :param uri: redfish uri at which the attribute can be updated + :param attribute_name: Should be same as attribute name in redfish + :param attribute_value: Value want be be updated for attribute + """ + auth_token = self.generate_ssl_auth_token(ip_add=self.conf.args.bmc_ip) + content_type = "-H 'Content-Type: application/json'" + rest_server = "https://{}{}".format(self.conf.args.bmc_ip, uri) + attribute_param = '\'{"Attributes":{'+'{}:{}'.format(attribute_name, attribute_value)+'}}\'' + curl_command = "curl -k -H"+" 'X-Auth-Token: "+auth_token+"' "+content_type+f" -X PATCH {rest_server} "+f"-d {attribute_param}" + log.info("Command to set attribut: "+curl_command) + try: + output = os.system(curl_command) + return output + except CommandFailed as cf: + return cf.output + + def generate_ssl_auth_token(self, ip_add = None): + """ + Generates ssl key then returns the ssl key + """ + payload = { + "username": self.conf.args.bmc_username, + "password": self.conf.args.bmc_password + } + uri = f"https://{ip_add}/redfish/v1/SessionService/Sessions" + creds = '{"UserName":\"'+ self.conf.args.bmc_username + '","Password":\"' + self.conf.args.bmc_password + '"}' + file_name = "/tmp/headers-"+time.strftime("%Y%m%d%H%M%S")+".txt" + sess_cmd = 'curl -k -H "Content-Type: application/json" -X POST -D '+file_name+" "+uri+' -d '+"\'"+creds+"\'" + os.system(sess_cmd) + auth_file = open(file_name) + token = auth_file.read() + token = [line for line in token.split("\n") if "X-Auth-Token" in line][0].split(":")[1].strip() + if token: + return token + else: + log.info("Token not found in response") + return None + + def get_bios_attribute_value(self, bios_attribute=None, minutes=BMC_CONST.HTTP_RETRY): + """ + Get BIOS current attribute value using redfish api + """ + uri = "/redfish/v1/Systems/system/Bios" + r = self.conf.util_bmc_server.get(uri=uri, minutes=minutes) + return r.json().get("Attributes").get(bios_attribute) + + def set_bios_attribute(self, bios_attribute=None, bios_attribute_val=None): + ''' + Set BMC BIOS attribute to provided value + ''' + uri = '/redfish/v1/Systems/system/Bios/Settings' + return self.set_attribute_redfish(uri=uri, + attribute_name='"'+bios_attribute+'"', + attribute_value=bios_attribute_val) + + def configure_enlarged_io(self, iocapacity): + """ + Calling set IO Enlarge capacity if provided value is not same as current value + """ + cur_iocapacity = self.get_current_ioadapter_enlarged_capacity() + log.info("Setting up ioenlarge capacity") + log.info("Current ioenlarge capacity value:"+str(cur_iocapacity)) + if cur_iocapacity != iocapacity: + self.set_ioenlarge_capacity(iocapacity) + else: + log.info("Provided IO Enlarge capacity value is same as current value, Exiting...") + + def get_current_ioadapter_enlarged_capacity(self): + """ + Get ioadapter enlarged capcity value + """ + log.debug("=====Get current IOAdapter Enlarge Capacity=====") + return self.get_bios_attribute_value( + bios_attribute="hb_ioadapter_enlarged_capacity_current" + ) + + def set_ioenlarge_capacity(self, iocapacity): + """ + Set ioadapter enlarged capcity value + """ + log.debug("=====Set IOAdapter Enlarge Capacity=====") + self.set_bios_attribute( + bios_attribute="hb_ioadapter_enlarged_capacity", + bios_attribute_val=iocapacity + ) + class OpTestEBMC(): diff --git a/testcases/MachineConfig.py b/testcases/MachineConfig.py index 560ff222d..d27f0a93e 100755 --- a/testcases/MachineConfig.py +++ b/testcases/MachineConfig.py @@ -33,8 +33,10 @@ import OpTestConfiguration import OpTestLogger +from common import OpTestASM from common import OpTestHMC from common import OpTestInstallUtil +from common.OpTestEBMC import EBMCHostManagement from common.OpTestUtil import OpTestUtil from common.OpTestSystem import OpSystemState @@ -59,6 +61,7 @@ def setUp(self): self.lpar_prof = conf.args.lpar_prof self.util = OpTestUtil(conf) self.lpar_flag = False + self.cv_BMC = self.cv_SYSTEM.bmc try: self.lpar_list = conf.args.lpar_list except AttributeError: @@ -141,6 +144,7 @@ def callConfig(self, key, lpar=""): if key == "cec": lmb_size = None num_hugepages = None + ioenlargecapacity = None setup = 0 if not self.cv_HMC.lpar_vios: self.skipTest("Please pass lpar_vios in config file.") @@ -159,10 +163,16 @@ def callConfig(self, key, lpar=""): num_hugepages = re.findall( 'hugepages=[0-9]+', str(self.machine_config))[0].split('=')[1] + if "iocapacity" in config_value: + setup=1 + if self.bmc_type in ["EBMC_PHYP", "FSP_PHYP"]: + ioenlargecapacity = re.findall( + 'iocapacity=[0-9]+', str(self.machine_config))[0].split('=')[1] status = CecConfig(self.cv_HMC, self.system_name, self.lpar_name, self.lpar_prof, lmb=lmb_size, - hugepages=num_hugepages).CecSetup() + hugepages=num_hugepages, iocapacity=ioenlargecapacity, + bmc_type=self.bmc_type, bmc=self.cv_SYSTEM.bmc).CecSetup() if status: self.fail(status) if not setup: @@ -471,7 +481,8 @@ class CecConfig(): ''' def __init__(self, cv_HMC=None, system_name=None, - lpar_name=None, lpar_prof=None, lmb=None, hugepages=None): + lpar_name=None, lpar_prof=None, lmb=None, hugepages=None, + iocapacity=None, bmc_type=None, bmc=None): self.cv_HMC = cv_HMC self.system_name = system_name @@ -480,7 +491,13 @@ def __init__(self, cv_HMC=None, system_name=None, self.lmb_size = lmb self.num_hugepages = hugepages self.setup = 0 - self.cec_dict = {'lmb_cec': None, 'hugepages': None} + self.iocapacity = iocapacity + self.cec_dict = {'lmb_cec': None, 'hugepages': None, 'iocapacity': None} + self.config = OpTestConfiguration.conf + self.bmc_type = bmc_type + self.bmc = bmc + if self.bmc_type == "FSP_PHYP" and iocapacity is not None: + self.bmc.cv_ASM.configure_enlarged_io(iocapacity) def CecSetup(self): @@ -491,6 +508,11 @@ def CecSetup(self): self.lmb_setup() if self.cec_dict['hugepages'] is not None: self.hugepage_16gb_setup() + if self.cec_dict['iocapacity'] is not None: + if bmc_type == "EBMC_PHYP": + self.io_enlarge_cpacity() + elif bmc_type == "FSP_PHYP": + self.cv_ASM.configure_enlarged_io(self.iocapacity) if self.setup: self.cv_HMC.poweron_system() self.ValidateCEC_Setup() @@ -516,6 +538,11 @@ def ValidateCEC_Setup(self): self.setting_16gb_hugepage_profile() else: self.cec_dict['hugepages'] = self.num_hugepages + if self.iocapacity: + if self.bmc_type == "FSP_PHYP": + self.bmc.cv_ASM.configure_enlarged_io(self.iocapacity) + else: + self.io_enlarge_capacity() def lmb_setup(self): # Configure the lmb as per user request @@ -533,6 +560,37 @@ def setting_16gb_hugepage_profile(self): int(self.current_hgpg[0])) self.cv_HMC.set_lpar_cfg(attrs) + def io_enlarge_capacity(self): + """ + Calling set IO Enlarge capacity if provided value is not same as current value + """ + cur_iocapacity = self.get_current_ioadapter_enlarged_capacity() + log.info("Setting up ioenlarge capacity") + log.info("Current ioenlarge capacity value:"+str(cur_iocapacity)) + if cur_iocapacity != self.iocapacity: + self.set_ioenlarge_capacity() + else: + log.info("Provided IO Enlarge capacity value is same as current value, Exiting...") + + def get_current_ioadapter_enlarged_capacity(self): + """ + Get ioadapter enlarged capcity value + """ + log.debug("=====Get current IOAdapter Enlarge Capacity=====") + return self.bmc.rest_api.get_bios_attribute_value( + bios_attribute="hb_ioadapter_enlarged_capacity_current" + ) + + def set_ioenlarge_capacity(self): + """ + Set ioadapter enlarged capcity value + """ + log.debug("=====Set IOAdapter Enlarge Capacity=====") + self.bmc.rest_api.set_bios_attribute( + bios_attribute="hb_ioadapter_enlarged_capacity", + bios_attribute_val=self.iocapacity + ) + class OsConfig(): ''' From 3d8a34bae666daa588bdc9dae0d6a0f243aa627c Mon Sep 17 00:00:00 2001 From: Abdul Haleem Date: Tue, 19 Nov 2024 19:14:19 +0530 Subject: [PATCH 2/2] MachineConfig.py: Optimised ioenlarge capacity to reuse api's Removed duplicate API's in both common and machineconf file and simplified to make use of bmc.rest_api to call configured_enlarge_io() Signed-off-by: Abdul Haleem --- testcases/MachineConfig.py | 38 ++------------------------------------ 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/testcases/MachineConfig.py b/testcases/MachineConfig.py index d27f0a93e..cfac37a0d 100755 --- a/testcases/MachineConfig.py +++ b/testcases/MachineConfig.py @@ -36,7 +36,6 @@ from common import OpTestASM from common import OpTestHMC from common import OpTestInstallUtil -from common.OpTestEBMC import EBMCHostManagement from common.OpTestUtil import OpTestUtil from common.OpTestSystem import OpSystemState @@ -496,8 +495,6 @@ def __init__(self, cv_HMC=None, system_name=None, self.config = OpTestConfiguration.conf self.bmc_type = bmc_type self.bmc = bmc - if self.bmc_type == "FSP_PHYP" and iocapacity is not None: - self.bmc.cv_ASM.configure_enlarged_io(iocapacity) def CecSetup(self): @@ -510,7 +507,7 @@ def CecSetup(self): self.hugepage_16gb_setup() if self.cec_dict['iocapacity'] is not None: if bmc_type == "EBMC_PHYP": - self.io_enlarge_cpacity() + self.bmc.rest_api.configure_enlarged_io(self.iocapacity) elif bmc_type == "FSP_PHYP": self.cv_ASM.configure_enlarged_io(self.iocapacity) if self.setup: @@ -542,7 +539,7 @@ def ValidateCEC_Setup(self): if self.bmc_type == "FSP_PHYP": self.bmc.cv_ASM.configure_enlarged_io(self.iocapacity) else: - self.io_enlarge_capacity() + self.bmc.rest_api.configure_enlarged_io(self.iocapacity) def lmb_setup(self): # Configure the lmb as per user request @@ -560,37 +557,6 @@ def setting_16gb_hugepage_profile(self): int(self.current_hgpg[0])) self.cv_HMC.set_lpar_cfg(attrs) - def io_enlarge_capacity(self): - """ - Calling set IO Enlarge capacity if provided value is not same as current value - """ - cur_iocapacity = self.get_current_ioadapter_enlarged_capacity() - log.info("Setting up ioenlarge capacity") - log.info("Current ioenlarge capacity value:"+str(cur_iocapacity)) - if cur_iocapacity != self.iocapacity: - self.set_ioenlarge_capacity() - else: - log.info("Provided IO Enlarge capacity value is same as current value, Exiting...") - - def get_current_ioadapter_enlarged_capacity(self): - """ - Get ioadapter enlarged capcity value - """ - log.debug("=====Get current IOAdapter Enlarge Capacity=====") - return self.bmc.rest_api.get_bios_attribute_value( - bios_attribute="hb_ioadapter_enlarged_capacity_current" - ) - - def set_ioenlarge_capacity(self): - """ - Set ioadapter enlarged capcity value - """ - log.debug("=====Set IOAdapter Enlarge Capacity=====") - self.bmc.rest_api.set_bios_attribute( - bios_attribute="hb_ioadapter_enlarged_capacity", - bios_attribute_val=self.iocapacity - ) - class OsConfig(): '''