Skip to content

Commit f8d7f82

Browse files
Merge pull request #819 from maramsmurthy/maramsmurthy_ioenlarge_redfish
Added Redfish API for following operation
2 parents 94f08c3 + 3d8a34b commit f8d7f82

File tree

2 files changed

+119
-3
lines changed

2 files changed

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

+27-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import OpTestConfiguration
3535
import OpTestLogger
36+
from common import OpTestASM
3637
from common import OpTestHMC
3738
from common import OpTestInstallUtil
3839
from common.OpTestUtil import OpTestUtil
@@ -59,6 +60,7 @@ def setUp(self):
5960
self.lpar_prof = conf.args.lpar_prof
6061
self.util = OpTestUtil(conf)
6162
self.lpar_flag = False
63+
self.cv_BMC = self.cv_SYSTEM.bmc
6264
try:
6365
self.lpar_list = conf.args.lpar_list
6466
except AttributeError:
@@ -141,6 +143,7 @@ def callConfig(self, key, lpar=""):
141143
if key == "cec":
142144
lmb_size = None
143145
num_hugepages = None
146+
ioenlargecapacity = None
144147
setup = 0
145148
if not self.cv_HMC.lpar_vios:
146149
self.skipTest("Please pass lpar_vios in config file.")
@@ -159,10 +162,16 @@ def callConfig(self, key, lpar=""):
159162
num_hugepages = re.findall(
160163
'hugepages=[0-9]+',
161164
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]
162170

163171
status = CecConfig(self.cv_HMC, self.system_name, self.lpar_name,
164172
self.lpar_prof, lmb=lmb_size,
165-
hugepages=num_hugepages).CecSetup()
173+
hugepages=num_hugepages, iocapacity=ioenlargecapacity,
174+
bmc_type=self.bmc_type, bmc=self.cv_SYSTEM.bmc).CecSetup()
166175
if status:
167176
self.fail(status)
168177
if not setup:
@@ -471,7 +480,8 @@ class CecConfig():
471480
'''
472481

473482
def __init__(self, cv_HMC=None, system_name=None,
474-
lpar_name=None, lpar_prof=None, lmb=None, hugepages=None):
483+
lpar_name=None, lpar_prof=None, lmb=None, hugepages=None,
484+
iocapacity=None, bmc_type=None, bmc=None):
475485

476486
self.cv_HMC = cv_HMC
477487
self.system_name = system_name
@@ -480,7 +490,11 @@ def __init__(self, cv_HMC=None, system_name=None,
480490
self.lmb_size = lmb
481491
self.num_hugepages = hugepages
482492
self.setup = 0
483-
self.cec_dict = {'lmb_cec': None, 'hugepages': None}
493+
self.iocapacity = iocapacity
494+
self.cec_dict = {'lmb_cec': None, 'hugepages': None, 'iocapacity': None}
495+
self.config = OpTestConfiguration.conf
496+
self.bmc_type = bmc_type
497+
self.bmc = bmc
484498

485499
def CecSetup(self):
486500

@@ -491,6 +505,11 @@ def CecSetup(self):
491505
self.lmb_setup()
492506
if self.cec_dict['hugepages'] is not None:
493507
self.hugepage_16gb_setup()
508+
if self.cec_dict['iocapacity'] is not None:
509+
if bmc_type == "EBMC_PHYP":
510+
self.bmc.rest_api.configure_enlarged_io(self.iocapacity)
511+
elif bmc_type == "FSP_PHYP":
512+
self.cv_ASM.configure_enlarged_io(self.iocapacity)
494513
if self.setup:
495514
self.cv_HMC.poweron_system()
496515
self.ValidateCEC_Setup()
@@ -516,6 +535,11 @@ def ValidateCEC_Setup(self):
516535
self.setting_16gb_hugepage_profile()
517536
else:
518537
self.cec_dict['hugepages'] = self.num_hugepages
538+
if self.iocapacity:
539+
if self.bmc_type == "FSP_PHYP":
540+
self.bmc.cv_ASM.configure_enlarged_io(self.iocapacity)
541+
else:
542+
self.bmc.rest_api.configure_enlarged_io(self.iocapacity)
519543

520544
def lmb_setup(self):
521545
# Configure the lmb as per user request

0 commit comments

Comments
 (0)