blob: b33f813164794bc1a2878573d31a5c8329d4ad27 [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
Hung-Wei Chiu6662a532020-03-23 14:54:29 -070088 # Port number starts from 0 in DLI API
89 ${outlet_number}= Evaluate ${outlet_number}-1
hwchiu01e51172020-01-16 22:29:13 +000090 ${resp}= Put Request alias=${alias_name} uri==${outlet_number}/state/ data=value=true
91 Should Be Equal As Strings ${resp.status_code} 207
92 Wait Until Keyword Succeeds ${timeout} 2s
HungWei Chiu1408fb92020-03-03 19:43:30 -050093 ... Check Expected DLI Switch Outlet Status ${outlet_number} true
hwchiu01e51172020-01-16 22:29:13 +000094
HungWei Chiu1408fb92020-03-03 19:43:30 -050095Enable EPC Switch Outlet
hwchiu01e51172020-01-16 22:29:13 +000096 [Arguments] ${outlet_number}
HungWei Chiu1408fb92020-03-03 19:43:30 -050097 [Documentation] Enable specific outlet of EPC power switch
98 ${resp}= Get Request alias=${alias_name} uri=ov.html?cmd=1&p=${outlet_number}&s=1
99 Wait Until Keyword Succeeds ${timeout} 2s
100 ... Check Expected EPC Switch Outlet Status ${outlet_number} 1
101
102Disable DLI Switch Outlet
103 [Arguments] ${outlet_number}
104 [Documentation] Disable specific outlet of DLI Power Switch
Hung-Wei Chiu6662a532020-03-23 14:54:29 -0700105 # Port number starts from 0 in DLI API
106 ${outlet_number}= Evaluate ${outlet_number}-1
hwchiu01e51172020-01-16 22:29:13 +0000107 ${resp}= Put Request alias=${alias_name} uri==${outlet_number}/state/ data=value=false
108 Should Be Equal As Strings ${resp.status_code} 207
109 Wait Until Keyword Succeeds ${timeout} 2s
HungWei Chiu1408fb92020-03-03 19:43:30 -0500110 ... Check Expected DLI Switch Outlet Status ${outlet_number} false
hwchiu01e51172020-01-16 22:29:13 +0000111
HungWei Chiu1408fb92020-03-03 19:43:30 -0500112Disable EPC Switch Outlet
113 [Arguments] ${outlet_number}
114 [Documentation] Disable specific outlet of EPC Power Switch
115 ${resp}= Get Request alias=${alias_name} uri=ov.html?cmd=1&p=${outlet_number}&s=0
116 Wait Until Keyword Succeeds ${timeout} 2s
117 ... Check Expected EPC Switch Outlet Status ${outlet_number} 0
118
119Check Expected DLI Switch Outlet Status
hwchiu01e51172020-01-16 22:29:13 +0000120 [Arguments] ${outlet_number} ${status}
HungWei Chiu1408fb92020-03-03 19:43:30 -0500121 [Documentation] Succeeds if the status of the desired DLI switch outlet is expected
Hung-Wei Chiu6662a532020-03-23 14:54:29 -0700122 # Port number starts from 0 in DLI API
123 ${outlet_number}= Evaluate ${outlet_number}-1
hwchiu01e51172020-01-16 22:29:13 +0000124 ${resp}= Get Request alias=${alias_name} uri==${outlet_number}/state/
125 Should Be Equal As Strings ${resp.text} [${status}]
HungWei Chiu1408fb92020-03-03 19:43:30 -0500126
127Check Expected EPC Switch Outlet Status
128 [Arguments] ${outlet_number} ${status}
129 [Documentation] Succeeds if the status of the desired EPC switch outlet is expected
130 ${resp}= Get Request alias=${alias_name} uri=statusjsn.js?components=1
131 ${outlet_number}= Convert To Number ${outlet_number}
132 ${rc} ${outlet_status} Run and Return Rc And Output
133 ... echo '${resp.text}' | jq -r .outputs[${outlet_number - 1}].state
134 Should Be Equal As Integers 0 ${rc}
135 Should Be Equal As Strings ${outlet_status} ${status}