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 28, 2024
1 parent 7e75b5a commit 6f0e2f1
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 3 deletions.
19 changes: 19 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 @@ -54,6 +55,7 @@ def __init__(self, conf=None,
self.conf.util.setup(config='REST')
r = self.conf.util_bmc_server.login()
self.wait_for_bmc_runtime()
self.op_test_util = OpTestUtil(conf)

def get_power_state(self, minutes=BMC_CONST.HTTP_RETRY):
'''
Expand All @@ -73,6 +75,23 @@ 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/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.op_test_util.set_attribute_redfish(uri=uri,
attribute_name=bios_attribute,
attribute_value=bios_attribute_val)

def get_bmc_state(self):
'''
Expand Down
42 changes: 42 additions & 0 deletions common/OpTestUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,48 @@ 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(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}"
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 and 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.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]
token = token[0].split(":")[1].strip()
if token:
return token
else:
print("Token not found in response")
return None


class Server(object):
Expand Down
48 changes: 45 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,22 @@ 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, 'iocapacity': None}
self.config = OpTestConfiguration.conf
self.BMCHostMgmt = EBMCHostManagement(conf=self.config,
ip=self.config.args.bmc_ip,
username=self.config.args.bmc_username,
password=self.config.args.bmc_password)

def CecSetup(self):

Expand All @@ -376,6 +388,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 +414,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 +433,32 @@ 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()
log.info(cur_iocapacity)
log.info(self.ioenlargecapacity)
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 self.BMCHostMgmt.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.BMCHostMgmt.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 6f0e2f1

Please sign in to comment.