diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-02-09 13:14:16 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-02-09 15:49:12 +0100 |
commit | b412fce830c7c179728a80985ff73e8affaceb63 (patch) | |
tree | 36bbf984fcae107b1c795dba962a9cd29eff0bea | |
parent | Merge pull request #11647 from thom311/hashmap-avoid-compiler-warning (diff) | |
download | systemd-b412fce830c7c179728a80985ff73e8affaceb63.tar.xz systemd-b412fce830c7c179728a80985ff73e8affaceb63.zip |
test-network: use dnsmasq with --dhcp-alternate-port option to test DHCP.ListenPort=
Fixes #11675.
-rwxr-xr-x | test/test-network/systemd-networkd-tests.py | 47 |
1 files changed, 7 insertions, 40 deletions
diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index 29bd08906c..06de54e356 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -9,7 +9,6 @@ import signal import socket import subprocess import sys -import threading import time import unittest from shutil import copytree @@ -132,8 +131,9 @@ class Utilities(): if (os.path.exists(os.path.join(network_unit_file_path, unit + '.d'))): shutil.rmtree(os.path.join(network_unit_file_path, unit + '.d')) - def start_dnsmasq(self): - subprocess.check_call('dnsmasq -8 /var/run/networkd-ci/test-dnsmasq-log-file --log-queries=extra --log-dhcp --pid-file=/var/run/networkd-ci/test-test-dnsmasq.pid --conf-file=/dev/null --interface=veth-peer --enable-ra --dhcp-range=2600::10,2600::20 --dhcp-range=192.168.5.10,192.168.5.200 -R --dhcp-leasefile=/var/run/networkd-ci/lease --dhcp-option=26,1492 --dhcp-option=option:router,192.168.5.1 --dhcp-option=33,192.168.5.4,192.168.5.5 --port=0', shell=True) + def start_dnsmasq(self, additional_options=''): + dnsmasq_command = 'dnsmasq -8 /var/run/networkd-ci/test-dnsmasq-log-file --log-queries=extra --log-dhcp --pid-file=/var/run/networkd-ci/test-test-dnsmasq.pid --conf-file=/dev/null --interface=veth-peer --enable-ra --dhcp-range=2600::10,2600::20 --dhcp-range=192.168.5.10,192.168.5.200 -R --dhcp-leasefile=/var/run/networkd-ci/lease --dhcp-option=26,1492 --dhcp-option=option:router,192.168.5.1 --dhcp-option=33,192.168.5.4,192.168.5.5 --port=0 ' + additional_options + subprocess.check_call(dnsmasq_command, shell=True) time.sleep(10) @@ -176,33 +176,6 @@ class Utilities(): time.sleep(5) print() -global ip -global port - -class DHCPServer(threading.Thread): - def __init__(self, name): - threading.Thread.__init__(self) - self.name = name - - def run(self): - self.start_dhcp_server() - - def start_dhcp_server(self): - sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - - server_address = ('0.0.0.0', 67) - sock.bind(server_address) - - print('Starting DHCP Server ...\n') - data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes - - global ip - ip = addr[0] - - global port - port = addr[1] - sock.close() - class NetworkdNetDevTests(unittest.TestCase, Utilities): links =[ @@ -1204,21 +1177,15 @@ class NetworkdNetworkDHCPClientTests(unittest.TestCase, Utilities): def test_dhcp_client_listen_port(self): self.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-listen-port.network') - - dh_server = DHCPServer("dhcp_server") - dh_server.start() - self.start_networkd() self.assertTrue(self.link_exits('veth99')) - global port - global ip - - self.assertRegex(str(port), '5555') - self.assertRegex(str(ip), '0.0.0.0') + self.start_dnsmasq('--dhcp-alternate-port=67,5555') - dh_server.join() + output = subprocess.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, '192.168.5.* dynamic') def test_dhcp_route_table_id(self): self.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-table.network') |