Add cleanup code in lib/rest_client.robot
Resolves openbmc/openbmc-test-automation#1213
Change-Id: Icd83193176601077dc2037822904e2713760335d
Signed-off-by: manasarm <manashsarma@in.ibm.com>
diff --git a/lib/rest_client.robot b/lib/rest_client.robot
index 3530bee..e4f1d44 100644
--- a/lib/rest_client.robot
+++ b/lib/rest_client.robot
@@ -62,7 +62,27 @@
*** Keywords ***
OpenBMC Get Request
+ [Documentation] Do REST GET request and return the result.
+ # Example result data:
+ # Response code:200, Content:{
+ # "data": [
+ # "/xyz/openbmc_project/state/host0",
+ # "/xyz/openbmc_project/state/chassis0",
+ # "/xyz/openbmc_project/state/bmc0"
+ # ],
+ # "message": "200 OK",
+ # "status": "ok"
+ # }
[Arguments] ${uri} ${timeout}=30 ${quiet}=${QUIET} &{kwargs}
+ # Description of argument(s):
+ # uri The URI to establish connection with
+ # (e.g. '/xyz/openbmc_project/software/').
+ # timeout Timeout in seconds to establish connection with URI.
+ # quiet If enabled, turns off logging to console.
+ # kwargs Any additional arguments to be passed directly to the
+ # Get Request call. For example, the caller might
+ # set kwargs as follows:
+ # ${kwargs}= Create Dictionary allow_redirect=${True}.
Initialize OpenBMC ${timeout} quiet=${quiet}
${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
@@ -74,7 +94,19 @@
[Return] ${ret}
OpenBMC Post Request
+ [Documentation] Do REST POST request and return the result.
+ # Example result data:
+ # <Response [200]>
[Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
+ # Description of argument(s):
+ # uri The URI to establish connection with
+ # (e.g. '/xyz/openbmc_project/software/').
+ # timeout Timeout in seconds to establish connection with URI.
+ # quiet If enabled, turns off logging to console.
+ # kwargs Any additional arguments to be passed directly to the
+ # Post Request call. For example, the caller might
+ # set kwargs as follows:
+ # ${kwargs}= Create Dictionary allow_redirect=${True}.
Initialize OpenBMC ${timeout} quiet=${quiet}
${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
@@ -88,7 +120,17 @@
[Return] ${ret}
OpenBMC Put Request
+ [Documentation] Do REST PUT request on the resource identified by the URI.
[Arguments] ${uri} ${timeout}=10 &{kwargs}
+ # Description of argument(s):
+ # uri The URI to establish connection with
+ # (e.g. '/xyz/openbmc_project/software/').
+ # timeout Timeout in seconds to establish connection with URI.
+ # kwargs Arguments passed to the REST call.
+ # kwargs Any additional arguments to be passed directly to the
+ # Put Request call. For example, the caller might
+ # set kwargs as follows:
+ # ${kwargs}= Create Dictionary allow_redirect=${True}.
Initialize OpenBMC ${timeout}
${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
@@ -101,7 +143,17 @@
[Return] ${ret}
OpenBMC Delete Request
+ [Documentation] Do REST request to delete the resource identified by the
+ ... URI.
[Arguments] ${uri} ${timeout}=10 &{kwargs}
+ # Description of argument(s):
+ # uri The URI to establish connection with
+ # (e.g. '/xyz/openbmc_project/software/').
+ # timeout Timeout in seconds to establish connection with URI.
+ # kwargs Any additional arguments to be passed directly to the
+ # Delete Request call. For example, the caller might
+ # set kwargs as follows:
+ # ${kwargs}= Create Dictionary allow_redirect=${True}.
Initialize OpenBMC ${timeout}
${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
@@ -112,6 +164,7 @@
[Return] ${ret}
Initialize OpenBMC
+ [Documentation] Do a REST login connection within specified time.
[Arguments] ${timeout}=20 ${quiet}=${1}
... ${OPENBMC_USERNAME}=${OPENBMC_USERNAME}
... ${OPENBMC_PASSWORD}=${OPENBMC_PASSWORD}
@@ -127,6 +180,7 @@
... ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
Post Login Request
+ [Documentation] Do REST login request.
[Arguments] ${timeout}=20 ${quiet}=${1}
... ${OPENBMC_USERNAME}=${OPENBMC_USERNAME}
... ${OPENBMC_PASSWORD}=${OPENBMC_PASSWORD}
@@ -146,7 +200,7 @@
Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Log Out OpenBMC
- [Documentation] Log out REST connection with active session "openbmc".
+ [Documentation] Log out of the openbmc REST session.
${headers}= Create Dictionary Content-Type=application/json
${data}= Create dictionary data=@{EMPTY}
@@ -160,23 +214,37 @@
... msg=${resp}
Log Request
+ [Documentation] Log the specific REST URI, method name on the console.
[Arguments] &{kwargs}
${msg}= Catenate SEPARATOR= URI: ${AUTH_URI} ${kwargs["base_uri"]}
... , method: ${kwargs["method"]} , args: ${kwargs["args"]}
Logging ${msg} console=True
Log Response
+ [Documentation] Log the response code on the console.
[Arguments] ${resp}
${msg}= Catenate SEPARATOR= Response code: ${resp.status_code}
... , Content: ${resp.content}
Logging ${msg} console=True
Logging
+ [Documentation] Log the specified message on the console.
[Arguments] ${msg} ${console}=default False
Log ${msg} console=True
Read Attribute
+ [Documentation] Retrieve attribute value from URI and return result.
+ # Example result data for the attribute 'FieldModeEnabled' in
+ # "/xyz/openbmc_project/software/attr/" :
+ # 0
[Arguments] ${uri} ${attr} ${timeout}=10 ${quiet}=${QUIET}
+ # Description of argument(s):
+ # uri URI of the object that the attribute lives on
+ # (e.g. '/xyz/openbmc_project/software/').
+ # attr Name of the attribute (e.g. 'FieldModeEnabled').
+ # timeout Timeout for the REST call.
+ # quiet If enabled, turns off logging to console.
+
${resp}= OpenBMC Get Request ${uri}/attr/${attr} timeout=${timeout}
... quiet=${quiet}
Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
@@ -218,16 +286,34 @@
${value}= Read Attribute ${uri} ${attr}
Should Be Equal ${value} ${expected_value}
-
Read Properties
+ [Documentation] Read data part of the URI object and return result.
+ # Example result data:
+ # [u'/xyz/openbmc_project/software/cf7bf9d5',
+ # u'/xyz/openbmc_project/software/5ecb8b2c',
+ # u'/xyz/openbmc_project/software/active',
+ # u'/xyz/openbmc_project/software/functional']
[Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET}
+ # Description of argument(s):
+ # uri URI of the object
+ # (e.g. '/xyz/openbmc_project/software/').
+ # timeout Timeout for the REST call.
+ # quiet If enabled, turns off logging to console.
+
${resp}= OpenBMC Get Request ${uri} timeout=${timeout} quiet=${quiet}
Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
${content}= To Json ${resp.content}
[Return] ${content["data"]}
Call Method
+ [Documentation] Invoke the specific REST service method.
[Arguments] ${uri} ${method} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
+ # Description of arguments:
+ # uri The URI to establish connection with
+ # (e.g. '/xyz/openbmc_project/software/').
+ # timeout Timeout in seconds to establish connection with URI.
+ # quiet If enabled, turns off logging to console.
+ # kwargs Arguments passed to the REST call.
${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
${resp}= OpenBmc Post Request ${base_uri}/action/${method}
@@ -235,13 +321,14 @@
[Return] ${resp}
Upload Image To BMC
+ [Documentation] Upload image to BMC device using REST POST operation.
[Arguments] ${uri} ${timeout}=10 ${quiet}=${1} &{kwargs}
# Description of argument(s):
# uri URI for uploading image via REST e.g. "/upload/image".
# timeout Time allocated for the REST command to return status
# (specified in Robot Framework Time Format e.g. "3 mins").
- # quiet If enabled turns off logging to console.
+ # quiet If enabled, turns off logging to console.
# kwargs A dictionary keys/values to be passed directly to
# Post Request.