Kailash Khalasi | c930eac | 2018-09-05 12:18:23 -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 | *** Settings *** |
Suchitra Vemuri | 6357e69 | 2018-09-07 11:11:47 -0700 | [diff] [blame] | 16 | Documentation Library of functions related to RG (source host) |
Kailash Khalasi | c930eac | 2018-09-05 12:18:23 -0700 | [diff] [blame] | 17 | Library OperatingSystem |
| 18 | Library SSHLibrary |
Suchitra Vemuri | ef98960 | 2018-09-10 13:45:26 -0700 | [diff] [blame] | 19 | Library restApi.py |
You Wang | aee3511 | 2018-09-28 16:07:49 -0700 | [diff] [blame^] | 20 | Resource ../../Framework/utils/utils.robot |
Kailash Khalasi | c930eac | 2018-09-05 12:18:23 -0700 | [diff] [blame] | 21 | |
| 22 | *** Keywords *** |
| 23 | Send EAPOL Message |
| 24 | [Arguments] ${ip} ${user} ${pass} ${iface} ${conf_file} ${prompt}=$ ${prompt_timeout}=60s |
| 25 | [Documentation] SSH's into the RG (src) and executes a particular auth request via wpa_supplicant client. Requested packet should exist on src. |
| 26 | ${conn_id}= SSHLibrary.Open Connection ${ip} prompt=${prompt} timeout=${prompt_timeout} |
Kailash Khalasi | e030eee | 2018-09-10 09:19:46 -0700 | [diff] [blame] | 27 | SSHLibrary.Login ${user} ${pass} |
You Wang | aee3511 | 2018-09-28 16:07:49 -0700 | [diff] [blame^] | 28 | SSHLibrary.Write rm -f wpa.log |
| 29 | SSHLibrary.Write sudo wpa_supplicant -B -i ${iface} -Dwired -c /etc/wpa_supplicant/${conf_file} -f wpa.log |
Kailash Khalasi | c930eac | 2018-09-05 12:18:23 -0700 | [diff] [blame] | 30 | Read Until [sudo] password for ${user}: |
| 31 | SSHLibrary.Write ${pass} |
You Wang | aee3511 | 2018-09-28 16:07:49 -0700 | [diff] [blame^] | 32 | Wait Until Keyword Succeeds 30s 2s Remote File Should Contain ${conn_id} wpa.log authentication completed successfully |
Kailash Khalasi | c930eac | 2018-09-05 12:18:23 -0700 | [diff] [blame] | 33 | SSHLibrary.Close Connection |
Suchitra Vemuri | 6357e69 | 2018-09-07 11:11:47 -0700 | [diff] [blame] | 34 | |
Kailash Khalasi | 6dab16e | 2018-09-17 20:24:08 -0700 | [diff] [blame] | 35 | Delete IP Addresses from Interface on Remote Host |
| 36 | [Arguments] ${ip} ${user} ${pass} ${interface} ${prompt}=$ ${prompt_timeout}=60s |
| 37 | ${conn_id}= SSHLibrary.Open Connection ${ip} prompt=${prompt} timeout=${prompt_timeout} |
| 38 | SSHLibrary.Login ${user} ${pass} |
| 39 | SSHLibrary.Write sudo ip addr flush dev ${interface}; echo $? |
| 40 | Read Until [sudo] password for ${user}: |
| 41 | SSHLibrary.Write ${pass} |
| 42 | ${result}= Read Until ${prompt} |
| 43 | SSHLibrary.Close Connection |
| 44 | |
Suchitra Vemuri | 6357e69 | 2018-09-07 11:11:47 -0700 | [diff] [blame] | 45 | Subscriber Status Check |
| 46 | [Arguments] ${onu_device} |
| 47 | [Documentation] Returns Status from Subscribers List for a particular ONU device |
| 48 | ${json_result}= restApi.ApiGet VOLT_SUBSCRIBER |
| 49 | Log ${json_result} |
| 50 | ${json_result_list}= Get From dictionary ${json_result} items |
Suchitra Vemuri | ef98960 | 2018-09-10 13:45:26 -0700 | [diff] [blame] | 51 | ${getJsonDict}= utils.getDictFromListOfDict ${json_result_list} onu_device ${onu_device} |
Suchitra Vemuri | 32fc2f2 | 2018-09-10 12:06:01 -0700 | [diff] [blame] | 52 | ${status}= Get From Dictionary ${getJsonDict} status |
Suchitra Vemuri | 6357e69 | 2018-09-07 11:11:47 -0700 | [diff] [blame] | 53 | [Return] ${status} |
Kailash Khalasi | 30a6a39 | 2018-09-10 14:32:39 -0700 | [diff] [blame] | 54 | |
| 55 | Create Subscriber |
| 56 | [Arguments] ${subscriber_list} ${list_index} |
| 57 | [Documentation] Sends a POST to create a subscriber in XOS |
| 58 | ${slist} = Get Variable Value ${subscriber_list} |
| 59 | ${subscriber_dictionary}= utils.listToDict ${slist} ${list_index} |
| 60 | ${api_result}= restApi.ApiPost VOLT_SUBSCRIBER ${subscriber_dictionary} |
| 61 | Should Be True ${api_result} |
| 62 | ${Subscriber_id}= Get From Dictionary ${api_result} id |
| 63 | Set Global Variable ${Subscriber_id} |
| 64 | [Return] ${Subscriber_id} |
| 65 | |
| 66 | Retrieve Subscriber |
| 67 | [Arguments] ${ctag} |
| 68 | [Documentation] Returns the subscriber id based on the subscriber's C-Tag |
| 69 | ${json_result}= restApi.ApiGet VOLT_SUBSCRIBER |
| 70 | Log ${json_result} |
| 71 | ${json_result_list}= Get From dictionary ${json_result} items |
| 72 | ${getJsonDict}= utils.getDictFromListOfDict ${json_result_list} c_tag ${ctag} |
| 73 | ${id}= Get From Dictionary ${getJsonDict} id |
| 74 | [Return] ${id} |
| 75 | |
| 76 | Delete Subscriber |
| 77 | [Arguments] ${ctag} |
| 78 | [Documentation] Deletes a given subscriber based on its c_tag |
| 79 | ${id}= Retrieve Subscriber ${ctag} |
| 80 | ${api_result}= restApi.ApiChameleonDelete VOLT_SUBSCRIBER ${id} |
| 81 | Should Be True ${api_result} |
Kailash Khalasi | 052cbb1 | 2018-09-13 16:50:13 -0700 | [diff] [blame] | 82 | |
Kailash Khalasi | 6dab16e | 2018-09-17 20:24:08 -0700 | [diff] [blame] | 83 | Add Double Vlan Interface on Host |
| 84 | [Arguments] ${ip} ${user} ${pass} ${interface} ${stag} ${ctag} ${prompt}=$ ${prompt_timeout}=60s |
Kailash Khalasi | 052cbb1 | 2018-09-13 16:50:13 -0700 | [diff] [blame] | 85 | ${conn_id}= SSHLibrary.Open Connection ${ip} prompt=${prompt} timeout=${prompt_timeout} |
| 86 | SSHLibrary.Login ${user} ${pass} |
Kailash Khalasi | 6dab16e | 2018-09-17 20:24:08 -0700 | [diff] [blame] | 87 | SSHLibrary.Write sudo ip link add link ${interface} name ${interface}.${stag} type vlan id ${stag} |
| 88 | Read Until [sudo] password for ${user}: |
| 89 | SSHLibrary.Write ${pass} |
| 90 | SSHLibrary.Write sudo ip link set ${interface}.${stag} up |
| 91 | ${result}= Read Until ${prompt} |
| 92 | SSHLibrary.Write sudo ip link add link ${interface}.${stag} name ${interface}.${stag}.${ctag} type vlan id ${ctag} |
| 93 | ${result}= Read Until ${prompt} |
| 94 | SSHLibrary.Write sudo ip link set ${interface}.${stag}.${ctag} up |
| 95 | ${result}= Read Until ${prompt} |
| 96 | SSHLibrary.Write ifconfig ${interface}.${stag}.${ctag} |
| 97 | ${result}= Read Until ${prompt} |
| 98 | SSHLibrary.Close Connection |
| 99 | |
| 100 | Delete Interface on Remote Host |
| 101 | [Arguments] ${ip} ${user} ${pass} ${interface} ${prompt}=$ ${prompt_timeout}=60s |
| 102 | ${conn_id}= SSHLibrary.Open Connection ${ip} prompt=${prompt} timeout=${prompt_timeout} |
| 103 | SSHLibrary.Login ${user} ${pass} |
| 104 | SSHLibrary.Write sudo ip link del ${interface} |
| 105 | Read Until [sudo] password for ${user}: |
| 106 | SSHLibrary.Write ${pass} |
| 107 | Read Until ${prompt} |
| 108 | SSHLibrary.Close Connection |
| 109 | |
| 110 | Add Ip Address on Interface on Host |
| 111 | [Arguments] ${ip} ${user} ${pass} ${ip_address} ${interface} ${prompt}=$ ${prompt_timeout}=60s |
| 112 | ${conn_id}= SSHLibrary.Open Connection ${ip} prompt=${prompt} timeout=${prompt_timeout} |
| 113 | SSHLibrary.Login ${user} ${pass} |
| 114 | SSHLibrary.Write sudo ip addr add ${ip_address} dev ${interface} |
| 115 | Read Until [sudo] password for ${user}: |
| 116 | SSHLibrary.Write ${pass} |
| 117 | Read Until ${prompt} |
| 118 | SSHLibrary.Close Connection |
| 119 | |
| 120 | Start DHCP Server on Remote Host |
| 121 | [Arguments] ${ip} ${user} ${pass} ${interface} ${prompt}=$ ${prompt_timeout}=60s |
| 122 | ${conn_id}= SSHLibrary.Open Connection ${ip} prompt=${prompt} timeout=${prompt_timeout} |
| 123 | SSHLibrary.Login ${user} ${pass} |
| 124 | SSHLibrary.Write sudo dhcpd -cf /etc/dhcp/dhcpd.conf ${interface} |
Kailash Khalasi | 052cbb1 | 2018-09-13 16:50:13 -0700 | [diff] [blame] | 125 | Read Until [sudo] password for ${user}: |
| 126 | SSHLibrary.Write ${pass} |
| 127 | ${result}= Read Until ${prompt} |
Kailash Khalasi | 6dab16e | 2018-09-17 20:24:08 -0700 | [diff] [blame] | 128 | Should Contain ${result} Listening on LPF/${interface} |
Kailash Khalasi | 052cbb1 | 2018-09-13 16:50:13 -0700 | [diff] [blame] | 129 | SSHLibrary.Close Connection |
Kailash Khalasi | 6dab16e | 2018-09-17 20:24:08 -0700 | [diff] [blame] | 130 | |
| 131 | Add Route to Remote Host |
| 132 | [Arguments] ${ip} ${user} ${pass} ${subnet} ${gateway} ${interface} ${prompt}=$ ${prompt_timeout}=60s |
| 133 | ${conn_id}= SSHLibrary.Open Connection ${ip} prompt=${prompt} timeout=${prompt_timeout} |
| 134 | SSHLibrary.Login ${user} ${pass} |
| 135 | SSHLibrary.Write sudo ip route add ${subnet} via ${gateway} dev ${interface} |
| 136 | Read Until [sudo] password for ${user}: |
| 137 | SSHLibrary.Write ${pass} |
| 138 | ${result}= Read Until ${prompt} |
You Wang | aee3511 | 2018-09-28 16:07:49 -0700 | [diff] [blame^] | 139 | SSHLibrary.Close Connection |