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)