Skip to content

Commit 10c385b

Browse files
committed
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 update and read using Signed-off-by: Maram Srimannarayana Murthy <[email protected]>
1 parent 7e75b5a commit 10c385b

File tree

3 files changed

+90
-3
lines changed

3 files changed

+90
-3
lines changed

common/OpTestEBMC.py

+16
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from .OpTestSSH import OpTestSSH
2828
from .OpTestBMC import OpTestBMC
2929
from .Exceptions import HTTPCheck
30+
from .OpTestUtil import OpTestUtil
3031
from .OpTestConstants import OpTestConstants as BMC_CONST
3132

3233
import OpTestLogger
@@ -73,6 +74,21 @@ def get_host_state(self, minutes=BMC_CONST.HTTP_RETRY):
7374
uri = '/redfish/v1/Systems/system/'
7475
r = self.conf.util_bmc_server.get(uri=uri, minutes=minutes)
7576
return r.json().get('BootProgress').get("LastState")
77+
78+
def get_bios_attribute_value(self, bios_attribute=None, minutes=BMC_CONST.HTTP_RETRY):
79+
"""
80+
Get BIOS current attribute value using redfish api
81+
"""
82+
uri = "redfish/v1/Systems/system/Memory/Bios"
83+
r = self.conf.util_bmc_server.get(uri=uri, minutes=minutes)
84+
return r.json().get("Attributes").get(bios_attribute)
85+
86+
def set_bios_attribute(self, bios_attribute=None, bios_attribute_val=None):
87+
'''
88+
Set BMC BIOS attribute to provided value
89+
'''
90+
uri = 'redfish/v1/Systems/system/Memory/BiosSettings'
91+
return OpTestUtil.set_attribute_redfish(uri, bios_attribute, bios_attribute_val)
7692

7793
def get_bmc_state(self):
7894
'''

common/OpTestUtil.py

+36
Original file line numberDiff line numberDiff line change
@@ -2347,6 +2347,42 @@ def prepare_source(self,spec_file, host, dest_path, package, build_option=None):
23472347
return host.host_run_command(f"ls -d -- {dest_path}/* | grep {package}")[0]
23482348
except OpTestError:
23492349
return ""
2350+
2351+
def set_attribute_redfish(self, uri, attribute_name, attribute_value):
2352+
"""
2353+
Changing any attribute value using Redfish API
2354+
2355+
:param uri: redfish uri at which the attribute can be updated
2356+
:param attribute_name: Should be same as attribute name in redfish
2357+
:param attribute_value: Value want be be updated for attribute
2358+
"""
2359+
auth_token = self.generate_ssl_auth_token()
2360+
content_type = "-H 'Content-Type: application/json'"
2361+
rest_server = "https://{}/{}".format(self.conf.args.bmc_ip, uri)
2362+
attribute_param = '{"Attributes":{{attribute_name}:{attribute_value}}}'
2363+
curl_command = "curl -k -H X-Auth-Token: "+auth_token+" "+content_type+f" -X PATCH {rest_server} "+f"-d {attribute_param}"
2364+
try:
2365+
output = self.run_command(term_obj, curl_command)
2366+
except CommandFailed as cf:
2367+
return cf.output
2368+
return output
2369+
2370+
def generate_ssl_auth_token(self, ip_add = self.conf.args.bmc_ip):
2371+
"""
2372+
Generates ssl key and returns the ssl key
2373+
"""
2374+
payload = {
2375+
"username": self.conf.args.bmc_username,
2376+
"password": self.conf.args.bmc_password
2377+
}
2378+
response = requests.post("https://{ip_add}/redfish/v1/SessionService/Sessions",
2379+
json=payload)
2380+
token = reponse.json.get("token")
2381+
if token:
2382+
return token
2383+
else:
2384+
print("Token not found in response")
2385+
return None
23502386

23512387

23522388
class Server(object):

testcases/MachineConfig.py

+38-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from common import OpTestInstallUtil
3737
from common.OpTestUtil import OpTestUtil
3838
from common.OpTestSystem import OpSystemState
39+
from common.OpTestEBMC import EBMCHostManagement
3940

4041
log = OpTestLogger.optest_logger_glob.get_logger(__name__)
4142

@@ -98,6 +99,7 @@ def callConfig(self, key):
9899
if key == "cec":
99100
lmb_size= None
100101
num_hugepages = None
102+
ioenlargecapacity = None
101103
setup = 0
102104
if not self.cv_HMC.lpar_vios:
103105
self.skipTest("Please pass lpar_vios in config file.")
@@ -113,8 +115,12 @@ def callConfig(self, key):
113115
setup = 1
114116
num_hugepages = re.findall(
115117
'hugepages=[0-9]+', str(self.machine_config))[0].split('=')[1]
118+
if "iocapacity" in config_value:
119+
setup = 1
120+
ioenlargecapacity = re.findall(
121+
'iocapacity=[0-9]+', str(self.machine_config))[0].split('=')[1]
116122

117-
status = CecConfig(self.cv_HMC,self.system_name,self.lpar_name,self.lpar_prof,lmb=lmb_size,hugepages=num_hugepages).CecSetup()
123+
status = CecConfig(self.cv_HMC,self.system_name,self.lpar_name,self.lpar_prof,lmb=lmb_size,hugepages=num_hugepages,iocapacity=ioenlargecapacity).CecSetup()
118124
if status:
119125
self.fail(status)
120126
if not setup:
@@ -356,16 +362,17 @@ class CecConfig():
356362
Ex: machine_config={"cec":"hugepages=4"}
357363
'''
358364
def __init__(self, cv_HMC=None, system_name= None,
359-
lpar_name=None, lpar_prof=None, lmb=None, hugepages=None):
365+
lpar_name=None, lpar_prof=None, lmb=None, hugepages=None, iocapacity=None):
360366

