Skip to content

Commit

Permalink
Merge pull request #819 from maramsmurthy/maramsmurthy_ioenlarge_redfish
Browse files Browse the repository at this point in the history
Added Redfish API for following operation
  • Loading branch information
PraveenPenguin authored Nov 20, 2024
2 parents 94f08c3 + 3d8a34b commit f8d7f82
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 3 deletions.
92 changes: 92 additions & 0 deletions common/OpTestEBMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# permissions and limitations under the License.


import os
import time
import requests
import json
Expand Down Expand Up @@ -127,6 +128,97 @@ def wait_for_bmc_runtime(self, timeout=10):
key=['Status', 'State'],
minutes=timeout)
return status

def set_attribute_redfish(self, uri, attribute_name, attribute_value):
"""
Changing any attribute value using Redfish API
:param uri: redfish uri at which the attribute can be updated
:param attribute_name: Should be same as attribute name in redfish
:param attribute_value: Value want be be updated for attribute
"""
auth_token = self.generate_ssl_auth_token(ip_add=self.conf.args.bmc_ip)
content_type = "-H 'Content-Type: application/json'"
rest_server = "https://{}{}".format(self.conf.args.bmc_ip, uri)
attribute_param = '\'{"Attributes":{'+'{}:{}'.format(attribute_name, attribute_value)+'}}\''
curl_command = "curl -k -H"+" 'X-Auth-Token: "+auth_token+"' "+content_type+f" -X PATCH {rest_server} "+f"-d {attribute_param}"
log.info("Command to set attribut: "+curl_command)
try:
output = os.system(curl_command)
return output
except CommandFailed as cf:
return cf.output

def generate_ssl_auth_token(self, ip_add = None):
"""
Generates ssl key then returns the ssl key
"""
payload = {
"username": self.conf.args.bmc_username,
"password": self.conf.args.bmc_password
}
uri = f"https://{ip_add}/redfish/v1/SessionService/Sessions"
creds = '{"UserName":\"'+ self.conf.args.bmc_username + '","Password":\"' + self.conf.args.bmc_password + '"}'
file_name = "/tmp/headers-"+time.strftime("%Y%m%d%H%M%S")+".txt"
sess_cmd = 'curl -k -H "Content-Type: application/json" -X POST -D '+file_name+" "+uri+' -d '+"\'"+creds+"\'"
os.system(sess_cmd)
auth_file = open(file_name)
token = auth_file.read()
token = [line for line in token.split("\n") if "X-Auth-Token" in line][0].split(":")[1].strip()
if token:
return token
else:
log.info("Token not found in response")
return None

def get_bios_attribute_value(self, bios_attribute=None, minutes=BMC_CONST.HTTP_RETRY):
"""
Get BIOS current attribute value using redfish api
"""
uri = "/redfish/v1/Systems/system/Bios"
r = self.conf.util_bmc_server.get(uri=uri, minutes=minutes)
return r.json().get("Attributes").get(bios_attribute)

def set_bios_attribute(self, bios_attribute=None, bios_attribute_val=None):
'''
Set BMC BIOS attribute to provided value
'''
uri = '/redfish/v1/Systems/system/Bios/Settings'
return self.set_attribute_redfish(uri=uri,
attribute_name='"'+bios_attribute+'"',
attribute_value=bios_attribute_val)

def configure_enlarged_io(self, iocapacity):
"""
Calling set IO Enlarge capacity if provided value is not same as current value
"""
cur_iocapacity = self.get_current_ioadapter_enlarged_capacity()
log.info("Setting up ioenlarge capacity")
log.info("Current ioenlarge capacity value:"+str(cur_iocapacity))
if cur_iocapacity != iocapacity:
self.set_ioenlarge_capacity(iocapacity)
else:
log.info("Provided IO Enlarge capacity value is same as current value, Exiting...")

def get_current_ioadapter_enlarged_capacity(self):
"""
Get ioadapter enlarged capcity value
"""
log.debug("=====Get current IOAdapter Enlarge Capacity=====")
return self.get_bios_attribute_value(
bios_attribute="hb_ioadapter_enlarged_capacity_current"
)

