Skip to content

Commit ad3cf04

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 Added call for FSP to set IO enlarge capacity value Signed-off-by: Maram Srimannarayana Murthy <[email protected]>
1 parent ed2e949 commit ad3cf04

File tree

2 files changed

+153
-3
lines changed

2 files changed

+153
-3
lines changed

common/OpTestEBMC.py

+92
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,97 @@ 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)
190+
191+
def configure_enlarged_io(self, iocapacity):
192+
"""
193+
Calling set IO Enlarge capacity if provided value is not same as current value
194+
"""
195+
cur_iocapacity = self.get_current_ioadapter_enlarged_capacity()
196+
log.info("Setting up ioenlarge capacity")
197+
log.info("Current ioenlarge capacity value:"+str(cur_iocapacity))
198+
if cur_iocapacity != iocapacity:
199+
self.set_ioenlarge_capacity(iocapacity)
200+
else:
201+
log.info("Provided IO Enlarge capacity value is same as current value, Exiting...")
202+
203+
def get_current_ioadapter_enlarged_capacity(self):
204+
"""
205+
Get ioadapter enlarged capcity value
206+
"""
207+
log.debug("=====Get current IOAdapter Enlarge Capacity=====")
208+
return self.get_bios_attribute_value(
209+
bios_attribute="hb_ioadapter_enlarged_capacity_current"
210+
)
211+
212+
def set_ioenlarge_capacity(self, iocapacity):
213+
"""
214+
Set ioadapter enlarged capcity value
215+
"""
216+
log.debug("=====Set IOAdapter Enlarge Capacity=====")
217+
self.set_bios_attribute(
218+
bios_attribute="hb_ioadapter_enlarged_capacity",
219+
bios_attribute_val=iocapacity
220+
)
221+
130222

131223

132224
class OpTestEBMC():

testcases/MachineConfig.py

+61-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

@@ -59,6 +61,7 @@ def setUp(self):
5961
self.lpar_prof = conf.args.lpar_prof
6062
self.util = OpTestUtil(conf)
6163
self.lpar_flag = False
64+
self.cv_BMC = self.cv_SYSTEM.bmc
6265
try:
6366
self.lpar_list = conf.args.lpar_list
6467
except AttributeError:
@@ -141,6 +144,7 @@ def callConfig(self, key, lpar=""):
141144
if key == "cec":
142145
lmb_size = None
143146
num_hugepages = None
147+
ioenlargecapacity = None
144148
setup = 0
145149
if not self.cv_HMC.lpar_vios:
146150
self.skipTest("Please pass lpar_vios in config file.")
@@ -159,10 +163,16 @@ def callConfig(self, key, lpar=""):
159163
num_hugepages = re.findall(
160164
'hugepages=[0-9]+',
161165
str(self.machine_config))[0].split('=')[1]
166+
if "iocapacity" in config_value:
167+
setup=1
168+
if self.bmc_type in ["EBMC_PHYP", "FSP_PHYP"]:
169+
ioenlargecapacity = re.findall(
170+
'iocapacity=[0-9]+', str(self.machine_config))[0].split('=')[1]
162171

163172
status = CecConfig(self.cv_HMC, self.system_name, self.lpar_name,
164173
self.lpar_prof, lmb=lmb_size,
165-
hugepages=num_hugepages).CecSetup()
174+
hugepages=num_hugepages, iocapacity=ioenlargecapacity,
175+
bmc_type=self.bmc_type, bmc=self.cv_SYSTEM.bmc).CecSetup()
166176
if status:
167177
self.fail(status)
168178
if not setup:
@@ -469,7 +479,8 @@ class CecConfig():
469479
'''
470480

471481
def __init__(self, cv_HMC=None, system_name=None,
472-
lpar_name=None, lpar_prof=None, lmb=None, hugepages=None):
482+
lpar_name=None, lpar_prof=None, lmb=None, hugepages=None,
483+
iocapacity=None, bmc_type=None, bmc=None):
473484

474485
self.cv_HMC = cv_HMC
475486
self.system_name = system_name
@@ -478,7 +489,13 @@ def __init__(self, cv_HMC=None, system_name=None,
478489
self.lmb_size = lmb
479490
self.num_hugepages = hugepages
480491
self.setup = 0
481-
self.cec_dict = {'lmb_cec': None, 'hugepages': None}
492+
self.iocapacity = iocapacity
493+
self.cec_dict = {'lmb_cec': None, 'hugepages': None, 'iocapacity': None}
494+
self.config = OpTestConfiguration.conf
495+
self.bmc_type = bmc_type
496+
self.bmc = bmc
497+
if self.bmc_type == "FSP_PHYP" and iocapacity is not None:
498+
self.bmc.cv_ASM.configure_enlarged_io(iocapacity)
482499

483500
def CecSetup(self):
484501

@@ -489,6 +506,11 @@ def CecSetup(self):
489506
self.lmb_setup()
490507
if self.cec_dict['hugepages'] is not None:
491508
self.hugepage_16gb_setup()
509+
if self.cec_dict['iocapacity'] is not None:
510+
if bmc_type == "EBMC_PHYP":
511+
self.io_enlarge_cpacity()
512+
elif bmc_type == "FSP_PHYP":
513+
self.cv_ASM.configure_enlarged_io(self.iocapacity)
492514
if self.setup:
493515
self.cv_HMC.poweron_system()
494516
self.ValidateCEC_Setup()
@@ -514,6 +536,11 @@ def ValidateCEC_Setup(self):
514536
self.setting_16gb_hugepage_profile()
515537
else:
516538
self.cec_dict['hugepages'] = self.num_hugepages
539+
if self.iocapacity:
540+
if self.bmc_type == "FSP_PHYP":
541+
self.bmc.cv_ASM.configure_enlarged_io(self.iocapacity)
542+
else:
543+
self.io_enlarge_capacity()
517544

518545
def lmb_setup(self):
519546
# Configure the lmb as per user request
@@ -531,6 +558,37 @@ def setting_16gb_hugepage_profile(self):
531558
int(self.current_hgpg[0]))
532559
self.cv_HMC.set_lpar_cfg(attrs)
533560

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

535593
class OsConfig():
536594
'''

0 commit comments

Comments
 (0)