Skip to content

Commit f10437f

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 updated and read Signed-off-by: Maram Srimannarayana Murthy <[email protected]>
1 parent 4ca0d5b commit f10437f

File tree

2 files changed

+113
-3
lines changed

2 files changed

+113
-3
lines changed

common/OpTestEBMC.py

+60
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# permissions and limitations under the License.
2020

2121

22+
import os
2223
import time
2324
import requests
2425
import json
@@ -127,6 +128,65 @@ def wait_for_bmc_runtime(self, timeout=10):
127128
key=['Status', 'State'],
128129
minutes=timeout)
129130
return status
131+
132+
def set_attribute_redfish(self, uri, attribute_name, attribute_value):
133+
"""
134+
Changing any attribute value using Redfish API
135+
136+
:param uri: redfish uri at which the attribute can be updated
137+
:param attribute_name: Should be same as attribute name in redfish
138+
:param attribute_value: Value want be be updated for attribute
139+
"""
140+
auth_token = self.generate_ssl_auth_token(ip_add=self.conf.args.bmc_ip)
141+
content_type = "-H 'Content-Type: application/json'"
142+
rest_server = "https://{}{}".format(self.conf.args.bmc_ip, uri)
143+
attribute_param = '\'{"Attributes":{'+'{}:{}'.format(attribute_name, attribute_value)+'}}\''
144+
curl_command = "curl -k -H"+" 'X-Auth-Token: "+auth_token+"' "+content_type+f" -X PATCH {rest_server} "+f"-d {attribute_param}"
145+
log.info("Command to set attribut: "+curl_command)
146+
try:
147+
output = os.system(curl_command)
148+
return output
149+
except CommandFailed as cf:
150+
return cf.output
151+
152+
def generate_ssl_auth_token(self, ip_add = None):
153+
"""
154+
Generates ssl key then returns the ssl key
155+
"""
156+
payload = {
157+
"username": self.conf.args.bmc_username,
158+
"password": self.conf.args.bmc_password
159+
}
160+
uri = f"https://{ip_add}/redfish/v1/SessionService/Sessions"
161+
creds = '{"UserName":\"'+ self.conf.args.bmc_username + '","Password":\"' + self.conf.args.bmc_password + '"}'
162+
file_name = "/tmp/headers-"+time.strftime("%Y%m%d%H%M%S")+".txt"
163+
sess_cmd = 'curl -k -H "Content-Type: application/json" -X POST -D '+file_name+" "+uri+' -d '+"\'"+creds+"\'"
164+
os.system(sess_cmd)
165+
auth_file = open(file_name)
166+
token = auth_file.read()
167+
token = [line for line in token.split("\n") if "X-Auth-Token" in line][0].split(":")[1].strip()
168+
if token:
169+
return token
170+
else:
171+
log.info("Token not found in response")
172+
return None
173+
174+
def get_bios_attribute_value(self, bios_attribute=None, minutes=BMC_CONST.HTTP_RETRY):
175+
"""
176+
Get BIOS current attribute value using redfish api
177+
"""
178+
uri = "/redfish/v1/Systems/system/Bios"
179+
r = self.conf.util_bmc_server.get(uri=uri, minutes=minutes)
180+
return r.json().get("Attributes").get(bios_attribute)
181+
182+
def set_bios_attribute(self, bios_attribute=None, bios_attribute_val=None):
183+
'''
184+
Set BMC BIOS attribute to provided value
185+
'''
186+
uri = '/redfish/v1/Systems/system/Bios/Settings'
187+
return self.set_attribute_redfish(uri=uri,
188+
attribute_name='"'+bios_attribute+'"',
189+
attribute_value=bios_attribute_val)
130190

131191

132192
class OpTestEBMC():

testcases/MachineConfig.py

+53-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333

3434
import OpTestConfiguration
3535
import OpTestLogger
36+
from common import OpTestASM
3637
from common import OpTestHMC
3738
from common import OpTestInstallUtil
39+
from common.OpTestEBMC import EBMCHostManagement
3840
from common.OpTestUtil import OpTestUtil
3941
from common.OpTestSystem import OpSystemState
4042

