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 updated and read
Added call for FSP to set IO enlarge capacity value

Signed-off-by: Maram Srimannarayana Murthy <[email protected]>
  • Loading branch information
maramsmurthy committed Oct 28, 2024
1 parent 4ca0d5b commit 36b28cf
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 3 deletions.
92 changes: 92 additions & 0 deletions common/OpTestEBMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# permissions and limitations under the License.


import os
import time
import requests
import json
Expand Down Expand Up @@ -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():
Expand Down
64 changes: 61 additions & 3 deletions testcases/MachineConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -140,6 +143,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.")
Expand All @@ -158,10 +162,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:
Expand Down Expand Up @@ -474,7 +484,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
Expand All @@ -483,7 +494,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):

Expand All @@ -494,6 +511,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()
Expand All @@ -519,6 +541,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
Expand All @@ -536,6 +563,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():
'''
Expand Down

0 comments on commit 36b28cf

Please sign in to comment.