1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
| | #! /usr/bin/python3
# SPDX-License-Identifier: GPL-2.0-or-later
#
# avocado/pasta_dhcp.py - Test DHCP & DHCPv6 with pasta
#
# Copyright Red Hat
# Author: David Gibson <david@gibson.dropbear.id.au>
import ipaddress
import json
import common
from pasta import PastaUnconfiguredTest
class PastaDhcpTest(PastaUnconfiguredTest):
DHCLIENT = '/sbin/dhclient'
def setUp(self):
super().setUp()
# Allow namespaced dhclient to write lease & pid files
self.innerx('mount -t tmpfs none /var/lib/dhclient', sudo=True)
self.innerx('mount -t tmpfs none /var/run', sudo=True)
# We need '-nc' because we're running with capabilities but
# not UID 0. Without -nc dhclient drops capabilities before
# invoking dhclient-script, so it's unable to actually
# configure the interface
self.innerx('{} -4 -v -nc {}'.format(self.DHCLIENT,
self.IFNAME), sudo=True)
def test_addr(self):
ifinfo = self.innerx('ip -4 -j addr show {}'.format(self.IFNAME))
ifinfo = json.loads(ifinfo)[0]
self.assertEquals(len(ifinfo['addr_info']), 1)
adinfo = ifinfo['addr_info'][0]
addr = ipaddress.ip_address(adinfo['local'])
self.assertEquals(addr, self.OUTER_IP4)
self.shutdown()
def test_route(self):
rinfo = self.innerx('ip -j -4 route show')
rinfo = json.loads(rinfo)
for route in rinfo:
if route['dst'] != 'default':
continue
gateway = ipaddress.ip_address(route['gateway'])
self.assertEquals(gateway, self.GW_IP4)
self.shutdown()
def test_mtu(self):
ifinfo = self.innerx('ip -j link show {}'.format(self.IFNAME))
ifinfo = json.loads(ifinfo)[0]
self.assertEquals(ifinfo['mtu'], 65520)
self.shutdown()
class PastaDhcpv6Test(PastaUnconfiguredTest):
DHCLIENT = '/sbin/dhclient'
timeout = 10.0
def setUp(self):
super().setUp()
# Allow namespaced dhclient to write lease & pid files
self.innerx('mount -t tmpfs none /var/lib/dhclient', sudo=True)
self.innerx('mount -t tmpfs none /var/run', sudo=True)
# We need '-nc' because we're running with capabilities but
# not UID 0. Without -nc dhclient drops capabilities before
# invoking dhclient-script, so it's unable to actually
# configure the interface
self.innerx('{} -6 -nc -v {}'.format(self.DHCLIENT,
self.IFNAME), sudo=True)
def test_addr(self):
ifinfo = self.innerx('ip -6 -j addr show {}'.format(self.IFNAME))
ifinfo = json.loads(ifinfo)[0]
for adinfo in ifinfo['addr_info']:
if adinfo['scope'] == 'global' and not 'dynamic' in adinfo:
global_addr = ipaddress.ip_address(adinfo['local'])
self.assertEquals(global_addr, self.OUTER_IP6)
self.shutdown()
def test_route(self):
rinfo = self.innerx('ip -j -6 route show')
rinfo = json.loads(rinfo)
for route in rinfo:
if route['dst'] != 'default':
continue
gateway = ipaddress.ip_address(route['gateway'])
self.assertEquals(gateway, self.gw_ll)
self.shutdown()
|