blob: feb1cbb9a5aa33d16dd87aeec6f6200e6a899882 [file] [log] [blame]
Zack Williams821c5022020-01-15 15:11:46 -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*** Settings ***
16Documentation Library for DHCP server and client functions
17Library OperatingSystem
18Resource utils.resource
19
20*** Keywords ***
21Send Dhclient Request
22 [Documentation] Executes a dhclient against a particular interface on the RG (src)
23 [Arguments] ${iface} ${ip} ${user} ${pass}=${None}
24 ... ${container_type}=${None} ${container_name}=${None}
25 ${result}= Login And Run Command On Remote System
26 ... dhclient -nw ${iface}
27 ... ${ip} ${user} ${pass} ${container_type} ${container_name}
28 [Return] ${result}
29
30Send Dhclient Request K8S
31 [Documentation] Run dhclient inside rg container in K8s
32 ${RG_CONTAINER}= Wait Until Keyword Succeeds 60s 1s
33 ... Run kubectl -n voltha get pod|grep "^rg[0-]"|cut -d' ' -f1
34 Run kubectl -n voltha exec ${RG_CONTAINER} -- sed -i 's/timeout 300;/timeout 30;/' /etc/dhcp/dhclient.conf
35 Run kubectl -n voltha exec ${RG_CONTAINER} -- ifconfig eth0 0.0.0.0
36 Run kubectl -n voltha exec ${RG_CONTAINER} -- dhclient
37
38Add Default Route to Dst Gateway
39 [Documentation] Adds an entry to the routing table on the RG (src)
40 # FIXME - Argument order of iface/ip/user/pass should match other functions
41 [Arguments] ${src_gateway} ${dst_subnet} ${iface} ${ip}
42 ... ${user} ${pass}=${None} ${container_type}=${None} ${container_name}=${None}
43 ${result}= Login And Run Command On Remote System
44 ... ip route add ${dst_subnet} via ${src_gateway} dev ${iface}
45 ... ${ip} ${user} ${pass} ${container_type} ${container_name}
46 [Return] ${result}
47
48Check IPv4 Address on DHCP Client
49 [Documentation] Check if the sepcified interface has an IPv4 address assigned
50 # FIXME - should ip_should_exist have a default value?
51 [Arguments] ${ip_should_exist} ${iface} ${ip} ${user} ${pass}=${None}
52 ... ${container_type}=${None} ${container_name}=${None}
53 ${output}= Login And Run Command On Remote System
54 ... ip address show ${iface}
55 ... ${ip} ${user} ${pass} ${container_type} ${container_name}
56 # FIXME - ipv4_regex not set if container_type != K8S?
57 ${ipv4_regex}= Set Variable If '${container_type}' != 'K8S'
58 ... \\b([0-9]{1,3}\\.){3}[0-9]{1,3}\\b \\b(172)\\.(18)(\\.([0-9]{1,3})){2}\\b
59 # FIXME - use a boolean rather than string comparison against truthy value
60 Run Keyword If '${ip_should_exist}' == 'True' Should Match Regexp
61 ... ${output} ${ipv4_regex}
62 Run Keyword If '${ip_should_exist}' == 'False' Should Not Match Regexp
63 ... ${output} ${ipv4_regex}
64
65Start DHCP Server on Remote Host
66 [Documentation] Start the 'dhcpd' process on specified network interface
67 ... on a remote host
68 [Arguments] ${interface} ${ip} ${user} ${pass}=${None}
69 ... ${container_type}=${None} ${container_name}=${None}
70 ${result}= Login And Run Command On Remote System
71 ... dhcpd -cf /etc/dhcp/dhcpd.conf ${interface}
72 ... ${ip} ${user} ${pass} ${container_type} ${container_name}