blob: 7b9768bdc8dd0d480282c029b2cc1e67969a206d [file] [log] [blame]
Kailash92764922019-07-25 08:21:39 -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# robot test 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 ***
29Execute 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
38Validate 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"
Kailashce305012019-08-05 13:15:52 -070042 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
Kailash92764922019-07-25 08:21:39 -070043 ${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
Kailash528f7c02019-07-31 10:55:49 -070055 Should Be Equal ${cstatus} ${connect_status} Device ${serial_number} connect_status != REACHABLE values=False
56
Kailashce305012019-08-05 13:15:52 -070057Get 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
71Validate 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
Kailash528f7c02019-07-31 10:55:49 -070085Check CLI Tools Configured
86 [Documentation] Tests that use 'voltctl' and 'kubectl' should execute this keyword in suite setup
87 # check voltctl and kubectl configured
Kailash1a871bf2019-08-05 14:20:02 -070088 ${voltctl_rc}= Run And Return RC ${VOLTCTL_CONFIG}; voltctl device list
89 ${kubectl_rc}= Run And Return RC ${KUBECTL_CONFIG}; kubectl get pods
Kailashba415282019-08-05 11:47:27 -070090 Run Keyword If ${voltctl_rc} != 0 or ${kubectl_rc} != 0 FATAL ERROR
91 ... VOLTCTL and KUBECTL not configured. Please configure before executing tests.