blob: 5600f06cea422758ae08332bfb83a5fbfcc9ef00 [file] [log] [blame]
Kailash6f5acb62019-08-28 14:38:45 -07001# 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# voltctl common functions
16
17*** Settings ***
18Documentation Library for various utilities
19Library SSHLibrary
20Library HttpLibrary.HTTP
21Library String
22Library DateTime
23Library Process
24Library Collections
25Library RequestsLibrary
26Library OperatingSystem
27
28*** Keywords ***
29Create Device
30 [Arguments] ${ip} ${port}
You Wang2b550642019-10-07 14:39:48 -070031 [Documentation] Creates a device in VOLTHA
Kailash6f5acb62019-08-28 14:38:45 -070032 #create/preprovision device
Gilles Depatie675a2062019-10-22 12:44:42 -040033 ${rc} ${device_id}= Run and Return Rc and Output
34 ... ${VOLTCTL_CONFIG}; voltctl device create -t openolt -H ${ip}:${port}
Kailash6f5acb62019-08-28 14:38:45 -070035 Should Be Equal As Integers ${rc} 0
36 [Return] ${device_id}
37
38Enable Device
39 [Arguments] ${device_id}
Zack Williamsec53a1b2019-09-16 15:50:52 -070040 [Documentation] Enables a device in VOLTHA
Kailash6f5acb62019-08-28 14:38:45 -070041 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device enable ${device_id}
42 Should Be Equal As Integers ${rc} 0
43
Suchitra Vemuri00d147d2019-09-13 13:07:32 -070044Get Device Flows from Voltha
45 [Arguments] ${device_id}
Zack Williamsec53a1b2019-09-16 15:50:52 -070046 [Documentation] Gets device flows from VOLTHA
Suchitra Vemuri00d147d2019-09-13 13:07:32 -070047 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device flows ${device_id}
48 Should Be Equal As Integers ${rc} 0
49 [Return] ${output}
50
51Get Logical Device Output from Voltha
52 [Arguments] ${device_id}
Zack Williamsec53a1b2019-09-16 15:50:52 -070053 [Documentation] Gets logicaldevice flows and ports from VOLTHA
Suchitra Vemuri00d147d2019-09-13 13:07:32 -070054 ${rc1} ${flows}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl logicaldevice flows ${device_id}
55 ${rc2} ${ports}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl logicaldevice ports ${device_id}
56 Log ${flows}
57 Log ${ports}
58 Should Be Equal As Integers ${rc1} 0
59 Should Be Equal As Integers ${rc2} 0
60
61Get Device Output from Voltha
62 [Arguments] ${device_id}
Zack Williamsec53a1b2019-09-16 15:50:52 -070063 [Documentation] Gets device flows and ports from VOLTHA
Suchitra Vemuri00d147d2019-09-13 13:07:32 -070064 ${rc1} ${flows}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device flows ${device_id}
65 ${rc2} ${ports}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device ports ${device_id}
66 Log ${flows}
67 Log ${ports}
68 Should Be Equal As Integers ${rc1} 0
69 Should Be Equal As Integers ${rc2} 0
70
Kailash6f5acb62019-08-28 14:38:45 -070071Validate Device
Gilles Depatie675a2062019-10-22 12:44:42 -040072 [Arguments] ${serial_number} ${admin_state} ${oper_status} ${connect_status} ${onu_reasons}=${EMPTY}
73 ... ${onu}=False
Kailash6f5acb62019-08-28 14:38:45 -070074 [Documentation] Parses the output of "voltctl device list" and inspects device ${serial_number}
75 ... Arguments are matched for device states of: "admin_state", "oper_status", and "connect_status"
76 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
77 ${jsondata}= To Json ${output}
78 Log ${jsondata}
79 ${length}= Get Length ${jsondata}
Zack Williamsec53a1b2019-09-16 15:50:52 -070080 FOR ${INDEX} IN RANGE 0 ${length}
81 ${value}= Get From List ${jsondata} ${INDEX}
82 ${astate}= Get From Dictionary ${value} adminstate
83 ${opstatus}= Get From Dictionary ${value} operstatus
84 ${cstatus}= Get From Dictionary ${value} connectstatus
85 ${sn}= Get From Dictionary ${value} serialnumber
86 ${mib_state}= Get From Dictionary ${value} reason
87 Run Keyword If '${sn}' == '${serial_number}' Exit For Loop
88 END
Kailash6f5acb62019-08-28 14:38:45 -070089 Should Be Equal ${astate} ${admin_state} Device ${serial_number} admin_state != ENABLED values=False
90 Should Be Equal ${opstatus} ${oper_status} Device ${serial_number} oper_status != ACTIVE values=False
Gilles Depatie675a2062019-10-22 12:44:42 -040091 Should Be Equal ${cstatus} ${connect_status} Device ${serial_number} connect_status != REACHABLE
92 ... values=False
93 Run Keyword If '${onu}' == 'True' Should Contain ${onu_reasons} ${mib_state}
94 ... Device ${serial_number} mib_state incorrect values=False
Kailash6f5acb62019-08-28 14:38:45 -070095
Kailash6f5acb62019-08-28 14:38:45 -070096Get Device ID From SN
97 [Arguments] ${serial_number}
98 [Documentation] Gets the device id by matching for ${serial_number}
99 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
100 ${jsondata}= To Json ${output}
101 Log ${jsondata}
102 ${length}= Get Length ${jsondata}
Zack Williamsec53a1b2019-09-16 15:50:52 -0700103 FOR ${INDEX} IN RANGE 0 ${length}
104 ${value}= Get From List ${jsondata} ${INDEX}
105 ${id}= Get From Dictionary ${value} id
106 ${sn}= Get From Dictionary ${value} serialnumber
107 Run Keyword If '${sn}' == '${serial_number}' Exit For Loop
108 END
Kailash6f5acb62019-08-28 14:38:45 -0700109 [Return] ${id}
110
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700111Get Logical Device ID From SN
112 [Arguments] ${serial_number}
113 [Documentation] Gets the device id by matching for ${serial_number}
114 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
115 ${jsondata}= To Json ${output}
116 Log ${jsondata}
117 ${length}= Get Length ${jsondata}
Zack Williamsec53a1b2019-09-16 15:50:52 -0700118 FOR ${INDEX} IN RANGE 0 ${length}
119 ${value}= Get From List ${jsondata} ${INDEX}
120 ${id}= Get From Dictionary ${value} parentid
121 ${sn}= Get From Dictionary ${value} serialnumber
122 Run Keyword If '${sn}' == '${serial_number}' Exit For Loop
123 END
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700124 [Return] ${id}
125
Kailash6f5acb62019-08-28 14:38:45 -0700126Validate Device Removed
127 [Arguments] ${id}
128 [Documentation] Verifys that device, ${serial_number}, has been removed
129 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
130 ${jsondata}= To Json ${output}
131 Log ${jsondata}
132 ${length}= Get Length ${jsondata}
133 @{ids}= Create List
Zack Williamsec53a1b2019-09-16 15:50:52 -0700134 FOR ${INDEX} IN RANGE 0 ${length}
135 ${value}= Get From List ${jsondata} ${INDEX}
136 ${device_id}= Get From Dictionary ${value} id
137 Append To List ${ids} ${device_id}
138 END
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700139 List Should Not Contain Value ${ids} ${id}