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 | |
George Keishing | ef7a30d | 2018-10-30 12:34:56 -0500 | [diff] [blame] | 42 | Should Be Equal As Strings ${resp.status_code} ${HTTP_CREATED} |
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} |
George Keishing | 884d7d4 | 2018-08-09 12:43:13 -0500 | [diff] [blame] | 56 | ... ${resp_check}=${1} |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame] | 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. |
George Keishing | 884d7d4 | 2018-08-09 12:43:13 -0500 | [diff] [blame] | 64 | # resp_check By default check the response status and return JSON. |
George Keishing | eaa73b7 | 2018-07-30 09:30:16 -0500 | [diff] [blame] | 65 | # timeout Timeout in seconds to establish connection with URI. |
| 66 | |
George Keishing | e7a3a3b | 2018-11-27 09:31:03 -0600 | [diff] [blame] | 67 | ${uri} = Catenate SEPARATOR= ${REDFISH_BASE_URI} ${uri_suffix} |
George Keishing | eaa73b7 | 2018-07-30 09:30:16 -0500 | [diff] [blame] | 68 | |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame] | 69 | # Create session, token list [vIP8IxCQlQ, Nq9l7fgP8FFeFg3QgCpr]. |
| 70 | ${id_auth_list} = Create List ${session_id} ${xauth_token} |
| 71 | |
| 72 | # Set session and auth token variable. |
| 73 | ${session_id} ${xauth_token} = |
| 74 | ... Run Keyword If "${xauth_token}" == "${None}" |
| 75 | ... Redfish Login Request |
| 76 | ... ELSE |
| 77 | ... Set Variable ${id_auth_list} |
| 78 | |
George Keishing | eaa73b7 | 2018-07-30 09:30:16 -0500 | [diff] [blame] | 79 | # Example: "X-Auth-Token: 3la1JUf1vY4yN2dNOwun" |
| 80 | ${headers} = Create Dictionary Content-Type=application/json |
| 81 | ... X-Auth-Token=${xauth_token} |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame] | 82 | |
George Keishing | eaa73b7 | 2018-07-30 09:30:16 -0500 | [diff] [blame] | 83 | ${resp}= Get Request |
George Keishing | e7a3a3b | 2018-11-27 09:31:03 -0600 | [diff] [blame] | 84 | ... openbmc ${uri} headers=${headers} timeout=${timeout} |
George Keishing | eaa73b7 | 2018-07-30 09:30:16 -0500 | [diff] [blame] | 85 | |
George Keishing | 884d7d4 | 2018-08-09 12:43:13 -0500 | [diff] [blame] | 86 | Return From Keyword If ${resp_check} == ${0} ${resp} |
George Keishing | eaa73b7 | 2018-07-30 09:30:16 -0500 | [diff] [blame] | 87 | |
| 88 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 89 | |
| 90 | ${content} = To JSON ${resp.content} |
| 91 | [Return] ${content} |
| 92 | |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame] | 93 | |
George Keishing | e7a3a3b | 2018-11-27 09:31:03 -0600 | [diff] [blame] | 94 | Redfish Post Request |
| 95 | [Documentation] Do redfish POST request. |
| 96 | [Arguments] ${uri_suffix} |
George Keishing | e7a3a3b | 2018-11-27 09:31:03 -0600 | [diff] [blame] | 97 | ... ${timeout}=30 |
George Keishing | 713dd5e | 2018-11-29 01:16:19 -0600 | [diff] [blame^] | 98 | ... &{kwargs} |
George Keishing | e7a3a3b | 2018-11-27 09:31:03 -0600 | [diff] [blame] | 99 | |
| 100 | # Description of argument(s): |
| 101 | # uri_suffix The URI to establish connection with |
| 102 | # (e.g. '/Systems/1/Actions/ComputerSystem.Reset'). |
| 103 | # kwargs Any additional arguments to be passed directly to the |
| 104 | # Post Request. For example, the caller might |
| 105 | # set kwargs as follows: |
| 106 | # ${kwargs}= Create Dictionary allow_redirect=${True}. |
| 107 | # timeout Timeout in seconds to establish connection with URI. |
| 108 | |
| 109 | ${uri}= Catenate SEPARATOR= ${REDFISH_BASE_URI} ${uri_suffix} |
| 110 | # Set session and auth token variable. |
| 111 | ${session_id} ${xauth_token}= Redfish Login Request |
| 112 | |
| 113 | # Set session URI path. |
| 114 | ${session_uri}= |
| 115 | ... Catenate SEPARATOR= ${REDFISH_SESSION_URI} ${session_id} |
| 116 | |
| 117 | # Example: "X-Auth-Token: 3la1JUf1vY4yN2dNOwun" |
| 118 | ${headers}= Create Dictionary Content-Type=application/json |
| 119 | ... X-Auth-Token=${xauth_token} |
| 120 | |
| 121 | ${resp}= Post Request |
| 122 | ... openbmc ${uri} &{kwargs} headers=${headers} timeout=${timeout} |
| 123 | |
| 124 | Redfish Delete Request ${session_uri} ${xauth_token} |
| 125 | |
| 126 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 127 | |
| 128 | |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame] | 129 | Redfish Delete Request |
| 130 | [Documentation] Delete the resource identified by the URI. |
George Keishing | 138f9d3 | 2018-08-08 10:50:05 -0500 | [diff] [blame] | 131 | [Arguments] ${uri_suffix} |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame] | 132 | ... ${xauth_token} |
| 133 | ... ${timeout}=10 |
George Keishing | d61775f | 2018-08-09 01:02:30 -0500 | [diff] [blame] | 134 | ... ${resp_check}=${1} |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame] | 135 | |
| 136 | # Description of argument(s): |
George Keishing | 138f9d3 | 2018-08-08 10:50:05 -0500 | [diff] [blame] | 137 | # uri_suffix The URI to establish connection with |
| 138 | # (e.g. 'SessionService/Sessions/XIApcw39QU'). |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame] | 139 | # xauth_token Authentication token. |
| 140 | # timeout Timeout in seconds to establish connection with URI. |
George Keishing | 884d7d4 | 2018-08-09 12:43:13 -0500 | [diff] [blame] | 141 | # resp_check By default check the response status. |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame] | 142 | |
George Keishing | e7a3a3b | 2018-11-27 09:31:03 -0600 | [diff] [blame] | 143 | ${uri} = Catenate SEPARATOR= ${REDFISH_BASE_URI} ${uri_suffix} |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame] | 144 | |
| 145 | # Example: "X-Auth-Token: 3la1JUf1vY4yN2dNOwun" |
| 146 | ${headers} = Create Dictionary Content-Type=application/json |
| 147 | ... X-Auth-Token=${xauth_token} |
| 148 | |
| 149 | # Delete server session. |
| 150 | ${resp}= Delete Request openbmc |
George Keishing | e7a3a3b | 2018-11-27 09:31:03 -0600 | [diff] [blame] | 151 | ... ${uri} headers=${headers} timeout=${timeout} |
George Keishing | d61775f | 2018-08-09 01:02:30 -0500 | [diff] [blame] | 152 | |
| 153 | Return From Keyword If ${resp_check} == ${0} ${resp} |
| 154 | |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame] | 155 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 156 | |
| 157 | # Delete client sessions. |
| 158 | Delete All Sessions |