Skip to content

Commit

Permalink
Added Redfish API for following operation
Browse files Browse the repository at this point in the history
Reading a BIOS attribute using Redfish API
Set value to BIOS attribute using Redfish API
IOEnlarger capacity BIOS attribute can be update and read using

Signed-off-by: Maram Srimannarayana Murthy <msmurthy@linux.vnet.ibm.com>
  • Loading branch information
maramsmurthy committed May 8, 2024
1 parent 7e75b5a commit 10c385b
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 3 deletions.
16 changes: 16 additions & 0 deletions common/OpTestEBMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
'''
Expand Down
36 changes: 36 additions & 0 deletions common/OpTestUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
41 changes: 38 additions & 3 deletions testcases/MachineConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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.")
Expand All @@ -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:
Expand Down Expand Up @@ -356,16 +362,17 @@ 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
self.lpar_name = lpar_name
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):

Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 10c385b

Please sign in to comment.