Skip to content

Commit 36b28cf

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 4ca0d5b commit 36b28cf

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:
@@ -140,6 +143,7 @@ def callConfig(self, key, lpar=""):
140143
if key == "cec":
141144
lmb_size = None
142145
num_hugepages = None
146+
ioenlargecapacity = None
143147
setup = 0
144148
if not self.cv_HMC.lpar_vios:
145149
self.skipTest("Please pass lpar_vios in config file.")
@@ -158,10 +162,16 @@ def callConfig(self, key, lpar=""):
158162
num_hugepages = re.findall(
159163
'hugepages=[0-9]+',
160164
str(self.machine_config))[0].split('=')[1]
165+
if "iocapacity" in config_value:
166+
setup=1
167+
if self.bmc_type in ["EBMC_PHYP", "FSP_PHYP"]:
168+
ioenlargecapacity = re.findall(
169+
'iocapacity=[0-9]+', str(self.machine_config))[0].split('=')[1]
161170

162171
status = CecConfig(self.cv_HMC, self.system_name, self.lpar_name,
163172
self.lpar_prof, lmb=lmb_size,
164-
hugepages=num_hugepages).CecSetup()
173+
hugepages=num_hugepages, iocapacity=ioenlargecapacity,
174+
bmc_type=self.bmc_type, bmc=self.cv_SYSTEM.bmc).CecSetup()
165175
if status:
166176
self.fail(status)
167177
if not setup:
@@ -474,7 +484,8 @@ class CecConfig():
474484
'''
475485

476486
def __init__(self, cv_HMC=None, system_name=None,
477-
lpar_name=None, lpar_prof=None, lmb=None, hugepages=None):
487+
lpar_name=None, lpar_prof=None, lmb=None, hugepages=None,
488+
iocapacity=None, bmc_type=None, bmc=None):
478489

479490
self.cv_HMC = cv_HMC
480491
self.system_name = system_name
@@ -483,7 +494,13 @@ def __init__(self, cv_HMC=None, system_name=None,
483494
self.lmb_size = lmb
484495
self.num_hugepages = hugepages
485496
self.setup = 0
486-
self.cec_dict = {'lmb_cec': None, 'hugepages': None}
497+
self.iocapacity = iocapacity
498+
self.cec_dict = {'lmb_cec': None, 'hugepages': None, 'iocapacity': None}
499+
self.config = OpTestConfiguration.conf
500+
self.bmc_type = bmc_type
501+
self.bmc = bmc
502+
if self.bmc_type == "FSP_PHYP" and iocapacity is not None:
503+
self.bmc.cv_ASM.configure_enlarged_io(iocapacity)
487504

488505
def CecSetup(self):
489506

@@ -494,6 +511,11 @@ def CecSetup(self):
494511
self.lmb_setup()
495512
if self.cec_dict['hugepages'] is not None:
496513
self.hugepage_16gb_setup()
514+
if self.cec_dict['iocapacity'] is not None:
515+
if bmc_type == "EBMC_PHYP":
516+
self.io_enlarge_cpacity()
517+
elif bmc_type == "FSP_PHYP":
518+
self.cv_ASM.configure_enlarged_io(self.iocapacity)
497519
if self.setup:
498520
self.cv_HMC.poweron_system()
499521
self.ValidateCEC_Setup()
@@ -519,6 +541,11 @@ def ValidateCEC_Setup(self):
519541
self.setting_16gb_hugepage_profile()
520542
else:
521543
self.cec_dict['hugepages'] = self.num_hugepages
544+
if self.iocapacity:
545+
if self.bmc_type == "FSP_PHYP":
546+
self.bmc.cv_ASM.configure_enlarged_io(self.iocapacity)
547+
else:
548+
self.io_enlarge_capacity()
522549

523550
def lmb_setup(self):
524551
# Configure the lmb as per user request
@@ -536,6 +563,37 @@ def setting_16gb_hugepage_profile(self):
536563
int(self.current_hgpg[0]))
537564
self.cv_HMC.set_lpar_cfg(attrs)
538565

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

540598
class OsConfig():
541599
'''

0 commit comments

Comments
 (0)