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 |
Hung-Wei Chiu | 6662a53 | 2020-03-23 14:54:29 -0700 | [diff] [blame] | 88 | # Port number starts from 0 in DLI API |
Hung-Wei Chiu | 2fb8c31 | 2020-03-24 13:16:38 -0700 | [diff] [blame] | 89 | # Pass the original outlet number to Check function to avoid duplicated calculation |
| 90 | ${new_outlet_number}= Evaluate ${outlet_number}-1 |
| 91 | ${resp}= Put Request alias=${alias_name} uri==${new_outlet_number}/state/ data=value=true |
hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 92 | Should Be Equal As Strings ${resp.status_code} 207 |
| 93 | Wait Until Keyword Succeeds ${timeout} 2s |
HungWei Chiu | 1408fb9 | 2020-03-03 19:43:30 -0500 | [diff] [blame] | 94 | ... Check Expected DLI Switch Outlet Status ${outlet_number} true |
hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 95 | |
HungWei Chiu | 1408fb9 | 2020-03-03 19:43:30 -0500 | [diff] [blame] | 96 | Enable EPC Switch Outlet |
hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 97 | [Arguments] ${outlet_number} |
HungWei Chiu | 1408fb9 | 2020-03-03 19:43:30 -0500 | [diff] [blame] | 98 | [Documentation] Enable specific outlet of EPC power switch |
| 99 | ${resp}= Get Request alias=${alias_name} uri=ov.html?cmd=1&p=${outlet_number}&s=1 |
| 100 | Wait Until Keyword Succeeds ${timeout} 2s |
| 101 | ... Check Expected EPC Switch Outlet Status ${outlet_number} 1 |
| 102 | |
| 103 | Disable DLI Switch Outlet |
| 104 | [Arguments] ${outlet_number} |
| 105 | [Documentation] Disable specific outlet of DLI Power Switch |
Hung-Wei Chiu | 6662a53 | 2020-03-23 14:54:29 -0700 | [diff] [blame] | 106 | # Port number starts from 0 in DLI API |
Hung-Wei Chiu | 2fb8c31 | 2020-03-24 13:16:38 -0700 | [diff] [blame] | 107 | # Pass the original outlet number to Check function to avoid duplicated calculation |
| 108 | ${new_outlet_number}= Evaluate ${outlet_number}-1 |
| 109 | ${resp}= Put Request alias=${alias_name} uri==${new_outlet_number}/state/ data=value=false |
hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 110 | Should Be Equal As Strings ${resp.status_code} 207 |
| 111 | Wait Until Keyword Succeeds ${timeout} 2s |
HungWei Chiu | 1408fb9 | 2020-03-03 19:43:30 -0500 | [diff] [blame] | 112 | ... Check Expected DLI Switch Outlet Status ${outlet_number} false |
hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 113 | |
HungWei Chiu | 1408fb9 | 2020-03-03 19:43:30 -0500 | [diff] [blame] | 114 | Disable EPC Switch Outlet |
| 115 | [Arguments] ${outlet_number} |
| 116 | [Documentation] Disable specific outlet of EPC Power Switch |
| 117 | ${resp}= Get Request alias=${alias_name} uri=ov.html?cmd=1&p=${outlet_number}&s=0 |
| 118 | Wait Until Keyword Succeeds ${timeout} 2s |
| 119 | ... Check Expected EPC Switch Outlet Status ${outlet_number} 0 |
| 120 | |
| 121 | Check Expected DLI Switch Outlet Status |
hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 122 | [Arguments] ${outlet_number} ${status} |
HungWei Chiu | 1408fb9 | 2020-03-03 19:43:30 -0500 | [diff] [blame] | 123 | [Documentation] Succeeds if the status of the desired DLI switch outlet is expected |
Hung-Wei Chiu | 6662a53 | 2020-03-23 14:54:29 -0700 | [diff] [blame] | 124 | # Port number starts from 0 in DLI API |
| 125 | ${outlet_number}= Evaluate ${outlet_number}-1 |
hwchiu | 01e5117 | 2020-01-16 22:29:13 +0000 | [diff] [blame] | 126 | ${resp}= Get Request alias=${alias_name} uri==${outlet_number}/state/ |
| 127 | Should Be Equal As Strings ${resp.text} [${status}] |
HungWei Chiu | 1408fb9 | 2020-03-03 19:43:30 -0500 | [diff] [blame] | 128 | |
| 129 | Check Expected EPC Switch Outlet Status |
| 130 | [Arguments] ${outlet_number} ${status} |
| 131 | [Documentation] Succeeds if the status of the desired EPC switch outlet is expected |
| 132 | ${resp}= Get Request alias=${alias_name} uri=statusjsn.js?components=1 |
| 133 | ${outlet_number}= Convert To Number ${outlet_number} |
| 134 | ${rc} ${outlet_status} Run and Return Rc And Output |
| 135 | ... echo '${resp.text}' | jq -r .outputs[${outlet_number - 1}].state |
| 136 | Should Be Equal As Integers 0 ${rc} |
| 137 | Should Be Equal As Strings ${outlet_status} ${status} |