blob: 1396285a1956594c8c892137ea26e0ea7f6b0fa2 [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}
31 [Documentation] Parses the output of "voltctl device list" and inspects device ${serial_number}
32 #create/preprovision device
Zack Williamsec53a1b2019-09-16 15:50:52 -070033 ${rc} ${device_id}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device create -t openolt -H ${ip}:${port}
Kailash6f5acb62019-08-28 14:38:45 -070034 Should Be Equal As Integers ${rc} 0
35 [Return] ${device_id}
36
37Enable Device
38 [Arguments] ${device_id}
Zack Williamsec53a1b2019-09-16 15:50:52 -070039 [Documentation] Enables a device in VOLTHA
Kailash6f5acb62019-08-28 14:38:45 -070040 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device enable ${device_id}
41 Should Be Equal As Integers ${rc} 0
42
Suchitra Vemuri00d147d2019-09-13 13:07:32 -070043Get Device Flows from Voltha
44 [Arguments] ${device_id}
Zack Williamsec53a1b2019-09-16 15:50:52 -070045 [Documentation] Gets device flows from VOLTHA
Suchitra Vemuri00d147d2019-09-13 13:07:32 -070046 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device flows ${device_id}
47 Should Be Equal As Integers ${rc} 0
48 [Return] ${output}
49
50Get Logical Device Output from Voltha
51 [Arguments] ${device_id}
Zack Williamsec53a1b2019-09-16 15:50:52 -070052 [Documentation] Gets logicaldevice flows and ports from VOLTHA
Suchitra Vemuri00d147d2019-09-13 13:07:32 -070053 ${rc1} ${flows}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl logicaldevice flows ${device_id}
54 ${rc2} ${ports}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl logicaldevice ports ${device_id}
55 Log ${flows}
56 Log ${ports}
57 Should Be Equal As Integers ${rc1} 0
58 Should Be Equal As Integers ${rc2} 0
59
60Get Device Output from Voltha
61 [Arguments] ${device_id}
Zack Williamsec53a1b2019-09-16 15:50:52 -070062 [Documentation] Gets device flows and ports from VOLTHA
Suchitra Vemuri00d147d2019-09-13 13:07:32 -070063 ${rc1} ${flows}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device flows ${device_id}
64 ${rc2} ${ports}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device ports ${device_id}
65 Log ${flows}
66 Log ${ports}
67 Should Be Equal As Integers ${rc1} 0
68 Should Be Equal As Integers ${rc2} 0
69
Kailash6f5acb62019-08-28 14:38:45 -070070Validate Device
Andy Bavier5adde022019-10-22 13:33:02 -070071 [Arguments] ${serial_number} ${admin_state} ${oper_status} ${connect_status} ${onu_reasons}=${EMPTY} ${onu}=False
Kailash6f5acb62019-08-28 14:38:45 -070072 [Documentation] Parses the output of "voltctl device list" and inspects device ${serial_number}
73 ... Arguments are matched for device states of: "admin_state", "oper_status", and "connect_status"
74 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
75 ${jsondata}= To Json ${output}
76 Log ${jsondata}
77 ${length}= Get Length ${jsondata}
Zack Williamsec53a1b2019-09-16 15:50:52 -070078 FOR ${INDEX} IN RANGE 0 ${length}
79 ${value}= Get From List ${jsondata} ${INDEX}
80 ${astate}= Get From Dictionary ${value} adminstate
81 ${opstatus}= Get From Dictionary ${value} operstatus
82 ${cstatus}= Get From Dictionary ${value} connectstatus
83 ${sn}= Get From Dictionary ${value} serialnumber
84 ${mib_state}= Get From Dictionary ${value} reason
85 Run Keyword If '${sn}' == '${serial_number}' Exit For Loop
86 END
Kailash6f5acb62019-08-28 14:38:45 -070087 Should Be Equal ${astate} ${admin_state} Device ${serial_number} admin_state != ENABLED values=False
88 Should Be Equal ${opstatus} ${oper_status} Device ${serial_number} oper_status != ACTIVE values=False
89 Should Be Equal ${cstatus} ${connect_status} Device ${serial_number} connect_status != REACHABLE values=False
Andy Bavier5adde022019-10-22 13:33:02 -070090 Run Keyword If '${onu}' == 'True' Should Contain ${onu_reasons} ${mib_state} Device ${serial_number} mib_state incorrect values=False
Kailash6f5acb62019-08-28 14:38:45 -070091
Kailash6f5acb62019-08-28 14:38:45 -070092Get Device ID From SN
93 [Arguments] ${serial_number}
94 [Documentation] Gets the device id by matching for ${serial_number}
95 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
96 ${jsondata}= To Json ${output}
97 Log ${jsondata}
98 ${length}= Get Length ${jsondata}
Zack Williamsec53a1b2019-09-16 15:50:52 -070099 FOR ${INDEX} IN RANGE 0 ${length}
100 ${value}= Get From List ${jsondata} ${INDEX}
101 ${id}= Get From Dictionary ${value} id
102 ${sn}= Get From Dictionary ${value} serialnumber
103 Run Keyword If '${sn}' == '${serial_number}' Exit For Loop
104 END
Kailash6f5acb62019-08-28 14:38:45 -0700105 [Return] ${id}
106
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700107Get Logical Device ID From SN
108 [Arguments] ${serial_number}
109 [Documentation] Gets the device id by matching for ${serial_number}
110 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
111 ${jsondata}= To Json ${output}
112 Log ${jsondata}
113 ${length}= Get Length ${jsondata}
Zack Williamsec53a1b2019-09-16 15:50:52 -0700114 FOR ${INDEX} IN RANGE 0 ${length}
115 ${value}= Get From List ${jsondata} ${INDEX}
116 ${id}= Get From Dictionary ${value} parentid
117 ${sn}= Get From Dictionary ${value} serialnumber
118 Run Keyword If '${sn}' == '${serial_number}' Exit For Loop
119 END
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700120 [Return] ${id}
121
Kailash6f5acb62019-08-28 14:38:45 -0700122Validate Device Removed
123 [Arguments] ${id}
124 [Documentation] Verifys that device, ${serial_number}, has been removed
125 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
126 ${jsondata}= To Json ${output}
127 Log ${jsondata}
128 ${length}= Get Length ${jsondata}
129 @{ids}= Create List
Zack Williamsec53a1b2019-09-16 15:50:52 -0700130 FOR ${INDEX} IN RANGE 0 ${length}
131 ${value}= Get From List ${jsondata} ${INDEX}
132 ${device_id}= Get From Dictionary ${value} id
133 Append To List ${ids} ${device_id}
134 END
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700135 List Should Not Contain Value ${ids} ${id}