diff --git a/common/OpTestEBMC.py b/common/OpTestEBMC.py index 4346e2f77..69963ef63 100644 --- a/common/OpTestEBMC.py +++ b/common/OpTestEBMC.py @@ -27,6 +27,7 @@ from .OpTestSSH import OpTestSSH from .OpTestBMC import OpTestBMC from .Exceptions import HTTPCheck +from .OpTestUtil import OpTestUtil from .OpTestConstants import OpTestConstants as BMC_CONST import OpTestLogger @@ -73,6 +74,21 @@ def get_host_state(self, minutes=BMC_CONST.HTTP_RETRY): uri = '/redfish/v1/Systems/system/' r = self.conf.util_bmc_server.get(uri=uri, minutes=minutes) return r.json().get('BootProgress').get("LastState") + + 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/Memory/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/Memory/BiosSettings' + return OpTestUtil.set_attribute_redfish(uri, bios_attribute, bios_attribute_val) def get_bmc_state(self): ''' diff --git a/common/OpTestUtil.py b/common/OpTestUtil.py index e933f72bd..ac1a587ff 100644 --- a/common/OpTestUtil.py +++ b/common/OpTestUtil.py @@ -2347,6 +2347,42 @@ def prepare_source(self,spec_file, host, dest_path, package, build_option=None): return host.host_run_command(f"ls -d -- {dest_path}/* | grep {package}")[0] except OpTestError: return "" + + 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() + content_type = "-H 'Content-Type: application/json'" + rest_server = "https://{}/{}".format(self.conf.args.bmc_ip, uri) + attribute_param = '{"Attributes":{{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}" + try: + output = self.run_command(term_obj, curl_command) + except CommandFailed as cf: + return cf.output + return output + + def generate_ssl_auth_token(self, ip_add = self.conf.args.bmc_ip): + """ + Generates ssl key and returns the ssl key + """ + payload = { + "username": self.conf.args.bmc_username, + "password": self.conf.args.bmc_password + } + response = requests.post("https://{ip_add}/redfish/v1/SessionService/Sessions", + json=payload) + token = reponse.json.get("token") + if token: + return token + else: + print("Token not found in response") + return None class Server(object): diff --git a/testcases/MachineConfig.py b/testcases/MachineConfig.py index b81ffadba..d74b8349d 100755 --- a/testcases/MachineConfig.py +++ b/testcases/MachineConfig.py @@ -36,6 +36,7 @@ from common import OpTestInstallUtil from common.OpTestUtil import OpTestUtil from common.OpTestSystem import OpSystemState +from common.OpTestEBMC import EBMCHostManagement log = OpTestLogger.optest_logger_glob.get_logger(__name__) @@ -98,6 +99,7 @@ def callConfig(self, key): 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.") @@ -113,8 +115,12 @@ def callConfig(self, key): setup = 1 num_hugepages = re.findall( 'hugepages=[0-9]+', str(self.machine_config))[0].split('=')[1] + if "iocapacity" in config_value: + setup = 1 + 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() + status = CecConfig(self.cv_HMC,self.system_name,self.lpar_name,self.lpar_prof,lmb=lmb_size,hugepages=num_hugepages,iocapacity=ioenlargecapacity).CecSetup() if status: self.fail(status) if not setup: @@ -356,7 +362,7 @@ class CecConfig(): Ex: machine_config={"cec":"hugepages=4"} ''' 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): self.cv_HMC = cv_HMC self.system_name = system_name @@ -364,8 +370,9 @@ def __init__(self, cv_HMC=None, system_name= None, self.lpar_prof = lpar_prof self.lmb_size = lmb self.num_hugepages = hugepages + self.ioenlargecapacity = iocapacity self.setup = 0 - self.cec_dict = {'lmb_cec': None, 'hugepages': None} + self.cec_dict = {'lmb_cec': None, 'hugepages': None, 'iocapcity': None} def CecSetup(self): @@ -376,6 +383,8 @@ 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: + self.io_enlarge_cpacity() if self.setup: self.cv_HMC.poweron_system() self.ValidateCEC_Setup() @@ -400,6 +409,8 @@ def ValidateCEC_Setup(self): self.setting_16gb_hugepage_profile() else: self.cec_dict['hugepages'] = self.num_hugepages + if self.ioenlargecapacity: + self.io_enlarge_capacity() def lmb_setup(self): #Configure the lmb as per user request @@ -417,6 +428,30 @@ def setting_16gb_hugepage_profile(self): int(self.current_hgpg[0])) self.cv_HMC.set_lpar_cfg(attrs) + def io_enlarge_capacity(self): + cur_iocapacity = self.get_current_ioadapter_enlarged_capacity() + if cur_iocapacity != self.ioenlargecapacity: + self.set_ioenlarge_capacity() + + def get_current_ioadapter_enlarged_capacity(self): + """ + Get ioadapter enlarged capcity value + """ + log.debug("=====Get current IOAdapter Enlarge Capacity=====") + return EBMCHostManagement.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=====") + EBMCHostManagement.set_bios_attribute( + bios_attribute="hb_ioadapter_enlarged_capacity", + bios_attribute_val=self.ioenlargecapacity + ) + class OsConfig(): ''' This Class assign huge page in the system based on MMU either Radix or hash and validate