blob: adca1fe0ae5fa3097d585d1dd47444db1e603639 [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
43Validate Device
Kailash2b963f02019-08-28 22:46:33 -070044 [Arguments] ${serial_number} ${admin_state} ${oper_status} ${connect_status} ${onu_reason}=${EMPTY} ${onu}=False
Kailash6f5acb62019-08-28 14:38:45 -070045 [Documentation] Parses the output of "voltctl device list" and inspects device ${serial_number}
46 ... Arguments are matched for device states of: "admin_state", "oper_status", and "connect_status"
47 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
48 ${jsondata}= To Json ${output}
49 Log ${jsondata}
50 ${length}= Get Length ${jsondata}
51 : FOR ${INDEX} IN RANGE 0 ${length}
52 \ ${value}= Get From List ${jsondata} ${INDEX}
53 \ ${astate}= Get From Dictionary ${value} adminstate
54 \ ${opstatus}= Get From Dictionary ${value} operstatus
55 \ ${cstatus}= Get From Dictionary ${value} connectstatus
56 \ ${sn}= Get From Dictionary ${value} serialnumber
57 \ ${mib_state}= Get From Dictionary ${value} reason
58 \ Run Keyword If '${sn}' == '${serial_number}' Exit For Loop
59 Should Be Equal ${astate} ${admin_state} Device ${serial_number} admin_state != ENABLED values=False
60 Should Be Equal ${opstatus} ${oper_status} Device ${serial_number} oper_status != ACTIVE values=False
61 Should Be Equal ${cstatus} ${connect_status} Device ${serial_number} connect_status != REACHABLE values=False
62 Run Keyword If '${onu}' == 'True' Should Be Equal ${mib_state} ${onu_reason} Device ${serial_number} mib_state incorrect values=False
63
64
65Get Device ID From SN
66 [Arguments] ${serial_number}
67 [Documentation] Gets the device id by matching for ${serial_number}
68 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
69 ${jsondata}= To Json ${output}
70 Log ${jsondata}
71 ${length}= Get Length ${jsondata}
72 : FOR ${INDEX} IN RANGE 0 ${length}
73 \ ${value}= Get From List ${jsondata} ${INDEX}
74 \ ${id}= Get From Dictionary ${value} id
75 \ ${sn}= Get From Dictionary ${value} serialnumber
76 \ Run Keyword If '${sn}' == '${serial_number}' Exit For Loop
77 [Return] ${id}
78
79Validate Device Removed
80 [Arguments] ${id}
81 [Documentation] Verifys that device, ${serial_number}, has been removed
82 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
83 ${jsondata}= To Json ${output}
84 Log ${jsondata}
85 ${length}= Get Length ${jsondata}
86 @{ids}= Create List
87 : FOR ${INDEX} IN RANGE 0 ${length}
88 \ ${value}= Get From List ${jsondata} ${INDEX}
89 \ ${device_id}= Get From Dictionary ${value} id
90 \ Append To List ${ids} ${device_id}
91 List Should Not Contain Value ${ids} ${id}