Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 1 | # 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 *** |
| 18 | Documentation Library for various utilities |
| 19 | Library SSHLibrary |
| 20 | Library HttpLibrary.HTTP |
| 21 | Library String |
| 22 | Library DateTime |
| 23 | Library Process |
| 24 | Library Collections |
| 25 | Library RequestsLibrary |
| 26 | Library OperatingSystem |
| 27 | |
| 28 | *** Keywords *** |
| 29 | Create Device |
| 30 | [Arguments] ${ip} ${port} |
| 31 | [Documentation] Parses the output of "voltctl device list" and inspects device ${serial_number} |
| 32 | #create/preprovision device |
Zack Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 33 | ${rc} ${device_id}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device create -t openolt -H ${ip}:${port} |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 34 | Should Be Equal As Integers ${rc} 0 |
| 35 | [Return] ${device_id} |
| 36 | |
| 37 | Enable Device |
| 38 | [Arguments] ${device_id} |
Zack Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 39 | [Documentation] Enables a device in VOLTHA |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 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 Vemuri | 00d147d | 2019-09-13 13:07:32 -0700 | [diff] [blame] | 43 | Get Device Flows from Voltha |
| 44 | [Arguments] ${device_id} |
Zack Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 45 | [Documentation] Gets device flows from VOLTHA |
Suchitra Vemuri | 00d147d | 2019-09-13 13:07:32 -0700 | [diff] [blame] | 46 | ${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 | |
| 50 | Get Logical Device Output from Voltha |
| 51 | [Arguments] ${device_id} |
Zack Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 52 | [Documentation] Gets logicaldevice flows and ports from VOLTHA |
Suchitra Vemuri | 00d147d | 2019-09-13 13:07:32 -0700 | [diff] [blame] | 53 | ${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 | |
| 60 | Get Device Output from Voltha |
| 61 | [Arguments] ${device_id} |
Zack Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 62 | [Documentation] Gets device flows and ports from VOLTHA |
Suchitra Vemuri | 00d147d | 2019-09-13 13:07:32 -0700 | [diff] [blame] | 63 | ${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 | |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 70 | Validate Device |
Kailash | 2b963f0 | 2019-08-28 22:46:33 -0700 | [diff] [blame] | 71 | [Arguments] ${serial_number} ${admin_state} ${oper_status} ${connect_status} ${onu_reason}=${EMPTY} ${onu}=False |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 72 | [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 Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 78 | 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 |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 87 | 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 |
| 90 | Run Keyword If '${onu}' == 'True' Should Be Equal ${mib_state} ${onu_reason} Device ${serial_number} mib_state incorrect values=False |
| 91 | |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 92 | Get 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 Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 99 | 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 |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 105 | [Return] ${id} |
| 106 | |
Suchitra Vemuri | 00d147d | 2019-09-13 13:07:32 -0700 | [diff] [blame] | 107 | Get 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 Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 114 | 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 Vemuri | 00d147d | 2019-09-13 13:07:32 -0700 | [diff] [blame] | 120 | [Return] ${id} |
| 121 | |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 122 | Validate 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 Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 130 | 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 Vemuri | 00d147d | 2019-09-13 13:07:32 -0700 | [diff] [blame] | 135 | List Should Not Contain Value ${ids} ${id} |