blob: 100533aea3f15961130522e196e1674e49e1c1c5 [file] [log] [blame]
Joey Armstrong9fadcbe2024-01-17 19:00:37 -05001# Copyright 2017-2024 Open Networking Foundation (ONF) and the ONF Contributors
hwchiu01e51172020-01-16 22:29:13 +00002#
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
Hung-Wei Chiu2fb8c312020-03-24 13:16:38 -070089 # 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
hwchiu01e51172020-01-16 22:29:13 +000092 Should Be Equal As Strings ${resp.status_code} 207
93 Wait Until Keyword Succeeds ${timeout} 2s
HungWei Chiu1408fb92020-03-03 19:43:30 -050094 ... Check Expected DLI Switch Outlet Status ${outlet_number} true
hwchiu01e51172020-01-16 22:29:13 +000095
HungWei Chiu1408fb92020-03-03 19:43:30 -050096Enable EPC Switch Outlet
hwchiu01e51172020-01-16 22:29:13 +000097 [Arguments] ${outlet_number}
HungWei Chiu1408fb92020-03-03 19:43:30 -050098 [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
103Disable DLI Switch Outlet
104 [Arguments] ${outlet_number}
105 [Documentation] Disable specific outlet of DLI Power Switch
Hung-Wei Chiu6662a532020-03-23 14:54:29 -0700106 # Port number starts from 0 in DLI API
Hung-Wei Chiu2fb8c312020-03-24 13:16:38 -0700107 # 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
hwchiu01e51172020-01-16 22:29:13 +0000110 Should Be Equal As Strings ${resp.status_code} 207
111 Wait Until Keyword Succeeds ${timeout} 2s
HungWei Chiu1408fb92020-03-03 19:43:30 -0500112 ... Check Expected DLI Switch Outlet Status ${outlet_number} false
hwchiu01e51172020-01-16 22:29:13 +0000113
HungWei Chiu1408fb92020-03-03 19:43:30 -0500114Disable 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
121Check Expected DLI Switch Outlet Status
hwchiu01e51172020-01-16 22:29:13 +0000122 [Arguments] ${outlet_number} ${status}
HungWei Chiu1408fb92020-03-03 19:43:30 -0500123 [Documentation] Succeeds if the status of the desired DLI switch outlet is expected
Hung-Wei Chiu6662a532020-03-23 14:54:29 -0700124 # Port number starts from 0 in DLI API
125 ${outlet_number}= Evaluate ${outlet_number}-1
hwchiu01e51172020-01-16 22:29:13 +0000126 ${resp}= Get Request alias=${alias_name} uri==${outlet_number}/state/
127 Should Be Equal As Strings ${resp.text} [${status}]
HungWei Chiu1408fb92020-03-03 19:43:30 -0500128
129Check 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}