Merge pull request #29495 from yuwata/network-manager-state-file
network: fixlets for manager state file
This commit is contained in:
@@ -9,3 +9,7 @@ IPv6Token=::1a:2b:3c:4d
|
||||
[Route]
|
||||
Gateway=_ipv6ra
|
||||
Destination=2001:1234:5:9fff:ff:ff:ff:ff/128
|
||||
|
||||
[IPv6AcceptRA]
|
||||
# To check DNS and NTP servers are really obtained by DHCPv6
|
||||
UseDNS=no
|
||||
|
||||
@@ -534,6 +534,10 @@ def read_link_attr(*args):
|
||||
with open(os.path.join('/sys/class/net', *args), encoding='utf-8') as f:
|
||||
return f.readline().strip()
|
||||
|
||||
def read_manager_state_file():
|
||||
with open('/run/systemd/netif/state', encoding='utf-8') as f:
|
||||
return f.read()
|
||||
|
||||
def read_link_state_file(link):
|
||||
ifindex = read_link_attr(link, 'ifindex')
|
||||
path = os.path.join('/run/systemd/netif/links', ifindex)
|
||||
@@ -567,7 +571,12 @@ def stop_by_pid_file(pid_file):
|
||||
print(f"Unexpected exception when waiting for {pid} to die: {e.errno}")
|
||||
rm_f(pid_file)
|
||||
|
||||
def start_dnsmasq(*additional_options, interface='veth-peer', lease_time='2m', ipv4_range='192.168.5.10,192.168.5.200', ipv4_router='192.168.5.1', ipv6_range='2600::10,2600::20'):
|
||||
def start_dnsmasq(*additional_options, interface='veth-peer', ra_mode=None, ipv4_range='192.168.5.10,192.168.5.200', ipv4_router='192.168.5.1', ipv6_range='2600::10,2600::20'):
|
||||
if ra_mode:
|
||||
ra_mode = f',{ra_mode}'
|
||||
else:
|
||||
ra_mode = ''
|
||||
|
||||
command = (
|
||||
'dnsmasq',
|
||||
f'--log-facility={dnsmasq_log_file}',
|
||||
@@ -579,8 +588,8 @@ def start_dnsmasq(*additional_options, interface='veth-peer', lease_time='2m', i
|
||||
f'--interface={interface}',
|
||||
f'--dhcp-leasefile={dnsmasq_lease_file}',
|
||||
'--enable-ra',
|
||||
f'--dhcp-range={ipv6_range},{lease_time}',
|
||||
f'--dhcp-range={ipv4_range},{lease_time}',
|
||||
f'--dhcp-range={ipv6_range}{ra_mode},2m',
|
||||
f'--dhcp-range={ipv4_range},2m',
|
||||
'--dhcp-option=option:mtu,1492',
|
||||
f'--dhcp-option=option:router,{ipv4_router}',
|
||||
'--port=0',
|
||||
@@ -5099,7 +5108,41 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
|
||||
|
||||
start_networkd()
|
||||
self.wait_online(['veth-peer:carrier'])
|
||||
start_dnsmasq()
|
||||
|
||||
# information request mode
|
||||
start_dnsmasq('--dhcp-option=option6:dns-server,[2600::ee]',
|
||||
'--dhcp-option=option6:ntp-server,[2600::ff]',
|
||||
ra_mode='ra-stateless')
|
||||
self.wait_online(['veth99:routable', 'veth-peer:routable'])
|
||||
|
||||
# Check link state file
|
||||
print('## link state file')
|
||||
output = read_link_state_file('veth99')
|
||||
print(output)
|
||||
self.assertIn('DNS=2600::ee', output)
|
||||
self.assertIn('NTP=2600::ff', output)
|
||||
|
||||
# Check manager state file
|
||||
print('## manager state file')
|
||||
output = read_manager_state_file()
|
||||
print(output)
|
||||
self.assertRegex(output, 'DNS=.*2600::ee')
|
||||
self.assertRegex(output, 'NTP=.*2600::ff')
|
||||
|
||||
print('## dnsmasq log')
|
||||
output = read_dnsmasq_log_file()
|
||||
print(output)
|
||||
self.assertIn('DHCPINFORMATION-REQUEST(veth-peer)', output)
|
||||
self.assertNotIn('DHCPSOLICIT(veth-peer)', output)
|
||||
self.assertNotIn('DHCPADVERTISE(veth-peer)', output)
|
||||
self.assertNotIn('DHCPREQUEST(veth-peer)', output)
|
||||
self.assertNotIn('DHCPREPLY(veth-peer)', output)
|
||||
|
||||
# solicit mode
|
||||
stop_dnsmasq()
|
||||
start_dnsmasq('--dhcp-option=option6:dns-server,[2600::ee]',
|
||||
'--dhcp-option=option6:ntp-server,[2600::ff]')
|
||||
networkctl_reconfigure('veth99')
|
||||
self.wait_online(['veth99:routable', 'veth-peer:routable'])
|
||||
|
||||
# checking address
|
||||
@@ -5118,9 +5161,24 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
|
||||
print(output)
|
||||
self.assertRegex(output, 'token :: dev veth99')
|
||||
|
||||
# Check link state file
|
||||
print('## link state file')
|
||||
output = read_link_state_file('veth99')
|
||||
print(output)
|
||||
self.assertIn('DNS=2600::ee', output)
|
||||
self.assertIn('NTP=2600::ff', output)
|
||||
|
||||
# Check manager state file
|
||||
print('## manager state file')
|
||||
output = read_manager_state_file()
|
||||
print(output)
|
||||
self.assertRegex(output, 'DNS=.*2600::ee')
|
||||
self.assertRegex(output, 'NTP=.*2600::ff')
|
||||
|
||||
print('## dnsmasq log')
|
||||
output = read_dnsmasq_log_file()
|
||||
print(output)
|
||||
self.assertNotIn('DHCPINFORMATION-REQUEST(veth-peer)', output)
|
||||
self.assertIn('DHCPSOLICIT(veth-peer)', output)
|
||||
self.assertNotIn('DHCPADVERTISE(veth-peer)', output)
|
||||
self.assertNotIn('DHCPREQUEST(veth-peer)', output)
|
||||
@@ -5131,7 +5189,8 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
|
||||
f.write('\n[DHCPv6]\nRapidCommit=no\n')
|
||||
|
||||
stop_dnsmasq()
|
||||
start_dnsmasq()
|
||||
start_dnsmasq('--dhcp-option=option6:dns-server,[2600::ee]',
|
||||
'--dhcp-option=option6:ntp-server,[2600::ff]')
|
||||
|
||||
networkctl_reload()
|
||||
self.wait_online(['veth99:routable', 'veth-peer:routable'])
|
||||
@@ -5147,9 +5206,24 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
|
||||
print(output)
|
||||
self.assertRegex(output, 'via fe80::1034:56ff:fe78:9abd')
|
||||
|
||||
# Check link state file
|
||||
print('## link state file')
|
||||
output = read_link_state_file('veth99')
|
||||
print(output)
|
||||
self.assertIn('DNS=2600::ee', output)
|
||||
self.assertIn('NTP=2600::ff', output)
|
||||
|
||||
# Check manager state file
|
||||
print('## manager state file')
|
||||
output = read_manager_state_file()
|
||||
print(output)
|
||||
self.assertRegex(output, 'DNS=.*2600::ee')
|
||||
self.assertRegex(output, 'NTP=.*2600::ff')
|
||||
|
||||
print('## dnsmasq log')
|
||||
output = read_dnsmasq_log_file()
|
||||
print(output)
|
||||
self.assertNotIn('DHCPINFORMATION-REQUEST(veth-peer)', output)
|
||||
self.assertIn('DHCPSOLICIT(veth-peer)', output)
|
||||
self.assertIn('DHCPADVERTISE(veth-peer)', output)
|
||||
self.assertIn('DHCPREQUEST(veth-peer)', output)
|
||||
|
||||
Reference in New Issue
Block a user