def set_ioenlarge_capacity(self, iocapacity):
"""
Set ioadapter enlarged capcity value
"""
log.debug("=====Set IOAdapter Enlarge Capacity=====")
self.set_bios_attribute(
bios_attribute="hb_ioadapter_enlarged_capacity",
bios_attribute_val=iocapacity
)



class OpTestEBMC():
Expand Down
30 changes: 27 additions & 3 deletions testcases/MachineConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import OpTestConfiguration
import OpTestLogger
from common import OpTestASM
from common import OpTestHMC
from common import OpTestInstallUtil
from common.OpTestUtil import OpTestUtil
Expand All @@ -59,6 +60,7 @@ def setUp(self):
self.lpar_prof = conf.args.lpar_prof
self.util = OpTestUtil(conf)
self.lpar_flag = False
self.cv_BMC = self.cv_SYSTEM.bmc
try:
self.lpar_list = conf.args.lpar_list
except AttributeError:
Expand Down Expand Up @@ -141,6 +143,7 @@ def callConfig(self, key, lpar=""):
if key == "cec":
lmb_size = None
num_hugepages = None
ioenlargecapacity = None
setup = 0
if not self.cv_HMC.lpar_vios:
self.skipTest("Please pass lpar_vios in config file.")
Expand All @@ -159,10 +162,16 @@ def callConfig(self, key, lpar=""):
num_hugepages = re.findall(
'hugepages=[0-9]+',
str(self.machine_config))[0].split('=')[1]
if "iocapacity" in config_value:
setup=1
if self.bmc_type in ["EBMC_PHYP", "FSP_PHYP"]:
ioenlargecapacity = re.findall(
'iocapacity=[0-9]+', str(self.machine_config))[0].split('=')[1]

status = CecConfig(self.cv_HMC, self.system_name, self.lpar_name,
self.lpar_prof, lmb=lmb_size,
hugepages=num_hugepages).CecSetup()
hugepages=num_hugepages, iocapacity=ioenlargecapacity,
bmc_type=self.bmc_type, bmc=self.cv_SYSTEM.bmc).CecSetup()
if status:
self.fail(status)
if not setup:
Expand Down Expand Up @@ -471,7 +480,8 @@ class CecConfig():
'''

def __init__(self, cv_HMC=None, system_name=None,
lpar_name=None, lpar_prof=None, lmb=None, hugepages=None):
lpar_name=None, lpar_prof=None, lmb=None, hugepages=None,
iocapacity=None, bmc_type=None, bmc=None):

self.cv_HMC = cv_HMC
self.system_name = system_name
Expand All @@ -480,7 +490,11 @@ def __init__(self, cv_HMC=None, system_name=None,
self.lmb_size = lmb
self.num_hugepages = hugepages
self.setup = 0
self.cec_dict = {'lmb_cec': None, 'hugepages': None}
self.iocapacity = iocapacity
self.cec_dict = {'lmb_cec': None, 'hugepages': None, 'iocapacity': None}
self.config = OpTestConfiguration.conf
self.bmc_type = bmc_type
self.bmc = bmc

def CecSetup(self):

Expand All @@ -491,6 +505,11 @@ def CecSetup(self):
self.lmb_setup()
if self.cec_dict['hugepages'] is not None:
self.hugepage_16gb_setup()
if self.cec_dict['iocapacity'] is not None:
if bmc_type == "EBMC_PHYP":
self.bmc.rest_api.configure_enlarged_io(self.iocapacity)
elif bmc_type == "FSP_PHYP":
self.cv_ASM.configure_enlarged_io(self.iocapacity)
if self.setup:
self.cv_HMC.poweron_system()
self.ValidateCEC_Setup()
Expand All @@ -516,6 +535,11 @@ def ValidateCEC_Setup(self):
self.setting_16gb_hugepage_profile()
else:
self.cec_dict['hugepages'] = self.num_hugepages
if self.iocapacity:
if self.bmc_type == "FSP_PHYP":
self.bmc.cv_ASM.configure_enlarged_io(self.iocapacity)
else:
self.bmc.rest_api.configure_enlarged_io(self.iocapacity)

def lmb_setup(self):
# Configure the lmb as per user request
Expand Down

0 comments on commit f8d7f82

Please sign in to comment.