blob: d7dc48a385ad1cb82d82dee639b5cd0366f75fa2 [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
33 ${rc} ${device_id}= Run and Return Rc and Output
34 ... ${VOLTCTL_CONFIG}; voltctl device create -t openolt -H ${ip}:${port}
35 Should Be Equal As Integers ${rc} 0
36 [Return] ${device_id}
37
38Enable Device
39 [Arguments] ${device_id}
40 ${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}
45 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device flows ${device_id}
46 Should Be Equal As Integers ${rc} 0
47 [Return] ${output}
48
49Get Logical Device Output from Voltha
50 [Arguments] ${device_id}
51 ${rc1} ${flows}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl logicaldevice flows ${device_id}
52 ${rc2} ${ports}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl logicaldevice ports ${device_id}
53 Log ${flows}
54 Log ${ports}
55 Should Be Equal As Integers ${rc1} 0
56 Should Be Equal As Integers ${rc2} 0
57
58Get Device Output from Voltha
59 [Arguments] ${device_id}
60 ${rc1} ${flows}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device flows ${device_id}
61 ${rc2} ${ports}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device ports ${device_id}
62 Log ${flows}
63 Log ${ports}
64 Should Be Equal As Integers ${rc1} 0
65 Should Be Equal As Integers ${rc2} 0
66
Kailash6f5acb62019-08-28 14:38:45 -070067Validate Device
Kailash2b963f02019-08-28 22:46:33 -070068 [Arguments] ${serial_number} ${admin_state} ${oper_status} ${connect_status} ${onu_reason}=${EMPTY} ${onu}=False
Kailash6f5acb62019-08-28 14:38:45 -070069 [Documentation] Parses the output of "voltctl device list" and inspects device ${serial_number}
70 ... Arguments are matched for device states of: "admin_state", "oper_status", and "connect_status"
71 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
72 ${jsondata}= To Json ${output}
73 Log ${jsondata}
74 ${length}= Get Length ${jsondata}
75 : FOR ${INDEX} IN RANGE 0 ${length}
76 \ ${value}= Get From List ${jsondata} ${INDEX}
77 \ ${astate}= Get From Dictionary ${value} adminstate
78 \ ${opstatus}= Get From Dictionary ${value} operstatus
79 \ ${cstatus}= Get From Dictionary ${value} connectstatus
80 \ ${sn}= Get From Dictionary ${value} serialnumber
81 \ ${mib_state}= Get From Dictionary ${value} reason
82 \ Run Keyword If '${sn}' == '${serial_number}' Exit For Loop
83 Should Be Equal ${astate} ${admin_state} Device ${serial_number} admin_state != ENABLED values=False
84 Should Be Equal ${opstatus} ${oper_status} Device ${serial_number} oper_status != ACTIVE values=False
85 Should Be Equal ${cstatus} ${connect_status} Device ${serial_number} connect_status != REACHABLE values=False
86 Run Keyword If '${onu}' == 'True' Should Be Equal ${mib_state} ${onu_reason} Device ${serial_number} mib_state incorrect values=False
87
88
89Get Device ID From SN
90 [Arguments] ${serial_number}
91 [Documentation] Gets the device id by matching for ${serial_number}
92 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
93 ${jsondata}= To Json ${output}
94 Log ${jsondata}
95 ${length}= Get Length ${jsondata}
96 : FOR ${INDEX} IN RANGE 0 ${length}
97 \ ${value}= Get From List ${jsondata} ${INDEX}
98 \ ${id}= Get From Dictionary ${value} id
99 \ ${sn}= Get From Dictionary ${value} serialnumber
100 \ Run Keyword If '${sn}' == '${serial_number}' Exit For Loop
101 [Return] ${id}
102
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700103Get Logical Device ID From SN
104 [Arguments] ${serial_number}
105 [Documentation] Gets the device id by matching for ${serial_number}
106 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
107 ${jsondata}= To Json ${output}
108 Log ${jsondata}
109 ${length}= Get Length ${jsondata}
110 : FOR ${INDEX} IN RANGE 0 ${length}
111 \ ${value}= Get From List ${jsondata} ${INDEX}
112 \ ${id}= Get From Dictionary ${value} parentid
113 \ ${sn}= Get From Dictionary ${value} serialnumber
114 \ Run Keyword If '${sn}' == '${serial_number}' Exit For Loop
115 [Return] ${id}
116
Kailash6f5acb62019-08-28 14:38:45 -0700117Validate Device Removed
118 [Arguments] ${id}
119 [Documentation] Verifys that device, ${serial_number}, has been removed
120 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
121 ${jsondata}= To Json ${output}
122 Log ${jsondata}
123 ${length}= Get Length ${jsondata}
124 @{ids}= Create List
125 : FOR ${INDEX} IN RANGE 0 ${length}
126 \ ${value}= Get From List ${jsondata} ${INDEX}
127 \ ${device_id}= Get From Dictionary ${value} id
128 \ Append To List ${ids} ${device_id}
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700129 List Should Not Contain Value ${ids} ${id}