George Keishing | eaa73b7 | 2018-07-30 09:30:16 -0500 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Library Collections |
| 3 | Library String |
| 4 | Library RequestsLibrary.RequestsKeywords |
| 5 | Library OperatingSystem |
| 6 | Resource resource.txt |
| 7 | Library disable_warning_urllib.py |
| 8 | Resource rest_response_code.robot |
| 9 | |
| 10 | *** Variables *** |
| 11 | |
| 12 | # Assign default value to QUIET for programs which may not define it. |
| 13 | ${QUIET} ${0} |
| 14 | |
| 15 | *** Keywords *** |
| 16 | |
| 17 | Redfish Login Request |
| 18 | [Documentation] Do REST login and return authorization token. |
| 19 | [Arguments] ${openbmc_username}=${OPENBMC_USERNAME} |
| 20 | ... ${openbmc_password}=${OPENBMC_PASSWORD} |
| 21 | ... ${alias_session}=openbmc |
| 22 | ... ${timeout}=20 |
| 23 | |
| 24 | # Description of argument(s): |
| 25 | # openbmc_username The username to be used to login to the BMC. |
| 26 | # This defaults to global ${OPENBMC_USERNAME}. |
| 27 | # openbmc_password The password to be used to login to the BMC. |
| 28 | # This defaults to global ${OPENBMC_PASSWORD}. |
| 29 | # alias_session Session object name. |
| 30 | # This defaults to "openbmc" |
| 31 | # timeout REST login attempt time out. |
| 32 | |
| 33 | Create Session openbmc ${AUTH_URI} timeout=${timeout} |
| 34 | ${headers}= Create Dictionary Content-Type=application/json |
| 35 | |
| 36 | ${data}= Create Dictionary |
| 37 | ... UserName=${openbmc_username} Password=${openbmc_password} |
| 38 | |
| 39 | ${resp}= Post Request openbmc |
| 40 | ... ${REDFISH_SESSION} data=${data} headers=${headers} |
| 41 | |
| 42 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 43 | Log ${resp.headers["X-Auth-Token"]} |
| 44 | |
| 45 | [Return] ${resp.headers["X-Auth-Token"]} |
| 46 | |
| 47 | |
| 48 | Redfish Get Request |
| 49 | [Documentation] Do REST GET request and return the result. |
| 50 | [Arguments] ${uri_suffix} ${xauth_token}=None |
| 51 | ... ${response_format}=json ${timeout}=30 |
| 52 | |
| 53 | # Description of argument(s): |
| 54 | # uri_suffix The URI to establish connection with |
| 55 | # (e.g. 'Systems'). |
| 56 | # xauth_token Authentication token. |
| 57 | # response_format The format desired for data returned by this keyword |
| 58 | # (json/HTTPS response). |
| 59 | # timeout Timeout in seconds to establish connection with URI. |
| 60 | |
| 61 | ${xauth_token} = Run Keyword If ${xauth_token} == ${None} |
| 62 | ... Redfish Login Request |
| 63 | |
| 64 | ${base_uri} = Catenate SEPARATOR= ${REDFISH_BASE_URI} ${uri_suffix} |
| 65 | |
| 66 | # Example: "X-Auth-Token: 3la1JUf1vY4yN2dNOwun" |
| 67 | ${headers} = Create Dictionary Content-Type=application/json |
| 68 | ... X-Auth-Token=${xauth_token} |
| 69 | ${resp}= Get Request |
| 70 | ... openbmc ${base_uri} headers=${headers} timeout=${timeout} |
| 71 | |
| 72 | Return From Keyword If ${response_format} != "json" ${resp} |
| 73 | |
| 74 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 75 | |
| 76 | ${content} = To JSON ${resp.content} |
| 77 | [Return] ${content} |
| 78 | |