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} |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame^] | 43 | ${content} = To JSON ${resp.content} |
| 44 | |
| 45 | Log ${content["Id"]} |
George Keishing | eaa73b7 | 2018-07-30 09:30:16 -0500 | [diff] [blame] | 46 | Log ${resp.headers["X-Auth-Token"]} |
| 47 | |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame^] | 48 | [Return] ${content["Id"]} ${resp.headers["X-Auth-Token"]} |
George Keishing | eaa73b7 | 2018-07-30 09:30:16 -0500 | [diff] [blame] | 49 | |
| 50 | |
| 51 | Redfish Get Request |
| 52 | [Documentation] Do REST GET request and return the result. |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame^] | 53 | [Arguments] ${uri_suffix} |
| 54 | ... ${session_id}=${None} |
| 55 | ... ${xauth_token}=${None} |
| 56 | ... ${response_format}="json" |
| 57 | ... ${timeout}=30 |
George Keishing | eaa73b7 | 2018-07-30 09:30:16 -0500 | [diff] [blame] | 58 | |
| 59 | # Description of argument(s): |
| 60 | # uri_suffix The URI to establish connection with |
| 61 | # (e.g. 'Systems'). |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame^] | 62 | # session_id Session id. |
George Keishing | eaa73b7 | 2018-07-30 09:30:16 -0500 | [diff] [blame] | 63 | # xauth_token Authentication token. |
| 64 | # response_format The format desired for data returned by this keyword |
| 65 | # (json/HTTPS response). |
| 66 | # timeout Timeout in seconds to establish connection with URI. |
| 67 | |
George Keishing | eaa73b7 | 2018-07-30 09:30:16 -0500 | [diff] [blame] | 68 | ${base_uri} = Catenate SEPARATOR= ${REDFISH_BASE_URI} ${uri_suffix} |
| 69 | |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame^] | 70 | # Create session, token list [vIP8IxCQlQ, Nq9l7fgP8FFeFg3QgCpr]. |
| 71 | ${id_auth_list} = Create List ${session_id} ${xauth_token} |
| 72 | |
| 73 | # Set session and auth token variable. |
| 74 | ${session_id} ${xauth_token} = |
| 75 | ... Run Keyword If "${xauth_token}" == "${None}" |
| 76 | ... Redfish Login Request |
| 77 | ... ELSE |
| 78 | ... Set Variable ${id_auth_list} |
| 79 | |
George Keishing | eaa73b7 | 2018-07-30 09:30:16 -0500 | [diff] [blame] | 80 | # Example: "X-Auth-Token: 3la1JUf1vY4yN2dNOwun" |
| 81 | ${headers} = Create Dictionary Content-Type=application/json |
| 82 | ... X-Auth-Token=${xauth_token} |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame^] | 83 | |
George Keishing | eaa73b7 | 2018-07-30 09:30:16 -0500 | [diff] [blame] | 84 | ${resp}= Get Request |
| 85 | ... openbmc ${base_uri} headers=${headers} timeout=${timeout} |
| 86 | |
| 87 | Return From Keyword If ${response_format} != "json" ${resp} |
| 88 | |
| 89 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 90 | |
| 91 | ${content} = To JSON ${resp.content} |
| 92 | [Return] ${content} |
| 93 | |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame^] | 94 | |
| 95 | Redfish Delete Request |
| 96 | [Documentation] Delete the resource identified by the URI. |
| 97 | [Arguments] ${session_id} |
| 98 | ... ${xauth_token} |
| 99 | ... ${timeout}=10 |
| 100 | |
| 101 | # Description of argument(s): |
| 102 | # session_id Session id. |
| 103 | # xauth_token Authentication token. |
| 104 | # timeout Timeout in seconds to establish connection with URI. |
| 105 | |
| 106 | ${base_uri} = Catenate SEPARATOR= ${REDFISH_SESSION}${/} ${session_id} |
| 107 | |
| 108 | # Example: "X-Auth-Token: 3la1JUf1vY4yN2dNOwun" |
| 109 | ${headers} = Create Dictionary Content-Type=application/json |
| 110 | ... X-Auth-Token=${xauth_token} |
| 111 | |
| 112 | # Delete server session. |
| 113 | ${resp}= Delete Request openbmc |
| 114 | ... ${base_uri} headers=${headers} timeout=${timeout} |
| 115 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 116 | |
| 117 | # Delete client sessions. |
| 118 | Delete All Sessions |