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} |
You Wang | 2b55064 | 2019-10-07 14:39:48 -0700 | [diff] [blame] | 31 | [Documentation] Creates a device in VOLTHA |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 32 | #create/preprovision device |
Gilles Depatie | 675a206 | 2019-10-22 12:44:42 -0400 | [diff] [blame] | 33 | ${rc} ${device_id}= Run and Return Rc and Output |
| 34 | ... ${VOLTCTL_CONFIG}; voltctl device create -t openolt -H ${ip}:${port} |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 35 | Should Be Equal As Integers ${rc} 0 |
| 36 | [Return] ${device_id} |
| 37 | |
| 38 | Enable Device |
| 39 | [Arguments] ${device_id} |
Zack Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 40 | [Documentation] Enables a device in VOLTHA |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 41 | ${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 Vemuri | 00d147d | 2019-09-13 13:07:32 -0700 | [diff] [blame] | 44 | Get Device Flows from Voltha |
| 45 | [Arguments] ${device_id} |
Zack Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 46 | [Documentation] Gets device flows from VOLTHA |
Suchitra Vemuri | 00d147d | 2019-09-13 13:07:32 -0700 | [diff] [blame] | 47 | ${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 | |
| 51 | Get Logical Device Output from Voltha |
| 52 | [Arguments] ${device_id} |
Zack Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 53 | [Documentation] Gets logicaldevice flows and ports from VOLTHA |
Suchitra Vemuri | 00d147d | 2019-09-13 13:07:32 -0700 | [diff] [blame] | 54 | ${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 | |
| 61 | Get Device Output from Voltha |
| 62 | [Arguments] ${device_id} |
Zack Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 63 | [Documentation] Gets device flows and ports from VOLTHA |
Suchitra Vemuri | 00d147d | 2019-09-13 13:07:32 -0700 | [diff] [blame] | 64 | ${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 | |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 71 | Validate Device |
Gilles Depatie | 675a206 | 2019-10-22 12:44:42 -0400 | [diff] [blame] | 72 | [Arguments] ${serial_number} ${admin_state} ${oper_status} ${connect_status} ${onu_reasons}=${EMPTY} |
| 73 | ... ${onu}=False |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 74 | [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 Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 80 | 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 |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 89 | 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 Depatie | 675a206 | 2019-10-22 12:44:42 -0400 | [diff] [blame] | 91 | 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 |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 95 | |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 96 | Get 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 Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 103 | 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 |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 109 | [Return] ${id} |
| 110 | |
Suchitra Vemuri | 00d147d | 2019-09-13 13:07:32 -0700 | [diff] [blame] | 111 | Get 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 Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 118 | 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 Vemuri | 00d147d | 2019-09-13 13:07:32 -0700 | [diff] [blame] | 124 | [Return] ${id} |
| 125 | |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 126 | Validate 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 Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 134 | 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 Vemuri | 00d147d | 2019-09-13 13:07:32 -0700 | [diff] [blame] | 139 | List Should Not Contain Value ${ids} ${id} |