blob: 19c5974ecc64dbc95e676c3aa01b1867c3d2cd93 [file] [log] [blame]
hwchiu01e51172020-01-16 22:29:13 +00001# 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 Chiu1408fb92020-03-03 19:43:30 -050016Documentation Library for Web Power Switch, support DLI(Digital Loggers)
17 ... and EPC(Expert Power Control)
hwchiu01e51172020-01-16 22:29:13 +000018Library Collections
19Library RequestsLibrary
20
21*** Variables ***
22${timeout} 60s
23${alias_name} Switch Outlet
hwchiu01e51172020-01-16 22:29:13 +000024
25*** Keywords ***
26Power Switch Connection Suite
27 [Arguments] ${ip} ${username} ${password}
28 [Documentation] Setup The HTTP Session To Web Power Switch
HungWei Chiu1408fb92020-03-03 19:43:30 -050029 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
35Enable 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
45Disable 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
54Check 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
64Setup DLI Power Switch
65 [Arguments] ${ip} ${username} ${password}
66 [Documentation] Setup The HTTP Session To Web Power Switch
hwchiu01e51172020-01-16 22:29:13 +000067 ${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 Chiu1408fb92020-03-03 19:43:30 -050071 Create Digest Session alias=${alias_name} url=http://${ip}/restapi/relay/outlets/
hwchiu01e51172020-01-16 22:29:13 +000072 ... auth=${auth} headers=${headers}
73
HungWei Chiu1408fb92020-03-03 19:43:30 -050074Setup 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
85Enable DLI Switch Outlet
hwchiu01e51172020-01-16 22:29:13 +000086 [Arguments] ${outlet_number}
HungWei Chiu1408fb92020-03-03 19:43:30 -050087 [Documentation] Enable specific outlet of DLI power switch
hwchiu01e51172020-01-16 22:29:13 +000088 ${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 Chiu1408fb92020-03-03 19:43:30 -050091 ... Check Expected DLI Switch Outlet Status ${outlet_number} true
hwchiu01e51172020-01-16 22:29:13 +000092
HungWei Chiu1408fb92020-03-03 19:43:30 -050093Enable EPC Switch Outlet
hwchiu01e51172020-01-16 22:29:13 +000094 [Arguments] ${outlet_number}
HungWei Chiu1408fb92020-03-03 19:43:30 -050095 [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
100Disable DLI Switch Outlet
101 [Arguments] ${outlet_number}
102 [Documentation] Disable specific outlet of DLI Power Switch
hwchiu01e51172020-01-16 22:29:13 +0000103 ${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 Chiu1408fb92020-03-03 19:43:30 -0500106 ... Check Expected DLI Switch Outlet Status ${outlet_number} false
hwchiu01e51172020-01-16 22:29:13 +0000107
HungWei Chiu1408fb92020-03-03 19:43:30 -0500108Disable 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
115Check Expected DLI Switch Outlet Status
hwchiu01e51172020-01-16 22:29:13 +0000116 [Arguments] ${outlet_number} ${status}
HungWei Chiu1408fb92020-03-03 19:43:30 -0500117 [Documentation] Succeeds if the status of the desired DLI switch outlet is expected
hwchiu01e51172020-01-16 22:29:13 +0000118 ${resp}= Get Request alias=${alias_name} uri==${outlet_number}/state/
119 Should Be Equal As Strings ${resp.text} [${status}]
HungWei Chiu1408fb92020-03-03 19:43:30 -0500120
121Check 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}