Skip to content

Commit da7fd53

Browse files
committed
Make BuildTest run both for IPv4 and IPv6
1 parent c24bbad commit da7fd53

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

tests/conftest.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ def clean_all(route_network, datacenter_type, vm_hostname=None):
7474
# logic to assign them and we want to avoid IP address conflicts.
7575
# Index 1 is usually used for the test's subject VM,
7676
# 2 might be used for testing IP change.
77-
ips = [get_next_address(VM_NET, i) for i in [1, 2]]
78-
clean_serveradmin({'intern_ip': Any(*ips)})
77+
for ip_attr in ('ipv4', 'ipv6'):
78+
ips = [get_next_address(VM_NET, i, ip_attr) for i in [1, 2]]
79+
clean_serveradmin({ip_attr: Any(*ips)})
7980

8081

8182
def clean_hv(hv, pattern):
@@ -208,16 +209,16 @@ def _wait_for_state_reached(ec2_client, instance_id: str, state: str,
208209
raise
209210

210211

211-
def get_next_address(vm_net, index):
212+
def get_next_address(vm_net, index, ip_attr):
212213
non_vm_hosts = list(Query({
213214
'project_network': vm_net,
214215
'servertype': Not('vm'),
215-
}, ['intern_ip']))
216+
}, [ip_attr]))
216217
offset = 1 if len(non_vm_hosts) > 0 else 0
217218
subnet_levels = ceil(log(PYTEST_XDIST_WORKER_COUNT + offset, 2))
218-
project_network = Query({'hostname': vm_net}, ['intern_ip']).get()
219+
project_network = Query({'hostname': vm_net}, [ip_attr]).get()
219220
try:
220-
subnets = list(project_network['intern_ip'].subnets(subnet_levels))
221+
subnets = list(project_network[ip_attr].subnets(subnet_levels))
221222
except ValueError:
222223
raise IGVMTestError(
223224
'Can\'t split {} into enough subnets '

tests/test_integration.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def teardown_module():
7373

7474

7575
class IGVMTest(TestCase):
76+
ip_attr = 'ipv4'
77+
7678
def setUp(self):
7779
"""Initialize VM object before every test
7880
@@ -112,7 +114,7 @@ def setUp(self):
112114
self.vm_obj['environment'] = 'testing'
113115
self.vm_obj['hostname'] = VM_HOSTNAME
114116
self.vm_obj['hypervisor'] = None
115-
self.vm_obj['intern_ip'] = get_next_address(VM_NET, 1)
117+
self.vm_obj['intern_ip'] = get_next_address(VM_NET, 1, self.ip_attr)
116118
self.vm_obj['memory'] = 2048
117119
self.vm_obj['no_monitoring'] = True
118120
self.vm_obj['num_cpu'] = 2
@@ -225,7 +227,7 @@ def test_kvm_hwmodel_to_cpumodel(self):
225227
msg='Missing hardware_model in KVM_HWMODEL_TO_CPUMODEL')
226228

227229

228-
class BuildTest(IGVMTest):
230+
class _BuildTest(IGVMTest):
229231
"""Test many possible VM building scenarios"""
230232

231233
def test_vm_build(self):
@@ -291,6 +293,13 @@ def test_rebuild(self):
291293
vm.run('test ! -f /root/initial_canary')
292294

293295

296+
class BuildTestIPv4(_BuildTest):
297+
ip_attr = 'ipv4'
298+
299+
300+
class BuildTestIPv6(_BuildTest):
301+
ip_attr = 'ipv6'
302+
294303
class CommandTest(IGVMTest):
295304
def setUp(self):
296305
super(CommandTest, self).setUp()
@@ -682,7 +691,7 @@ def test_new_address(self):
682691
# We don't have a way to ask for new IP address from Serveradmin
683692
# and lock it for us. The method below will usually work fine.
684693
# When it starts failing, we must develop retry method.
685-
new_address = get_next_address(VM_NET, 2)
694+
new_address = get_next_address(VM_NET, 2, 'ipv4')
686695

687696
change_address(VM_HOSTNAME, new_address, offline=True)
688697

0 commit comments

Comments
 (0)