361367
self.cv_HMC = cv_HMC
362368
self.system_name = system_name
363369
self.lpar_name = lpar_name
364370
self.lpar_prof = lpar_prof
365371
self.lmb_size = lmb
366372
self.num_hugepages = hugepages
373+
self.ioenlargecapacity = iocapacity
367374
self.setup = 0
368-
self.cec_dict = {'lmb_cec': None, 'hugepages': None}
375+
self.cec_dict = {'lmb_cec': None, 'hugepages': None, 'iocapcity': None}
369376

370377
def CecSetup(self):
371378

@@ -376,6 +383,8 @@ def CecSetup(self):
376383
self.lmb_setup()
377384
if self.cec_dict['hugepages'] is not None:
378385
self.hugepage_16gb_setup()
386+
if self.cec_dict['iocapacity'] is not None:
387+
self.io_enlarge_cpacity()
379388
if self.setup:
380389
self.cv_HMC.poweron_system()
381390
self.ValidateCEC_Setup()
@@ -400,6 +409,8 @@ def ValidateCEC_Setup(self):
400409
self.setting_16gb_hugepage_profile()
401410
else:
402411
self.cec_dict['hugepages'] = self.num_hugepages
412+
if self.ioenlargecapacity:
413+
self.io_enlarge_capacity()
403414

404415
def lmb_setup(self):
405416
#Configure the lmb as per user request
@@ -417,6 +428,30 @@ def setting_16gb_hugepage_profile(self):
417428
int(self.current_hgpg[0]))
418429
self.cv_HMC.set_lpar_cfg(attrs)
419430

431+
def io_enlarge_capacity(self):
432+
cur_iocapacity = self.get_current_ioadapter_enlarged_capacity()
433+
if cur_iocapacity != self.ioenlargecapacity:
434+
self.set_ioenlarge_capacity()
435+
436+
def get_current_ioadapter_enlarged_capacity(self):
437+
"""
438+
Get ioadapter enlarged capcity value
439+
"""
440+
log.debug("=====Get current IOAdapter Enlarge Capacity=====")
441+
return EBMCHostManagement.get_bios_attribute_value(
442+
bios_attribute="hb_ioadapter_enlarged_capacity_current"
443+
)
444+
445+
def set_ioenlarge_capacity(self):
446+
"""
447+
Set ioadapter enlarged capcity value
448+
"""
449+
log.debug("=====Set IOAdapter Enlarge Capacity=====")
450+
EBMCHostManagement.set_bios_attribute(
451+
bios_attribute="hb_ioadapter_enlarged_capacity",
452+
bios_attribute_val=self.ioenlargecapacity
453+
)
454+
420455
class OsConfig():
421456
'''
422457
This Class assign huge page in the system based on MMU either Radix or hash and validate

0 commit comments

Comments
 (0)