Kailash | 9276492 | 2019-07-25 08:21:39 -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 | # robot test 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 | Execute ONOS Command |
| 30 | [Arguments] ${cmd} |
| 31 | [Documentation] Establishes an ssh connection to the onos contoller and executes a command |
| 32 | ${conn_id}= SSHLibrary.Open Connection localhost port=8101 prompt=onos> timeout=300s |
| 33 | SSHLibrary.Login karaf karaf |
| 34 | ${output}= SSHLibrary.Execute Command ${cmd} |
| 35 | SSHLibrary.Close Connection |
| 36 | [Return] ${output} |
| 37 | |
| 38 | Validate Device |
| 39 | [Arguments] ${serial_number} ${admin_state} ${oper_status} ${connect_status} |
| 40 | [Documentation] Parses the output of "voltctl device list" and inspects device ${serial_number} |
| 41 | ... Arguments are matched for device states of: "admin_state", "oper_status", and "connect_status" |
Kailash | ce30501 | 2019-08-05 13:15:52 -0700 | [diff] [blame] | 42 | ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json |
Kailash | 9276492 | 2019-07-25 08:21:39 -0700 | [diff] [blame] | 43 | ${jsondata}= To Json ${output} |
| 44 | Log ${jsondata} |
| 45 | ${length}= Get Length ${jsondata} |
| 46 | : FOR ${INDEX} IN RANGE 0 ${length} |
| 47 | \ ${value}= Get From List ${jsondata} ${INDEX} |
| 48 | \ ${astate}= Get From Dictionary ${value} adminstate |
| 49 | \ ${opstatus}= Get From Dictionary ${value} operstatus |
| 50 | \ ${cstatus}= Get From Dictionary ${value} connectstatus |
| 51 | \ ${sn}= Get From Dictionary ${value} serialnumber |
| 52 | \ Run Keyword If '${sn}' == '${serial_number}' Exit For Loop |
| 53 | Should Be Equal ${astate} ${admin_state} Device ${serial_number} admin_state != ENABLED values=False |
| 54 | Should Be Equal ${opstatus} ${oper_status} Device ${serial_number} oper_status != ACTIVE values=False |
Kailash | 528f7c0 | 2019-07-31 10:55:49 -0700 | [diff] [blame] | 55 | Should Be Equal ${cstatus} ${connect_status} Device ${serial_number} connect_status != REACHABLE values=False |
| 56 | |
Kailash | ce30501 | 2019-08-05 13:15:52 -0700 | [diff] [blame] | 57 | Get Device ID From SN |
| 58 | [Arguments] ${serial_number} |
| 59 | [Documentation] Gets the device id by matching for ${serial_number} |
| 60 | ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json |
| 61 | ${jsondata}= To Json ${output} |
| 62 | Log ${jsondata} |
| 63 | ${length}= Get Length ${jsondata} |
| 64 | : FOR ${INDEX} IN RANGE 0 ${length} |
| 65 | \ ${value}= Get From List ${jsondata} ${INDEX} |
| 66 | \ ${id}= Get From Dictionary ${value} id |
| 67 | \ ${sn}= Get From Dictionary ${value} serialnumber |
| 68 | \ Run Keyword If '${sn}' == '${serial_number}' Exit For Loop |
| 69 | [Return] ${id} |
| 70 | |
| 71 | Validate Device Removed |
| 72 | [Arguments] ${id} |
| 73 | [Documentation] Verifys that device, ${serial_number}, has been removed |
| 74 | ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json |
| 75 | ${jsondata}= To Json ${output} |
| 76 | Log ${jsondata} |
| 77 | ${length}= Get Length ${jsondata} |
| 78 | @{ids}= Create List |
| 79 | : FOR ${INDEX} IN RANGE 0 ${length} |
| 80 | \ ${value}= Get From List ${jsondata} ${INDEX} |
| 81 | \ ${device_id}= Get From Dictionary ${value} id |
| 82 | \ Append To List ${ids} ${device_id} |
| 83 | List Should Not Contain Value ${ids} ${id} |
| 84 | |
Kailash | 528f7c0 | 2019-07-31 10:55:49 -0700 | [diff] [blame] | 85 | Check CLI Tools Configured |
| 86 | [Documentation] Tests that use 'voltctl' and 'kubectl' should execute this keyword in suite setup |
| 87 | # check voltctl and kubectl configured |
Kailash | 1a871bf | 2019-08-05 14:20:02 -0700 | [diff] [blame] | 88 | ${voltctl_rc}= Run And Return RC ${VOLTCTL_CONFIG}; voltctl device list |
| 89 | ${kubectl_rc}= Run And Return RC ${KUBECTL_CONFIG}; kubectl get pods |
Kailash | ba41528 | 2019-08-05 11:47:27 -0700 | [diff] [blame] | 90 | Run Keyword If ${voltctl_rc} != 0 or ${kubectl_rc} != 0 FATAL ERROR |
| 91 | ... VOLTCTL and KUBECTL not configured. Please configure before executing tests. |