mirror of
https://github.com/espressif/openthread.git
synced 2026-07-28 14:47:46 +00:00
[border-agent] update meshcop test cases (#6865)
Add a new test case to verify the meshcop service is published with proper fields.
This commit is contained in:
@@ -191,13 +191,13 @@ class OtbrDocker:
|
||||
self._socat_proc.wait()
|
||||
del self._socat_proc
|
||||
|
||||
def bash(self, cmd: str) -> List[str]:
|
||||
def bash(self, cmd: str, encoding='ascii') -> List[str]:
|
||||
logging.info("%s $ %s", self, cmd)
|
||||
proc = subprocess.Popen(['docker', 'exec', '-i', self._docker_name, 'bash', '-c', cmd],
|
||||
stdin=subprocess.DEVNULL,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=sys.stderr,
|
||||
encoding='ascii')
|
||||
encoding=encoding)
|
||||
|
||||
with proc:
|
||||
|
||||
@@ -247,7 +247,7 @@ class OtbrDocker:
|
||||
],
|
||||
}
|
||||
"""
|
||||
output = self.bash(f'dig -6 @{server} {name} {qtype}')
|
||||
output = self.bash(f'dig -6 @{server} \'{name}\' {qtype}', encoding='raw_unicode_escape')
|
||||
|
||||
section = None
|
||||
dig_result = {
|
||||
@@ -286,7 +286,6 @@ class OtbrDocker:
|
||||
if section == 'QUESTION':
|
||||
assert line.startswith(';')
|
||||
line = line[1:]
|
||||
|
||||
record = list(line.split())
|
||||
|
||||
if section != 'QUESTION':
|
||||
@@ -2803,6 +2802,18 @@ class LinuxHost():
|
||||
"""
|
||||
|
||||
self.bash(f'dns-sd -Z {name} local. > /tmp/{name} 2>&1 &')
|
||||
time.sleep(timeout)
|
||||
|
||||
full_service_name = f'{instance}.{name}'
|
||||
# When hostname is unspecified, extract hostname from browse result
|
||||
if host_name is None:
|
||||
for line in self.bash(f'cat /tmp/{name}', encoding='raw_unicode_escape'):
|
||||
elements = line.split()
|
||||
if len(elements) >= 6 and elements[0] == full_service_name and elements[1] == 'SRV':
|
||||
host_name = elements[5].split('.')[0]
|
||||
break
|
||||
|
||||
assert (host_name is not None)
|
||||
self.bash(f'dns-sd -G v6 {host_name}.local. > /tmp/{host_name} 2>&1 &')
|
||||
time.sleep(timeout)
|
||||
|
||||
@@ -2810,14 +2821,14 @@ class LinuxHost():
|
||||
addresses = []
|
||||
service = {}
|
||||
|
||||
logging.debug(self.bash(f'cat /tmp/{host_name}'))
|
||||
logging.debug(self.bash(f'cat /tmp/{name}'))
|
||||
logging.debug(self.bash(f'cat /tmp/{host_name}', encoding='raw_unicode_escape'))
|
||||
logging.debug(self.bash(f'cat /tmp/{name}', encoding='raw_unicode_escape'))
|
||||
|
||||
# example output in the host file:
|
||||
# Timestamp A/R Flags if Hostname Address TTL
|
||||
# 9:38:09.274 Add 23 48 my-host.local. 2001:0000:0000:0000:0000:0000:0000:0002%<0> 120
|
||||
#
|
||||
for line in self.bash(f'cat /tmp/{host_name}'):
|
||||
for line in self.bash(f'cat /tmp/{host_name}', encoding='raw_unicode_escape'):
|
||||
elements = line.split()
|
||||
fullname = f'{host_name}.local.'
|
||||
if fullname not in elements:
|
||||
@@ -2831,9 +2842,21 @@ class LinuxHost():
|
||||
# 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}'):
|
||||
is_txt = False
|
||||
txt = ''
|
||||
for line in self.bash(f'cat /tmp/{name}', encoding='raw_unicode_escape'):
|
||||
elements = line.split()
|
||||
if not elements or elements[0] != f'{instance}.{name}':
|
||||
if len(elements) >= 2 and elements[1] == 'TXT':
|
||||
is_txt = True
|
||||
if is_txt:
|
||||
txt += line.strip()
|
||||
if line.strip().endswith('"'):
|
||||
is_txt = False
|
||||
txt_dict = self.__parse_dns_sd_txt(txt)
|
||||
logging.info(f'txt = {txt_dict}')
|
||||
service['txt'] = txt_dict
|
||||
|
||||
if not elements or elements[0] != full_service_name:
|
||||
continue
|
||||
if elements[1] == 'SRV':
|
||||
service['fullname'] = elements[0]
|
||||
@@ -2846,7 +2869,7 @@ class LinuxHost():
|
||||
assert (service['host_fullname'] == f'{host_name}.local.')
|
||||
service['host'] = host_name
|
||||
service['addresses'] = addresses
|
||||
return service if service['addresses'] else None
|
||||
return service if 'addresses' in service and service['addresses'] else None
|
||||
|
||||
def start_radvd_service(self, prefix, slaac):
|
||||
self.bash("""cat >/etc/radvd.conf <<EOF
|
||||
@@ -2879,6 +2902,19 @@ EOF
|
||||
def kill_radvd_service(self):
|
||||
self.bash('pkill radvd')
|
||||
|
||||
def __parse_dns_sd_txt(self, line: str):
|
||||
# Example TXT entry:
|
||||
# "xp=\\000\\013\\184\\000\\000\\000\\000\\000"
|
||||
txt = {}
|
||||
for entry in re.findall(r'"((?:[^\\]|\\.)*?)"', line):
|
||||
if '=' not in entry:
|
||||
continue
|
||||
|
||||
k, v = entry.split('=', 1)
|
||||
txt[k] = v
|
||||
|
||||
return txt
|
||||
|
||||
|
||||
class OtbrNode(LinuxHost, NodeImpl, OtbrDocker):
|
||||
is_otbr = True
|
||||
|
||||
Reference in New Issue
Block a user