@@ -140,6 +142,7 @@ def callConfig(self, key, lpar=""):
140142
if key == "cec":
141143
lmb_size = None
142144
num_hugepages = None
145+
ioenlargecapacity = None
143146
setup = 0
144147
if not self.cv_HMC.lpar_vios:
145148
self.skipTest("Please pass lpar_vios in config file.")
@@ -158,10 +161,15 @@ def callConfig(self, key, lpar=""):
158161
num_hugepages = re.findall(
159162
'hugepages=[0-9]+',
160163
str(self.machine_config))[0].split('=')[1]
164+
if "iocapacity" in config_value:
165+
setup=1
166+
if self.bmc_type == "EBMC_PHYP":
167+
ioenlargecapacity = re.findall(
168+
'iocapacity=[0-9]+', str(self.machine_config))[0].split('=')[1]
161169

162170
status = CecConfig(self.cv_HMC, self.system_name, self.lpar_name,
163171
self.lpar_prof, lmb=lmb_size,
164-
hugepages=num_hugepages).CecSetup()
172+
hugepages=num_hugepages, iocapacity=ioenlargecapacity).CecSetup()
165173
if status:
166174
self.fail(status)
167175
if not setup:
@@ -474,7 +482,8 @@ class CecConfig():
474482
'''
475483

476484
def __init__(self, cv_HMC=None, system_name=None,
477-
lpar_name=None, lpar_prof=None, lmb=None, hugepages=None):
485+
lpar_name=None, lpar_prof=None, lmb=None, hugepages=None,
486+
iocapacity=None):
478487

479488
self.cv_HMC = cv_HMC
480489
self.system_name = system_name
@@ -483,7 +492,13 @@ def __init__(self, cv_HMC=None, system_name=None,
483492
self.lmb_size = lmb
484493
self.num_hugepages = hugepages
485494
self.setup = 0
486-
self.cec_dict = {'lmb_cec': None, 'hugepages': None}
495+
self.iocapacity = iocapacity
496+
self.cec_dict = {'lmb_cec': None, 'hugepages': None, 'iocapacity': None}
497+
self.config = OpTestConfiguration.conf
498+
self.BMCHostMgmt = EBMCHostManagement(conf=self.config,
499+
ip=self.config.args.bmc_ip,
500+
username=self.config.args.bmc_username,
501+
password=self.config.args.bmc_password)
487502

488503
def CecSetup(self):
489504

@@ -494,6 +509,8 @@ def CecSetup(self):
494509
self.lmb_setup()
495510
if self.cec_dict['hugepages'] is not None:
496511
self.hugepage_16gb_setup()
512+
if self.cec_dict['iocapacity'] is not None:
513+
self.io_enlarge_cpacity()
497514
if self.setup:
498515
self.cv_HMC.poweron_system()
499516
self.ValidateCEC_Setup()
@@ -519,6 +536,8 @@ def ValidateCEC_Setup(self):
519536
self.setting_16gb_hugepage_profile()
520537
else:
521538
self.cec_dict['hugepages'] = self.num_hugepages
539+
if self.iocapacity:
540+
self.io_enlarge_capacity()
522541

523542
def lmb_setup(self):
524543
# Configure the lmb as per user request
@@ -536,6 +555,37 @@ def setting_16gb_hugepage_profile(self):
536555
int(self.current_hgpg[0]))
537556
self.cv_HMC.set_lpar_cfg(attrs)
538557

558+
def io_enlarge_capacity(self):
559+
"""
560+
Calling set IO Enlarge capacity if provided value is not same as current value
561+
"""
562+
cur_iocapacity = self.get_current_ioadapter_enlarged_capacity()
563+
log.info("Setting up ioenlarge capacity")
564+
log.info("Current ioenlarge capacity value:"+str(cur_iocapacity))
565+
if cur_iocapacity != self.iocapacity:
566+
self.set_ioenlarge_capacity()
567+
else:
568+
log.info("Provided IO Enlarge capacity value is same as current value, Exiting...")
569+
570+
def get_current_ioadapter_enlarged_capacity(self):
571+
"""
572+
Get ioadapter enlarged capcity value
573+
"""
574+
log.debug("=====Get current IOAdapter Enlarge Capacity=====")
575+
return self.BMCHostMgmt.get_bios_attribute_value(
576+
bios_attribute="hb_ioadapter_enlarged_capacity_current"
577+
)
578+
579+
def set_ioenlarge_capacity(self):
580+
"""
581+
Set ioadapter enlarged capcity value
582+
"""
583+
log.debug("=====Set IOAdapter Enlarge Capacity=====")
584+
self.BMCHostMgmt.set_bios_attribute(
585+
bios_attribute="hb_ioadapter_enlarged_capacity",
586+
bios_attribute_val=self.iocapacity
587+
)
588+
539589

540590
class OsConfig():
541591
'''

0 commit comments

Comments
 (0)