New BMC redfish library integration
Changes:
- Use redfish_plus.py when importing Redfish instances.
- Update bmc_redfish.py.
- Update bmc_redfish_utility.py.
- Update object name 'redfish' to 'Redfish'.
- Update test setup and teardown in suites.
- Update response error checking using valid_status_codes.
- Fix test cases required for migration.
Change-Id: Ida154aede649d9a2bbef66d16ccf725f5ea37ed0
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/lib/bmc_redfish.py b/lib/bmc_redfish.py
index eeab824..fad445e 100644
--- a/lib/bmc_redfish.py
+++ b/lib/bmc_redfish.py
@@ -1,152 +1,40 @@
#!/usr/bin/env python
r"""
-Using python based redfish library.
-Refer: https://github.com/DMTF/python-redfish-library
+See class prolog below for details.
"""
-import redfish
+from redfish_plus import redfish_plus
from robot.libraries.BuiltIn import BuiltIn
-class HTTPSBadRequestError(Exception):
+class bmc_redfish(redfish_plus):
r"""
- BMC redfish generic raised method for error(s).
+ bmc_redfish is a child class of redfish_plus that is designed to provide
+ benefits specifically for using redfish to communicate with an OpenBMC.
+
+ See the prologs of the methods below for details.
"""
- pass
-
-
-class bmc_redfish(object):
-
- ROBOT_LIBRARY_SCOPE = "TEST SUITE"
- ROBOT_EXIT_ON_FAILURE = True
-
- def __init__(self, hostname, username, password, *args, **kwargs):
- r"""
- Establish session connection to host.
-
- Description of argument(s):
- hostname The host name or IP address of the server.
- username The username to be used to connect to the server.
- password The password to be used to connect to the server.
- args/kwargs Additional parms which are passed directly
- to the redfish_client function.
- """
- self._base_url_ = "https://" + hostname
- self._username_ = username
- self._password_ = password
- self._default_prefix_ = "/redfish/v1"
-
- def __enter__(self):
- return self
-
- def __del__(self):
- del self
def login(self, *args, **kwargs):
r"""
- Call the corresponding RestClientBase method and return the result.
+ Assign BMC default values for username, password and auth arguments
+ and call parent class login method.
Description of argument(s):
- args/kwargs These are passed directly to the corresponding
- RestClientBase method.
+ args See parent class prolog for details.
+ kwargs See parent class prolog for details.
"""
- for arg in args:
- hostname = self._base_url_.strip("https://")
- # Class object constructor reinitialized.
- self.__init__(hostname=hostname,
- username=arg['username'],
- password=arg['password'])
+ args = list(args)
+ # Assign default values for username, password, auth where necessary.
+ username = args.pop(0) if args else \
+ kwargs.pop('username',
+ BuiltIn().get_variable_value("${OPENBMC_USERNAME}"))
+ password = args.pop(0) if args else \
+ kwargs.pop('password',
+ BuiltIn().get_variable_value("${OPENBMC_PASSWORD}"))
+ auth = args.pop(0) if args else kwargs.pop('auth', 'session')
- self._robj_ = redfish.redfish_client(base_url=self._base_url_,
- username=self._username_,
- password=self._password_,
- default_prefix=self._default_prefix_)
- self._robj_.login(auth=redfish.AuthMethod.SESSION)
- self._session_key_ = self._robj_.get_session_key()
- self._session_location_ = self._robj_.get_session_location()
-
- def set_session_key(self, session_key):
- r"""
- Update the session key instance.
-
- session_key Redfish valid session key.
- """
- self._robj_.set_session_key(session_key)
-
- def set_session_location(self, session_location):
- r"""
- Update the session location instance.
-
- session_location Redfish valid session location.
- Example:
- /redfish/v1/SessionService/Sessions/j04tD83QQn
- """
- self._robj_.set_session_location(session_location)
-
- def get(self, resource_path, *args, **kwargs):
- r"""
- Perform a GET request and return response.
-
- Description of argument(s):
- resource_path URI resource absolute path (e.g. "/redfish/v1/Systems/1").
- args/kwargs These are passed directly to the corresponding
- RestClientBase method.
- """
- self._rest_response_ = self._robj_.get(resource_path, *args, **kwargs)
- return self._rest_response_
-
- def post(self, resource_path, *args, **kwargs):
- r"""
- Perform a POST request.
-
- Description of argument(s):
- resource_path URI resource relative path
- (e.g. "Systems/1/Actions/ComputerSystem.Reset").
- args/kwargs These are passed directly to the corresponding
- RestClientBase method.
- """
- self._rest_response_ = self._robj_.post(resource_path, *args, **kwargs)
- return self._rest_response_
-
- def patch(self, resource_path, *args, **kwargs):
- r"""
- Perform a POST request.
-
- Description of argument(s):
- resource_path URI resource relative path
- args/kwargs These are passed directly to the corresponding
- RestClientBase method.
- """
- self._rest_response_ = self._robj_.patch(resource_path, *args, **kwargs)
- return self._rest_response_
-
- def put(self, resource_path, actions, attr_data):
- r"""
- Perform a PUT request.
-
- Description of argument(s):
- resource_path URI resource relative path.
- args/kwargs These are passed directly to the corresponding
- RestClientBase method.
- """
- self._rest_response_ = self._robj_.put(resource_path, *args, **kwargs)
- return self._rest_response_
-
- def delete(self, resource_path):
- r"""
- Perform a DELETE request.
-
- Description of argument(s):
- resource_path URI resource absolute path
- (e.g. "/redfish/v1/SessionService/Sessions/8d1a9wiiNL").
- """
- self._rest_response_ = self._robj_.delete(resource_path)
- return self._rest_response_
-
- def logout(self):
- r"""
- Logout redfish connection session.
- """
- self._robj_.logout()
+ super(redfish_plus, self).login(username, password, auth,
+ *args, **kwargs)
diff --git a/lib/bmc_redfish_resource.robot b/lib/bmc_redfish_resource.robot
index ab0db3d..ef38830 100644
--- a/lib/bmc_redfish_resource.robot
+++ b/lib/bmc_redfish_resource.robot
@@ -3,9 +3,8 @@
Resource resource.robot
Resource rest_response_code.robot
-Library bmc_redfish.py
-... ${OPENBMC_HOST} ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
-... WITH NAME redfish
+Library bmc_redfish.py https://${OPENBMC_HOST} ${OPENBMC_USERNAME}
+... ${OPENBMC_PASSWORD} WITH NAME Redfish
Library bmc_redfish_utils.py WITH NAME redfish_utils
Library disable_warning_urllib.py
diff --git a/lib/bmc_redfish_utils.py b/lib/bmc_redfish_utils.py
index 492a1a3..1bf53a7 100644
--- a/lib/bmc_redfish_utils.py
+++ b/lib/bmc_redfish_utils.py
@@ -27,8 +27,8 @@
}
"""
session_dict = {
- "key": self._redfish_._session_key_,
- "location": self._redfish_._session_location_
+ "key": self._redfish_.get_session_key(),
+ "location": self._redfish_.get_session_location()
}
return session_dict
@@ -111,8 +111,8 @@
global resource_list
resource_list = []
-
- self._rest_response_ = self._redfish_.get(resource_path)
+ self._rest_response_ = \
+ self._redfish_.get(resource_path, valid_status_codes=[200, 404, 500])
# Return empty list.
if self._rest_response_.status != 200:
@@ -124,7 +124,8 @@
return uri_path
for resource in resource_list:
- self._rest_response_ = self._redfish_.get(resource)
+ self._rest_response_ = \
+ self._redfish_.get(resource, valid_status_codes=[200, 404, 500])
if self._rest_response_.status != 200:
continue
self.walk_nested_dict(self._rest_response_.dict)
@@ -154,7 +155,8 @@
# Example: '/redfish/v1/JsonSchemas/' and sub resources.
if 'JsonSchemas' in resource:
continue
- self._rest_response_ = self._redfish_.get(resource)
+ self._rest_response_ = \
+ self._redfish_.get(resource, valid_status_codes=[200, 404, 500])
if self._rest_response_.status != 200:
continue
resource_dict[resource] = self._rest_response_.dict
diff --git a/lib/openbmc_ffdc_methods.robot b/lib/openbmc_ffdc_methods.robot
index a436c63..cdd6778 100755
--- a/lib/openbmc_ffdc_methods.robot
+++ b/lib/openbmc_ffdc_methods.robot
@@ -478,7 +478,7 @@
# Login is needed to fetch Redfish information.
# If login fails, return from keyword.
- ${status}= Run Keyword And Return Status redfish.Login
+ ${status}= Run Keyword And Return Status Redfish.Login
Return From Keyword If ${status} == ${False}
# Get the Redfish resources and properties.
diff --git a/redfish/account_service/test_user_account.robot b/redfish/account_service/test_user_account.robot
index 13a1d1a..a81feb6 100644
--- a/redfish/account_service/test_user_account.robot
+++ b/redfish/account_service/test_user_account.robot
@@ -15,7 +15,7 @@
[Documentation] Verify Redfish account service is available.
[Tags] Verify_AccountService_Available
- ${resp} = redfish_utils.Get Attribute /redfish/v1/AccountService ServiceEnabled
+ ${resp} = Redfish_utils.Get Attribute /redfish/v1/AccountService ServiceEnabled
Should Be Equal As Strings ${resp} ${True}
@@ -24,11 +24,11 @@
Test Setup Execution
[Documentation] Do test case setup tasks.
- redfish.Login
+ Redfish.Login
Test Teardown Execution
[Documentation] Do the post test teardown.
FFDC On Test Case Fail
- redfish.Logout
+ Redfish.Logout
diff --git a/redfish/dmtf_tools/Redfish-JsonSchema-ResponseValidator.robot b/redfish/dmtf_tools/Redfish-JsonSchema-ResponseValidator.robot
index d875c22..60c9e81 100644
--- a/redfish/dmtf_tools/Redfish-JsonSchema-ResponseValidator.robot
+++ b/redfish/dmtf_tools/Redfish-JsonSchema-ResponseValidator.robot
@@ -22,9 +22,9 @@
Download DMTF Tool ${rsv_dir_path} ${rsv_github_url}
- redfish.Login
+ Redfish.Login
${url_list}= redfish_utils.List Request /redfish/v1
- redfish.Logout
+ Redfish.Logout
Shell Cmd mkdir -p logs/
diff --git a/redfish/managers/test_bmc_network_conf.robot b/redfish/managers/test_bmc_network_conf.robot
index 5e4b70c..6891e6e 100644
--- a/redfish/managers/test_bmc_network_conf.robot
+++ b/redfish/managers/test_bmc_network_conf.robot
@@ -37,7 +37,7 @@
[Documentation] Get MAC address and verify it's existence on the BMC.
[Tags] Get_MAC_Address_And_Verify
- ${resp}= redfish.Get ${REDFISH_NW_ETH0_URI}
+ ${resp}= Redfish.Get ${REDFISH_NW_ETH0_URI}
${macaddr}= Get From Dictionary ${resp.dict} MACAddress
Validate MAC On BMC ${macaddr}
@@ -54,7 +54,7 @@
Test Setup Execution
[Documentation] Test setup execution.
- redfish.Login
+ Redfish.Login
@{network_configurations}= Get Network Configuration
Set Test Variable @{network_configurations}
@@ -96,7 +96,7 @@
# "VLANId": 0
# }
- ${resp}= redfish.Get ${REDFISH_NW_ETH0_URI}
+ ${resp}= Redfish.Get ${REDFISH_NW_ETH0_URI}
@{network_configurations}= Get From Dictionary ${resp.dict} IPv4Addresses
[Return] @{network_configurations}
@@ -162,4 +162,4 @@
[Documentation] Test teardown execution.
FFDC On Test Case Fail
- redfish.Logout
+ Redfish.Logout
diff --git a/redfish/managers/test_managers_bmc.robot b/redfish/managers/test_managers_bmc.robot
index 3c65884..9f2f29b 100644
--- a/redfish/managers/test_managers_bmc.robot
+++ b/redfish/managers/test_managers_bmc.robot
@@ -4,8 +4,8 @@
Resource ../../lib/common_utils.robot
Resource ../../lib/openbmc_ffdc.robot
-Test Teardown FFDC On Test Case Fail
-Suite Teardown redfish.Logout
+Test Setup Test Setup Execution
+Test Teardown Redfish.Logout
*** Test Cases ***
@@ -13,21 +13,20 @@
[Documentation] Get firmware version from BMC manager.
[Tags] Verify_Redfish_BMC_Firmware_Version
- redfish.Login
- ${resp}= redfish.Get /redfish/v1/Managers/bmc
+ Redfish.Login
+ ${resp}= Redfish.Get /redfish/v1/Managers/bmc
Should Be Equal As Strings ${resp.status} ${HTTP_OK}
${bmc_version}= Get BMC Version
Should Be Equal As Strings
... ${resp.dict["FirmwareVersion"]} ${bmc_version.strip('"')}
- redfish.Logout
Verify Redfish BMC Manager Properties
[Documentation] Verify BMC managers resource properties.
[Tags] Verify_Redfish_BMC_Manager_Properties
- redfish.Login
- ${resp}= redfish.Get /redfish/v1/Managers/bmc
+ Redfish.Login
+ ${resp}= Redfish.Get /redfish/v1/Managers/bmc
Should Be Equal As Strings ${resp.status} ${HTTP_OK}
# Example:
# "Description": "Baseboard Management Controller"
@@ -44,7 +43,6 @@
Should Be Equal As Strings ${resp.dict["Name"]} OpenBmc Manager
Should Not Be Empty ${resp.dict["UUID"]}
Should Be Equal As Strings ${resp.dict["PowerState"]} On
- redfish.Logout
Test Redfish BMC Manager GracefulRestart
@@ -60,12 +58,24 @@
# "target": "/redfish/v1/Managers/bmc/Actions/Manager.Reset"
# }
- redfish.Login
+ Redfish.Login
${payload}= Create Dictionary ResetType=GracefulRestart
- ${resp}= redfish.Post Managers/bmc/Actions/Manager.Reset body=&{payload}
+ ${resp}= Redfish.Post Managers/bmc/Actions/Manager.Reset body=&{payload}
Should Be Equal As Strings ${resp.status} ${HTTP_OK}
# TODO: Add logic to ping and check BMC online state
+*** Keywords ***
+Test Setup Execution
+ [Documentation] Do test case setup tasks.
+
+ redfish.Login
+
+
+Test Teardown Execution
+ [Documentation] Do the post test teardown.
+
+ FFDC On Test Case Fail
+ redfish.Logout
diff --git a/redfish/service_root/test_service_root.robot b/redfish/service_root/test_service_root.robot
index 23a2ea6..8aef25e 100644
--- a/redfish/service_root/test_service_root.robot
+++ b/redfish/service_root/test_service_root.robot
@@ -1,9 +1,12 @@
*** Settings ***
+
Resource ../../lib/resource.robot
Resource ../../lib/bmc_redfish_resource.robot
Resource ../../lib/openbmc_ffdc.robot
+
Test Teardown FFDC On Test Case Fail
+Test Setup Rprintn
*** Test Cases ***
@@ -11,8 +14,8 @@
[Documentation] Login to BMCweb and then logout.
[Tags] Redfish_Login_And_Logout
- redfish.Login
- redfish.Logout
+ Redfish.Login
+ Redfish.Logout
GET Redfish Hypermedia Without Login
@@ -30,18 +33,17 @@
[Documentation] Login to BMCweb and get /redfish/v1/SessionService.
[Tags] GET_Redfish_SessionService_Resource_With_Login
- redfish.Login
- ${resp}= redfish.Get /redfish/v1/SessionService
- Should Be Equal As Strings ${resp.status} ${HTTP_OK}
- redfish.Logout
+ Redfish.Login
+ ${resp}= Redfish.Get /redfish/v1/SessionService
+ Redfish.Logout
GET Redfish SessionService Without Login
[Documentation] Get /redfish/v1/SessionService without login
[Tags] GET_Redfish_SessionService_Without_Login
- ${resp}= redfish.Get /redfish/v1/SessionService
- Should Be Equal As Strings ${resp.status} ${HTTP_UNAUTHORIZED}
+ ${resp}= Redfish.Get /redfish/v1/SessionService
+ ... valid_status_codes=[${HTTP_UNAUTHORIZED}]
Redfish Login Using Invalid Token
@@ -64,15 +66,17 @@
[Documentation] Delete a session using valid login.
[Tags] Delete_Redfish_Session_Using_Valid_Login
- redfish.Login
+ Redfish.Login
+ Redfish.Login
# Example o/p:
# [{'@odata.id': '/redfish/v1/SessionService/Sessions/bOol3WlCI8'},
# {'@odata.id': '/redfish/v1/SessionService/Sessions/Yu3xFqjZr1'}]
- ${resp_list}= redfish_utils.List Request /redfish/v1/SessionService/Sessions
- redfish.Delete ${resp_list[1]}
+ ${resp_list}= Redfish_Utils.List Request
+ ... /redfish/v1/SessionService/Sessions
+ Redfish.Delete ${resp_list[1]}
- ${resp}= redfish_utils.List Request /redfish/v1/SessionService/Sessions
+ ${resp}= Redfish_Utils.List Request /redfish/v1/SessionService/Sessions
List Should Not Contain Value ${resp} ${resp_list[1]}
@@ -80,11 +84,12 @@
GET And Verify Redfish Response
[Documentation] GET given resource and verfiy response.
- [Arguments] ${expected_response_code} ${resource_path}
+ [Arguments] ${valid_status_codes} ${resource_path}
- # Description of arguments:
- # expected_response_code Expected REST status codes.
- # resource_path Redfish resource URL path.
+ # Description of argument(s):
+ # valid_status_codes A comma-separated list of acceptable
+ # status codes (e.g. 200).
+ # resource_path Redfish resource URL path.
- ${resp}= redfish.Get ${resource_path}
- Should Be Equal As Strings ${resp.status} ${expected_response_code}
+ ${resp}= Redfish.Get ${resource_path}
+ ... valid_status_codes=[${valid_status_codes}]
diff --git a/redfish/service_root/test_service_root_security.robot b/redfish/service_root/test_service_root_security.robot
index f8d0e4f..ac2f482 100644
--- a/redfish/service_root/test_service_root_security.robot
+++ b/redfish/service_root/test_service_root_security.robot
@@ -4,6 +4,7 @@
Resource ../../lib/openbmc_ffdc.robot
Test Teardown FFDC On Test Case Fail
+Test Setup Rprintn
*** Variables ***
@@ -59,7 +60,7 @@
[Tags] Create_Multiple_Login_Sessions_And_Verify
[Teardown] Multiple Session Cleanup
- redfish.Login
+ Redfish.Login
# Example:
# {
# 'key': 'L0XEsZAXpNdF147jJaOD',
@@ -75,10 +76,9 @@
# Update the redfish session object with the first login key and location
# and verify if it is still working.
- redfish.Set Session Key ${saved_session_info["key"]}
- redfish.Set Session Location ${saved_session_info["location"]}
- ${resp}= redfish.Get ${saved_session_info["location"]}
- Should Be Equal As Strings ${resp.status} ${HTTP_OK}
+ Redfish.Set Session Key ${saved_session_info["key"]}
+ Redfish.Set Session Location ${saved_session_info["location"]}
+ Redfish.Get ${saved_session_info["location"]}
Attempt Login With Expired Session
@@ -86,17 +86,16 @@
... use the session.
[Tags] Attempt_Login_With_Expired_Session
- redfish.Login
+ Redfish.Login
${saved_session_info}= Get Redfish Session Info
- redfish.Logout
+ Redfish.Logout
# Attempt login with expired session.
# By default 60 minutes of inactivity closes the session.
- redfish.Set Session Key ${saved_session_info["key"]}
- redfish.Set Session Location ${saved_session_info["location"]}
+ Redfish.Set Session Key ${saved_session_info["key"]}
+ Redfish.Set Session Location ${saved_session_info["location"]}
- ${resp}= redfish.Get ${saved_session_info["location"]}
- Should Be Equal As Strings ${resp.status} ${HTTP_UNAUTHORIZED}
+ Redfish.Get ${saved_session_info["location"]} valid_status_codes=[${HTTP_UNAUTHORIZED}]
*** Keywords ***
@@ -111,13 +110,13 @@
# password The password to be used to connect to the server.
${data}= Create Dictionary username=${username} password=${password}
- Run Keyword And Expect Error ${expected_response} redfish.Login ${data}
+ Run Keyword And Expect Error ${expected_response} Redfish.Login ${data}
Create New Login Session
[Documentation] Multiple login session keys.
- redfish.Login
+ Redfish.Login
${session_info}= Get Redfish Session Info
# Append the session location to the list.
@@ -132,5 +131,5 @@
FFDC On Test Case Fail
:FOR ${item} IN @{session_list}
- \ redfish.Delete ${item}
+ \ Redfish.Delete ${item}
diff --git a/redfish/update_service/test_firmware_inventory.robot b/redfish/update_service/test_firmware_inventory.robot
index 0b0848f..9e26b88 100644
--- a/redfish/update_service/test_firmware_inventory.robot
+++ b/redfish/update_service/test_firmware_inventory.robot
@@ -3,7 +3,8 @@
Resource ../../lib/bmc_redfish_resource.robot
Resource ../../lib/openbmc_ffdc.robot
-Test Teardown FFDC On Test Case Fail
+Test Setup Test Setup Execution
+Test Teardown Test Teardown Execution
*** Test Cases ***
@@ -17,11 +18,8 @@
# "Name": "Update Service",
# "ServiceEnabled": true
- redfish.Login
- ${resp}= redfish.Get /redfish/v1/UpdateService
- Should Be Equal As Strings ${resp.status} ${HTTP_OK}
+ ${resp}= Redfish.Get /redfish/v1/UpdateService
Should Be Equal As Strings ${resp.dict["ServiceEnabled"]} ${True}
- redfish.Logout
Verify Redfish Software Inventory Collection
@@ -46,22 +44,17 @@
# "Name": "Software Inventory Collection"
# }
- redfish.Login
- ${resp}= redfish.Get /redfish/v1/UpdateService/FirmwareInventory
- Should Be Equal As Strings ${resp.status} ${HTTP_OK}
+ ${resp}= Redfish.Get /redfish/v1/UpdateService/FirmwareInventory
Should Be True ${resp.dict["Members@odata.count"]} >= ${1}
Length Should Be ${resp.dict["Members"]} ${resp.dict["Members@odata.count"]}
- redfish.Logout
Redfish Software Inventory Status Check
[Documentation] Get firmware inventory entries and do health check status.
[Tags] Redfish_Software_Inventory_Status_Check
- redfish.Login
- ${resp}= redfish.Get /redfish/v1/UpdateService/FirmwareInventory
- Should Be Equal As Strings ${resp.status} ${HTTP_OK}
+ ${resp}= Redfish.Get /redfish/v1/UpdateService/FirmwareInventory
# Entries "Members@odata.count": 3,
# {'@odata.id': '/redfish/v1/UpdateService/FirmwareInventory/a3522998'}
@@ -69,8 +62,7 @@
# {'@odata.id': '/redfish/v1/UpdateService/FirmwareInventory/ace821ef'}
:FOR ${entry} IN RANGE 0 ${resp.dict["Members@odata.count"]}
- \ ${resp_resource}= redfish.Get ${resp.dict["Members"][${entry}]["@odata.id"]}
- \ Should Be Equal As Strings ${resp_resource.status} ${HTTP_OK}
+ \ ${resp_resource}= Redfish.Get ${resp.dict["Members"][${entry}]["@odata.id"]}
# Example:
# "Status": {
# "Health": "OK",
@@ -80,4 +72,18 @@
\ Should Be Equal As Strings ${resp_resource.dict["Status"]["Health"]} OK
\ Should Be Equal As Strings ${resp_resource.dict["Status"]["HealthRollup"]} OK
\ Should Be Equal As Strings ${resp_resource.dict["Status"]["State"]} Enabled
- redfish.Logout
+
+
+*** Keywords ***
+
+Test Setup Execution
+ [Documentation] Do test case setup tasks.
+
+ Redfish.Login
+
+
+Test Teardown Execution
+ [Documentation] Do the post test teardown.
+
+ FFDC On Test Case Fail
+ Redfish.Logout