[tests] test updating SRP host address (#6246)

Test if we can update the host address.
This commit is contained in:
kangping
2021-03-09 10:47:47 -08:00
committed by GitHub
parent 5b6691eaa0
commit 21cd2d18d7
2 changed files with 34 additions and 11 deletions
@@ -99,14 +99,14 @@ class SingleHostAndService(thread_cert.TestCase):
client.srp_client_start(server.get_addrs()[0], client.get_srp_server_port())
self.simulator.go(2)
self.check_host_and_service(server, client)
self.check_host_and_service(server, client, '2001::1')
#
# 2. Discover the service by the HOST on the ethernet. This makes sure
# the Advertising Proxy multicasts the same service on ethernet.
#
self.host_check_mdns_service(host)
self.host_check_mdns_service(host, '2001::1')
#
# 3. Check if the Advertising Proxy removes the service from ethernet
@@ -128,9 +128,21 @@ class SingleHostAndService(thread_cert.TestCase):
client.srp_client_add_service('my-service', '_ipps._tcp', 12345)
self.simulator.go(2)
self.host_check_mdns_service(host)
self.check_host_and_service(server, client, '2001::1')
self.host_check_mdns_service(host, '2001::1')
def host_check_mdns_service(self, host):
#
# 5. Update the SRP host address and make sure the Advertising Proxy
# will follow it.
#
client.srp_client_set_host_address('2001::2')
self.simulator.go(2)
self.check_host_and_service(server, client, '2001::2')
self.host_check_mdns_service(host, '2001::2')
def host_check_mdns_service(self, host, host_addr):
service = host.discover_mdns_service('my-service', '_ipps._tcp', 'my-host')
self.assertIsNotNone(service)
self.assertEqual(service['instance'], 'my-service')
@@ -139,8 +151,10 @@ class SingleHostAndService(thread_cert.TestCase):
self.assertEqual(service['priority'], 0)
self.assertEqual(service['weight'], 0)
self.assertEqual(service['host'], 'my-host')
self.assertEqual(ipaddress.ip_address(service['addresses'][0]), ipaddress.ip_address(host_addr))
self.assertEqual(len(service['addresses']), 1)
def check_host_and_service(self, server, client):
def check_host_and_service(self, server, client, host_addr):
"""Check that we have properly registered host and service instance.
"""
@@ -182,7 +196,7 @@ class SingleHostAndService(thread_cert.TestCase):
self.assertEqual(server_host['deleted'], 'false')
self.assertEqual(server_host['fullname'], server_service['host_fullname'])
self.assertEqual(len(server_host['addresses']), 1)
self.assertEqual(ipaddress.ip_address(server_host['addresses'][0]), ipaddress.ip_address('2001::1'))
self.assertEqual(ipaddress.ip_address(server_host['addresses'][0]), ipaddress.ip_address(host_addr))
if __name__ == '__main__':
@@ -97,7 +97,7 @@ class SrpRegisterSingleService(thread_cert.TestCase):
client.srp_client_add_service('my-service', '_ipps._tcp', 12345, 0, 0, ['abc', 'def=', 'xyz=XYZ'])
self.simulator.go(2)
self.check_host_and_service(server, client)
self.check_host_and_service(server, client, '2001::1')
#
# 2. Unregister a service but retain the name. The service name should be
@@ -138,10 +138,19 @@ class SrpRegisterSingleService(thread_cert.TestCase):
client.srp_client_add_service('my-service', '_ipps._tcp', 12345, 0, 0, ['abc', 'def=', 'xyz=XYZ'])
self.simulator.go(2)
self.check_host_and_service(server, client)
self.check_host_and_service(server, client, '2001::1')
#
# 4. Fully remove the host and all its service instances.
# 4. Update the SRP host address and make sure it will succeed.
#
client.srp_client_set_host_address('2001::2')
self.simulator.go(2)
self.check_host_and_service(server, client, '2001::2')
#
# 5. Fully remove the host and all its service instances.
#
client.srp_client_remove_host(remove_key=True)
@@ -161,7 +170,7 @@ class SrpRegisterSingleService(thread_cert.TestCase):
print(server_hosts)
self.assertEqual(len(server_hosts), 0)
def check_host_and_service(self, server, client):
def check_host_and_service(self, server, client, host_addr):
"""Check that we have properly registered host and service instance.
"""
@@ -205,7 +214,7 @@ class SrpRegisterSingleService(thread_cert.TestCase):
self.assertEqual(server_host['deleted'], 'false')
self.assertEqual(server_host['fullname'], server_service['host_fullname'])
self.assertEqual(len(server_host['addresses']), 1)
self.assertEqual(ipaddress.ip_address(server_host['addresses'][0]), ipaddress.ip_address('2001::1'))
self.assertEqual(ipaddress.ip_address(server_host['addresses'][0]), ipaddress.ip_address(host_addr))
if __name__ == '__main__':