| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 1 | *** Settings *** | 
 | 2 | Library           Collections | 
 | 3 | Library           String | 
 | 4 | Library           RequestsLibrary.RequestsKeywords | 
 | 5 | Library           OperatingSystem | 
 | 6 | Resource          ../lib/resource.txt | 
 | 7 | Library           ../lib/disable_warning_urllib.py | 
 | 8 |  | 
 | 9 | *** Variables *** | 
 | 10 | # Response codes | 
 | 11 | ${HTTP_CONTINUE}    100 | 
 | 12 | ${HTTP_SWITCHING_PROTOCOLS}    101 | 
 | 13 | ${HTTP_PROCESSING}    102 | 
 | 14 | ${HTTP_OK}        200 | 
 | 15 | ${HTTP_CREATED}    201 | 
 | 16 | ${HTTP_ACCEPTED}    202 | 
 | 17 | ${HTTP_NON_AUTHORITATIVE_INFORMATION}    203 | 
 | 18 | ${HTTP_NO_CONTENT}    204 | 
 | 19 | ${HTTP_RESET_CONTENT}    205 | 
 | 20 | ${HTTP_PARTIAL_CONTENT}    206 | 
 | 21 | ${HTTP_MULTI_STATUS}    207 | 
 | 22 | ${HTTP_IM_USED}    226 | 
 | 23 | ${HTTP_MULTIPLE_CHOICES}    300 | 
 | 24 | ${HTTP_MOVED_PERMANENTLY}    301 | 
 | 25 | ${HTTP_FOUND}     302 | 
 | 26 | ${HTTP_SEE_OTHER}    303 | 
 | 27 | ${HTTP_NOT_MODIFIED}    304 | 
 | 28 | ${HTTP_USE_PROXY}    305 | 
 | 29 | ${HTTP_TEMPORARY_REDIRECT}    307 | 
 | 30 | ${HTTP_BAD_REQUEST}    400 | 
 | 31 | ${HTTP_UNAUTHORIZED}    401 | 
 | 32 | ${HTTP_PAYMENT_REQUIRED}    402 | 
 | 33 | ${HTTP_FORBIDDEN}    403 | 
 | 34 | ${HTTP_NOT_FOUND}    404 | 
 | 35 | ${HTTP_METHOD_NOT_ALLOWED}    405 | 
 | 36 | ${HTTP_NOT_ACCEPTABLE}    406 | 
 | 37 | ${HTTP_PROXY_AUTHENTICATION_REQUIRED}    407 | 
 | 38 | ${HTTP_REQUEST_TIMEOUT}    408 | 
 | 39 | ${HTTP_CONFLICT}    409 | 
 | 40 | ${HTTP_GONE}      410 | 
 | 41 | ${HTTP_LENGTH_REQUIRED}    411 | 
 | 42 | ${HTTP_PRECONDITION_FAILED}    412 | 
 | 43 | ${HTTP_REQUEST_ENTITY_TOO_LARGE}    413 | 
 | 44 | ${HTTP_REQUEST_URI_TOO_LONG}    414 | 
 | 45 | ${HTTP_UNSUPPORTED_MEDIA_TYPE}    415 | 
 | 46 | ${HTTP_REQUESTED_RANGE_NOT_SATISFIABLE}    416 | 
 | 47 | ${HTTP_EXPECTATION_FAILED}    417 | 
 | 48 | ${HTTP_UNPROCESSABLE_ENTITY}    422 | 
 | 49 | ${HTTP_LOCKED}    423 | 
 | 50 | ${HTTP_FAILED_DEPENDENCY}    424 | 
 | 51 | ${HTTP_UPGRADE_REQUIRED}    426 | 
 | 52 | ${HTTP_INTERNAL_SERVER_ERROR}    500 | 
 | 53 | ${HTTP_NOT_IMPLEMENTED}    501 | 
 | 54 | ${HTTP_BAD_GATEWAY}    502 | 
 | 55 | ${HTTP_SERVICE_UNAVAILABLE}    503 | 
 | 56 | ${HTTP_GATEWAY_TIMEOUT}    504 | 
 | 57 | ${HTTP_HTTP_VERSION_NOT_SUPPORTED}    505 | 
 | 58 | ${HTTP_INSUFFICIENT_STORAGE}    507 | 
 | 59 | ${HTTP_NOT_EXTENDED}    510 | 
 | 60 |  | 
 | 61 | *** Keywords *** | 
 | 62 | OpenBMC Get Request | 
| Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 63 |     [Arguments]    ${uri}    ${timeout}=10    &{kwargs} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 64 |     ${base_uri}=    Catenate    SEPARATOR=    ${DBUS_PREFIX}    ${uri} | 
 | 65 |     Log Request    method=Get    base_uri=${base_uri}    args=&{kwargs} | 
| Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 66 |     Initialize OpenBMC    ${timeout} | 
 | 67 |     ${ret}=    Get Request    openbmc    ${base_uri}    &{kwargs}  timeout=${timeout} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 68 |     Log Response    ${ret} | 
 | 69 |     [Return]    ${ret} | 
 | 70 |  | 
 | 71 | OpenBMC Post Request | 
| Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 72 |     [Arguments]    ${uri}    ${timeout}=10    &{kwargs} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 73 |     ${base_uri}=    Catenate    SEPARATOR=    ${DBUS_PREFIX}    ${uri} | 
 | 74 |     ${headers}=     Create Dictionary   Content-Type=application/json | 
 | 75 |     set to dictionary   ${kwargs}       headers     ${headers} | 
 | 76 |     Log Request    method=Post    base_uri=${base_uri}    args=&{kwargs} | 
| Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 77 |     Initialize OpenBMC    ${timeout} | 
 | 78 |     ${ret}=    Post Request    openbmc    ${base_uri}    &{kwargs}  timeout=${timeout} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 79 |     Log Response    ${ret} | 
 | 80 |     [Return]    ${ret} | 
 | 81 |  | 
 | 82 | OpenBMC Put Request | 
| Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 83 |     [Arguments]    ${uri}    ${timeout}=10    &{kwargs} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 84 |     ${base_uri}=    Catenate    SEPARATOR=    ${DBUS_PREFIX}    ${uri} | 
 | 85 |     ${headers}=     Create Dictionary   Content-Type=application/json | 
 | 86 |     set to dictionary   ${kwargs}       headers     ${headers} | 
 | 87 |     Log Request    method=Put    base_uri=${base_uri}    args=&{kwargs} | 
| Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 88 |     Initialize OpenBMC    ${timeout} | 
 | 89 |     ${ret}=    Put Request    openbmc    ${base_uri}    &{kwargs}  timeout=${timeout} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 90 |     Log Response    ${ret} | 
 | 91 |     [Return]    ${ret} | 
 | 92 |  | 
 | 93 | OpenBMC Delete Request | 
| Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 94 |     [Arguments]    ${uri}    ${timeout}=10    &{kwargs} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 95 |     ${base_uri}=    Catenate    SEPARATOR=    ${DBUS_PREFIX}    ${uri} | 
 | 96 |     Log Request    method=Delete    base_uri=${base_uri}    args=&{kwargs} | 
| Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 97 |     Initialize OpenBMC    ${timeout} | 
 | 98 |     ${ret}=    Put Request    openbmc    ${base_uri}    &{kwargs}  timeout=${timeout} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 99 |     Log Response    ${ret} | 
 | 100 |     [Return]    ${ret} | 
 | 101 |  | 
 | 102 | Initialize OpenBMC | 
| Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 103 |     [Arguments]    ${timeout}=10 | 
 | 104 |     Create Session    openbmc    ${AUTH_URI}  timeout=${timeout}   max_retries=3 | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 105 |     ${headers}=     Create Dictionary   Content-Type=application/json | 
 | 106 |     @{credentials} =   Create List     ${OPENBMC_USERNAME}      ${OPENBMC_PASSWORD} | 
 | 107 |     ${data} =   create dictionary   data=@{credentials} | 
 | 108 |     ${resp} =   Post Request    openbmc    /login    data=${data}   headers=${headers} | 
 | 109 |     should be equal as strings      ${resp.status_code}     ${HTTP_OK} | 
 | 110 |  | 
 | 111 | Log Request | 
 | 112 |     [Arguments]    &{kwargs} | 
 | 113 |     ${msg}=    Catenate    SEPARATOR=    URI:    ${AUTH_URI}    ${kwargs["base_uri"]}    , method: | 
 | 114 |     ...    ${kwargs["method"]}    , args:    ${kwargs["args"]} | 
 | 115 |     Logging    ${msg}    console=True | 
 | 116 |  | 
 | 117 | Log Response | 
 | 118 |     [Arguments]    ${resp} | 
 | 119 |     ${msg}=    Catenate    SEPARATOR=    Response code:    ${resp.status_code}    , Content:    ${resp.content} | 
 | 120 |     Logging    ${msg}    console=True | 
 | 121 |  | 
 | 122 | Logging | 
 | 123 |     [Arguments]    ${msg}    ${console}=default False | 
 | 124 |     Log    ${msg}    console=True | 
 | 125 |  | 
 | 126 | Read Attribute | 
| Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 127 |     [arguments]    ${uri}    ${attr}    ${timeout}=10 | 
 | 128 |     ${resp} =   OpenBMC Get Request    ${uri}/attr/${attr}    timeout=${timeout} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 129 |     ${content}=     To Json    ${resp.content} | 
 | 130 |     [return]    ${content["data"]} | 
 | 131 |  | 
 | 132 | Write Attribute | 
| Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 133 |     [Arguments]    ${uri}      ${attr}    ${timeout}=10    &{kwargs} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 134 |     ${base_uri}=    Catenate    SEPARATOR=    ${DBUS_PREFIX}    ${uri} | 
| Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 135 |     ${resp} =       openbmc put request    ${base_uri}/attr/${attr}    timeout=${timeout}    &{kwargs} | 
| George Keishing | 06ae4aa | 2016-08-30 01:41:28 -0500 | [diff] [blame] | 136 |     should be equal as strings      ${resp.status_code}     ${HTTP_OK} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 137 |     ${json} =   to json         ${resp.content} | 
 | 138 |  | 
 | 139 | Read Properties | 
| Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 140 |     [arguments]    ${uri}    ${timeout}=10 | 
 | 141 |     ${resp} =   OpenBMC Get Request    ${uri}    timeout=${timeout} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 142 |     Should Be Equal As Strings    ${resp.status_code}    ${HTTP_OK} | 
 | 143 |     ${content}=     To Json    ${resp.content} | 
 | 144 |     [return]    ${content["data"]} | 
 | 145 |  | 
 | 146 | Call Method | 
| Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 147 |     [arguments]    ${uri}    ${method}    ${timeout}=10    &{kwargs} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 148 |     ${base_uri}=    Catenate    SEPARATOR=    ${DBUS_PREFIX}    ${uri} | 
| Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 149 |     ${resp} =       openbmc post request    ${base_uri}/action/${method}    timeout=${timeout}    &{kwargs} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 150 |     [return]     ${resp} |