hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 1 | # Copyright 2017-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | *** Settings *** |
HungWei Chiu | 1408fb9 | 2020-03-03 19:43:30 -0500 | [diff] [blame] | 16 | Documentation Library for Web Power Switch, support DLI(Digital Loggers) |
| 17 | ... and EPC(Expert Power Control) |
hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 18 | Library Collections |
| 19 | Library RequestsLibrary |
| 20 | |
| 21 | *** Variables *** |
| 22 | ${timeout} 60s |
| 23 | ${alias_name} Switch Outlet |
hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 24 | |
| 25 | *** Keywords *** |
| 26 | Power Switch Connection Suite |
| 27 | [Arguments] ${ip} ${username} ${password} |
| 28 | [Documentation] Setup The HTTP Session To Web Power Switch |
HungWei Chiu | 1408fb9 | 2020-03-03 19:43:30 -0500 | [diff] [blame] | 29 | Variable Should Exist ${powerswitch_type} |
| 30 | ... 'Miss Global Variable powerswitch_type, available options are EPC, DLI' |
| 31 | Run Keyword IF '${powerswitch_type}' == 'DLI' Setup DLI Power Switch ${ip} ${username} ${password} |
| 32 | ... ELSE IF '${powerswitch_type}' == 'EPC' Setup EPC Power Switch ${ip} ${username} ${password} |
| 33 | ... ELSE Fail 'The Power Switch Type unsupported: ${powerswitch_type}' |
| 34 | |
| 35 | Enable Switch Outlet |
| 36 | [Arguments] ${outlet_number} |
| 37 | [Documentation] Enable specific outlet of the Web Power Switch |
| 38 | Variable Should Exist ${powerswitch_type} |
| 39 | ... 'Miss Global Variable powerswitch_type, available options are EPC, DLI' |
| 40 | Run Keyword IF '${powerswitch_type}' == 'DLI' Enable DLI Switch Outlet ${outlet_number} |
| 41 | ... ELSE IF '${powerswitch_type}' == 'EPC' Enable EPC Switch Outlet ${outlet_number} |
| 42 | ... ELSE Fail 'The Power Switch Type unsupported: ${powerswitch_type}' |
| 43 | |
| 44 | |
| 45 | Disable Switch Outlet |
| 46 | [Arguments] ${outlet_number} |
| 47 | [Documentation] Disable specific outlet of the web Power Switch |
| 48 | Variable Should Exist ${powerswitch_type} |
| 49 | ... 'Miss Global Variable powerswitch_type, available options are EPC, DLI' |
| 50 | Run Keyword IF '${powerswitch_type}' == 'DLI' Disable DLI Switch Outlet ${outlet_number} |
| 51 | ... ELSE IF '${powerswitch_type}' == 'EPC' Disable EPC Switch Outlet ${outlet_number} |
| 52 | ... ELSE Fail 'The Power Switch Type unsupported: ${powerswitch_type}' |
| 53 | |
| 54 | Check Expected Switch Outlet Status |
| 55 | [Arguments] ${outlet_number} ${status} |
| 56 | [Documentation] Succeeds if the status of the desired switch outlet is expected |
| 57 | Variable Should Exist ${powerswitch_type} |
| 58 | ... 'Miss Global Variable powerswitch_type, available options are EPC, DLI' |
| 59 | Run Keyword IF '${powerswitch_type}' == 'DLI' Check Expected DLI Switch Outlet Status ${outlet_number} |
| 60 | ... ELSE IF '${powerswitch_type}' == 'EPC' Check Expected EPC Switch Outlet Status ${outlet_number} |
| 61 | ... ELSE Fail 'The Power Switch Type unsupported: ${powerswitch_type}' |
| 62 | |
| 63 | #Intenal Use Only |
| 64 | Setup DLI Power Switch |
| 65 | [Arguments] ${ip} ${username} ${password} |
| 66 | [Documentation] Setup The HTTP Session To Web Power Switch |
hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 67 | ${auth}= Create List ${username} ${password} |
| 68 | ${headers}= Create Dictionary |
| 69 | Set To Dictionary ${headers} X-CSRF x |
| 70 | Set To Dictionary ${headers} Content-Type application/x-www-form-urlencoded |
HungWei Chiu | 1408fb9 | 2020-03-03 19:43:30 -0500 | [diff] [blame] | 71 | Create Digest Session alias=${alias_name} url=http://${ip}/restapi/relay/outlets/ |
hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 72 | ... auth=${auth} headers=${headers} |
| 73 | |
HungWei Chiu | 1408fb9 | 2020-03-03 19:43:30 -0500 | [diff] [blame] | 74 | Setup EPC Power Switch |
| 75 | [Arguments] ${ip} ${username} ${password} |
| 76 | [Documentation] Setup The HTTP Session To Web Power Switch |
| 77 | ${auth}= Create List ${username} ${password} |
| 78 | ${headers}= Create Dictionary |
| 79 | Set To Dictionary ${headers} X-CSRF x |
| 80 | Set To Dictionary ${headers} Content-Type application/x-www-form-urlencoded |
| 81 | Create Digest Session alias=${alias_name} url=http://${ip} |
| 82 | ... auth=${auth} headers=${headers} |
| 83 | |
| 84 | |
| 85 | Enable DLI Switch Outlet |
hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 86 | [Arguments] ${outlet_number} |
HungWei Chiu | 1408fb9 | 2020-03-03 19:43:30 -0500 | [diff] [blame] | 87 | [Documentation] Enable specific outlet of DLI power switch |
hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 88 | ${resp}= Put Request alias=${alias_name} uri==${outlet_number}/state/ data=value=true |
| 89 | Should Be Equal As Strings ${resp.status_code} 207 |
| 90 | Wait Until Keyword Succeeds ${timeout} 2s |
HungWei Chiu | 1408fb9 | 2020-03-03 19:43:30 -0500 | [diff] [blame] | 91 | ... Check Expected DLI Switch Outlet Status ${outlet_number} true |
hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 92 | |
HungWei Chiu | 1408fb9 | 2020-03-03 19:43:30 -0500 | [diff] [blame] | 93 | Enable EPC Switch Outlet |
hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 94 | [Arguments] ${outlet_number} |
HungWei Chiu | 1408fb9 | 2020-03-03 19:43:30 -0500 | [diff] [blame] | 95 | [Documentation] Enable specific outlet of EPC power switch |
| 96 | ${resp}= Get Request alias=${alias_name} uri=ov.html?cmd=1&p=${outlet_number}&s=1 |
| 97 | Wait Until Keyword Succeeds ${timeout} 2s |
| 98 | ... Check Expected EPC Switch Outlet Status ${outlet_number} 1 |
| 99 | |
| 100 | Disable DLI Switch Outlet |
| 101 | [Arguments] ${outlet_number} |
| 102 | [Documentation] Disable specific outlet of DLI Power Switch |
hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 103 | ${resp}= Put Request alias=${alias_name} uri==${outlet_number}/state/ data=value=false |
| 104 | Should Be Equal As Strings ${resp.status_code} 207 |
| 105 | Wait Until Keyword Succeeds ${timeout} 2s |
HungWei Chiu | 1408fb9 | 2020-03-03 19:43:30 -0500 | [diff] [blame] | 106 | ... Check Expected DLI Switch Outlet Status ${outlet_number} false |
hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 107 | |
HungWei Chiu | 1408fb9 | 2020-03-03 19:43:30 -0500 | [diff] [blame] | 108 | Disable EPC Switch Outlet |
| 109 | [Arguments] ${outlet_number} |
| 110 | [Documentation] Disable specific outlet of EPC Power Switch |
| 111 | ${resp}= Get Request alias=${alias_name} uri=ov.html?cmd=1&p=${outlet_number}&s=0 |
| 112 | Wait Until Keyword Succeeds ${timeout} 2s |
| 113 | ... Check Expected EPC Switch Outlet Status ${outlet_number} 0 |
| 114 | |
| 115 | Check Expected DLI Switch Outlet Status |
hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 116 | [Arguments] ${outlet_number} ${status} |
HungWei Chiu | 1408fb9 | 2020-03-03 19:43:30 -0500 | [diff] [blame] | 117 | [Documentation] Succeeds if the status of the desired DLI switch outlet is expected |
hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 118 | ${resp}= Get Request alias=${alias_name} uri==${outlet_number}/state/ |
| 119 | Should Be Equal As Strings ${resp.text} [${status}] |
HungWei Chiu | 1408fb9 | 2020-03-03 19:43:30 -0500 | [diff] [blame] | 120 | |
| 121 | Check Expected EPC Switch Outlet Status |
| 122 | [Arguments] ${outlet_number} ${status} |
| 123 | [Documentation] Succeeds if the status of the desired EPC switch outlet is expected |
| 124 | ${resp}= Get Request alias=${alias_name} uri=statusjsn.js?components=1 |
| 125 | ${outlet_number}= Convert To Number ${outlet_number} |
| 126 | ${rc} ${outlet_status} Run and Return Rc And Output |
| 127 | ... echo '${resp.text}' | jq -r .outputs[${outlet_number - 1}].state |
| 128 | Should Be Equal As Integers 0 ${rc} |
| 129 | Should Be Equal As Strings ${outlet_status} ${status} |