[tests] fix advertising proxy tests (#6276)

zeroconf is not able to discover the services after updating the host
address. We fixed this issue by replacing zeroconf with dns-sd.
This commit is contained in:
kangping
2021-03-12 08:00:01 -08:00
committed by GitHub
parent 48b09e3130
commit dcc9472ba1
2 changed files with 45 additions and 26 deletions
+45 -25
View File
@@ -39,7 +39,6 @@ import time
import traceback import traceback
import unittest import unittest
from typing import Union, Dict, Optional, List from typing import Union, Dict, Optional, List
from zeroconf import Zeroconf, ServiceInfo
import pexpect import pexpect
import pexpect.popen_spawn import pexpect.popen_spawn
@@ -303,9 +302,6 @@ class OtbrDocker:
self.bash(f'sysctl net.ipv6.conf.{self.ETH_DEV}.accept_ra=2') self.bash(f'sysctl net.ipv6.conf.{self.ETH_DEV}.accept_ra=2')
self.bash(f'sysctl net.ipv6.conf.{self.ETH_DEV}.accept_ra_rt_info_max_plen=64') self.bash(f'sysctl net.ipv6.conf.{self.ETH_DEV}.accept_ra_rt_info_max_plen=64')
# Zeroconf complains that there is not enough BUFS to subscribe multicast groups.
self.bash('sysctl net.ipv4.igmp_max_memberships=1024')
class OtCli: class OtCli:
@@ -2727,27 +2723,51 @@ class LinuxHost():
The return value is a dict with the same key/values of srp_server_get_service The return value is a dict with the same key/values of srp_server_get_service
except that we don't have a `deleted` field here. except that we don't have a `deleted` field here.
""" """
zeroconf = Zeroconf()
timeout *= 1000 # Zeroconf use timeout in milliseconds. self.bash(f'dns-sd -Z {name} local. > /tmp/{name} 2>&1 &')
try: self.bash(f'dns-sd -G v6 {host_name}.local. > /tmp/{host_name} 2>&1 &')
info = ServiceInfo(type_=f'{name}.local.', name=f'{instance}.{name}.local.', server=f'{host_name}.local.') time.sleep(timeout)
while timeout > 0 and not info.parsed_addresses():
info.request(zeroconf, 500) self.bash('pkill dns-sd')
timeout -= 500 addresses = []
if info.parsed_addresses(): service = {}
return {
'fullname': info.name, logging.debug(self.bash(f'cat /tmp/{host_name}'))
'instance': info.get_name(), logging.debug(self.bash(f'cat /tmp/{name}'))
'name': name,
'port': info.port, # example output in the host file:
'weight': info.weight, # Timestamp A/R Flags if Hostname Address TTL
'priority': info.priority, # 9:38:09.274 Add 23 48 my-host.local. 2001:0000:0000:0000:0000:0000:0000:0002%<0> 120
'host_fullname': info.server, #
'host': host_name, for line in self.bash(f'cat /tmp/{host_name}'):
'addresses': info.parsed_addresses() elements = line.split()
} if not elements or len(elements) < 6 or not elements[4].startswith(host_name):
finally: continue
zeroconf.close() addresses.append(elements[5].split('%')[0])
logging.debug(f'addresses of {host_name}: {addresses}')
# example output of in the service file:
# _ipps._tcp PTR my-service._ipps._tcp
# my-service._ipps._tcp SRV 0 0 12345 my-host.local. ; Replace with unicast FQDN of target host
# my-service._ipps._tcp TXT ""
#
for line in self.bash(f'cat /tmp/{name}'):
elements = line.split()
if not elements or elements[0] != f'{instance}.{name}':
continue
if elements[1] == 'SRV':
service['fullname'] = elements[0]
service['instance'] = instance
service['name'] = name
service['priority'] = int(elements[2])
service['weight'] = int(elements[3])
service['port'] = int(elements[4])
service['host_fullname'] = elements[5]
assert (service['host_fullname'] == f'{host_name}.local.')
service['host'] = host_name
service['addresses'] = addresses
return service if service['addresses'] else None
class OtbrNode(LinuxHost, NodeImpl, OtbrDocker): class OtbrNode(LinuxHost, NodeImpl, OtbrDocker):
@@ -2,4 +2,3 @@ ipaddress
pexpect pexpect
pycryptodome pycryptodome
pyshark==0.4.2.11 pyshark==0.4.2.11
zeroconf