Fix test_ipvX_subnet_nameservers when trunk ports are used

When a VM is created with trunk ports, the DNS nameservers are added
to both the parent port and the subport.
This patch checks whether the VM has a VLAN interface (i.e. it uses
trunk ports) and, in that case, tests test_ipv4_subnet_nameservers and
test_ipv6_subnet_nameservers check nameservers from both parent port
and subport subnets.

Depends-On: I6fa5b70558e886b17c63dab61fad3c7a2728d148

Change-Id: I453be8aa13a5c27d425435160756d58b672d69d6
This commit is contained in:
Eduardo Olivares 2023-09-11 12:51:23 +02:00
parent b32c3a5f6e
commit e926d82ea1

View File

@ -102,21 +102,37 @@ class CirrosServerStackTest(testtools.TestCase):
self.assertIn(self.stack.swap_filename, mounted_filenames, swaps_table)
def test_ipv4_subnet_nameservers(self):
self._test_subnet_nameservers(
subnet=self.stack.network_stack.ipv4_subnet_details,
ip_version=4)
self._test_subnet_nameservers(ip_version=4)
def test_ipv6_subnet_nameservers(self):
self._test_subnet_nameservers(
subnet=self.stack.network_stack.ipv6_subnet_details,
ip_version=6)
self._test_subnet_nameservers(ip_version=6)
def _test_subnet_nameservers(self, ip_version):
def get_subnet_nameservers(network_stack, ip_version):
# returns a tuple with:
# 1. the subnet name (str)
# 2. the subnet dns nameservers (list of str)
subnet_details = (network_stack.ipv4_subnet_details
if ip_version == 4
else network_stack.ipv6_subnet_details)
nameservers = [netaddr.IPAddress(nameserver)
for nameserver in subnet_details['dns_nameservers']]
return (subnet_details['name'], nameservers)
subnet_name, subnet_nameservers = get_subnet_nameservers(
self.stack.network_stack, ip_version)
if self.stack.has_vlan:
vlan_subnet_name, vlan_subnet_nameservers = get_subnet_nameservers(
self.stack.vlan_network_stack, ip_version)
subnet_names = ','.join([subnet_name, vlan_subnet_name])
subnet_nameservers += vlan_subnet_nameservers
else:
subnet_names = subnet_name
def _test_subnet_nameservers(self, subnet, ip_version):
subnet_nameservers = [netaddr.IPAddress(nameserver)
for nameserver in subnet['dns_nameservers']]
if not subnet_nameservers:
self.skipTest(f"Subnet '{subnet['id']}' has any IPv{ip_version} "
"nameserver")
self.skipTest(f"Subnet(s) '{subnet_names}' have no IPv{ip_version}"
" nameservers")
server_nameservers = sh.list_nameservers(
ssh_client=self.stack.ssh_client, ip_version=ip_version,
filenames=self.nameservers_filenames)