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} |
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 | eaa73b7 | 2018-07-30 09:30:16 -0500 | [diff] [blame] | 67 | ${base_uri} = Catenate SEPARATOR= ${REDFISH_BASE_URI} ${uri_suffix} |
| 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 |
| 84 | ... openbmc ${base_uri} headers=${headers} timeout=${timeout} |
| 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 | |
| 94 | Redfish Delete Request |
| 95 | [Documentation] Delete the resource identified by the URI. |
George Keishing | 138f9d3 | 2018-08-08 10:50:05 -0500 | [diff] [blame] | 96 | [Arguments] ${uri_suffix} |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame] | 97 | ... ${xauth_token} |
| 98 | ... ${timeout}=10 |
George Keishing | d61775f | 2018-08-09 01:02:30 -0500 | [diff] [blame] | 99 | ... ${resp_check}=${1} |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame] | 100 | |
| 101 | # Description of argument(s): |
George Keishing | 138f9d3 | 2018-08-08 10:50:05 -0500 | [diff] [blame] | 102 | # uri_suffix The URI to establish connection with |
| 103 | # (e.g. 'SessionService/Sessions/XIApcw39QU'). |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame] | 104 | # xauth_token Authentication token. |
| 105 | # timeout Timeout in seconds to establish connection with URI. |
George Keishing | 884d7d4 | 2018-08-09 12:43:13 -0500 | [diff] [blame^] | 106 | # resp_check By default check the response status. |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame] | 107 | |
George Keishing | 138f9d3 | 2018-08-08 10:50:05 -0500 | [diff] [blame] | 108 | ${base_uri} = Catenate SEPARATOR= ${REDFISH_BASE_URI} ${uri_suffix} |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame] | 109 | |
| 110 | # Example: "X-Auth-Token: 3la1JUf1vY4yN2dNOwun" |
| 111 | ${headers} = Create Dictionary Content-Type=application/json |
| 112 | ... X-Auth-Token=${xauth_token} |
| 113 | |
| 114 | # Delete server session. |
| 115 | ${resp}= Delete Request openbmc |
| 116 | ... ${base_uri} headers=${headers} timeout=${timeout} |
George Keishing | d61775f | 2018-08-09 01:02:30 -0500 | [diff] [blame] | 117 | |
| 118 | Return From Keyword If ${resp_check} == ${0} ${resp} |
| 119 | |
George Keishing | 9cef109 | 2018-08-06 01:06:24 -0500 | [diff] [blame] | 120 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 121 | |
| 122 | # Delete client sessions. |
| 123 | Delete All Sessions |