tests: wait for full VM startup before testing network and few other

Network may be configured (by qubes-misc-post service in some cases)
after qrexec is started. Delay any test after VM is fully started (as
the user would do).
Adjust wait_for_session function, to re-use VM startup timeout, which
make it adjustable for slower machines (like nested virt on openQA).
This commit is contained in:
Marek Marczykowski-Górecki 2020-11-20 05:36:46 +01:00
parent 8233009e2a
commit 7d8d0c10d1
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
4 changed files with 45 additions and 40 deletions

View File

@ -1277,7 +1277,7 @@ class SystemTestCase(QubesTestCase):
@asyncio.coroutine
def wait_for_session(self, vm):
timeout = 30
timeout = vm.qrexec_timeout
if getattr(vm, 'template', None) and 'whonix-ws' in vm.template.name:
# first boot of whonix-ws takes more time because of /home
# initialization, including Tor Browser copying
@ -1287,6 +1287,12 @@ class SystemTestCase(QubesTestCase):
'qubes.WaitForSession', input=vm.default_user.encode()),
timeout=timeout)
@asyncio.coroutine
def start_vm(self, vm):
"""Start a VM and wait for it to be fully up"""
yield from vm.start()
yield from self.wait_for_session(vm)
_templates = None

View File

@ -57,6 +57,9 @@ class GrubBase(object):
else:
assert False, "Unsupported template?!"
# wait for full VM startup first, to have functional network
self.loop.run_until_complete(self.wait_for_session(vm))
for cmd in [cmd_install1, cmd_install2, cmd_update_grub]:
try:
self.loop.run_until_complete(vm.run_for_stdio(

View File

@ -154,7 +154,7 @@ class VmNetworkingMixin(object):
'''
:type self: qubes.tests.SystemTestCase | VMNetworkingMixin
'''
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertEqual(self.run_cmd(self.testvm1, self.ping_ip), 0)
self.assertEqual(self.run_cmd(self.testvm1, self.ping_name), 0)
@ -172,7 +172,7 @@ class VmNetworkingMixin(object):
self.testvm1.netvm = self.proxy
self.app.save()
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertTrue(self.proxy.is_running())
self.assertEqual(self.run_cmd(self.proxy, self.ping_ip), 0,
"Ping by IP from ProxyVM failed")
@ -201,7 +201,7 @@ class VmNetworkingMixin(object):
self.testvm1.netvm = self.proxy
self.app.save()
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertTrue(self.proxy.is_running())
self.assertEqual(self.run_cmd(self.testvm1, self.ping_ip), 0,
"Ping by IP failed")
@ -252,7 +252,7 @@ class VmNetworkingMixin(object):
self.testvm1.firewall.rules = [qubes.firewall.Rule(action='drop')]
self.testvm1.firewall.save()
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertTrue(self.proxy.is_running())
server = self.loop.run_until_complete(self.testnetvm.run(
@ -352,8 +352,8 @@ class VmNetworkingMixin(object):
self.app.save()
self.loop.run_until_complete(asyncio.gather(
self.testvm1.start(),
self.testvm2.start()))
self.start_vm(self.testvm1),
self.start_vm(self.testvm2)))
self.assertNotEqual(self.run_cmd(self.testvm1,
self.ping_cmd.format(target=self.testvm2.ip)), 0)
@ -377,7 +377,7 @@ class VmNetworkingMixin(object):
:type self: qubes.tests.SystemTestCase | VMNetworkingMixin
'''
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertEqual(self.run_cmd(self.testvm1, self.ping_ip), 0)
self.assertEqual(self.run_cmd(self.testnetvm,
@ -410,7 +410,7 @@ class VmNetworkingMixin(object):
cmd = "systemctl stop xendriverdomain"
if self.run_cmd(self.testnetvm, cmd) != 0:
self.fail("Command '%s' failed" % cmd)
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
cmd = "systemctl start xendriverdomain"
if self.run_cmd(self.testnetvm, cmd) != 0:
@ -423,7 +423,7 @@ class VmNetworkingMixin(object):
def test_110_dynamic_attach(self):
self.testvm1.netvm = None
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.testvm1.netvm = self.testnetvm
# wait for it to settle down
self.loop.run_until_complete(self.testvm1.run_for_stdio(
@ -431,7 +431,7 @@ class VmNetworkingMixin(object):
self.assertEqual(self.run_cmd(self.testvm1, self.ping_ip), 0)
def test_111_dynamic_detach_attach(self):
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.testvm1.netvm = None
# wait for it to settle down
self.loop.run_until_complete(self.testvm1.run_for_stdio(
@ -451,9 +451,9 @@ class VmNetworkingMixin(object):
self.loop.run_until_complete(self.proxy.create_on_disk())
self.testvm1.netvm = self.proxy
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.loop.run_until_complete(self.proxy.shutdown(force=True, wait=True))
self.loop.run_until_complete(self.proxy.start())
self.loop.run_until_complete(self.start_vm(self.proxy))
# wait for it to settle down
self.loop.run_until_complete(self.wait_for_session(self.proxy))
self.assertEqual(self.run_cmd(self.testvm1, self.ping_ip), 0)
@ -467,11 +467,9 @@ class VmNetworkingMixin(object):
self.loop.run_until_complete(self.proxy.create_on_disk())
self.testvm1.netvm = self.proxy
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.loop.run_until_complete(self.proxy.kill())
self.loop.run_until_complete(self.proxy.start())
# wait for it to settle down
self.loop.run_until_complete(self.wait_for_session(self.proxy))
self.loop.run_until_complete(self.start_vm(self.proxy))
self.assertEqual(self.run_cmd(self.testvm1, self.ping_ip), 0)
def test_114_reattach_after_provider_crash(self):
@ -483,7 +481,7 @@ class VmNetworkingMixin(object):
self.loop.run_until_complete(self.proxy.create_on_disk())
self.testvm1.netvm = self.proxy
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
p = self.loop.run_until_complete(self.proxy.run(
'echo c > /proc/sysrq-trigger', user='root'))
self.loop.run_until_complete(p.wait())
@ -493,9 +491,7 @@ class VmNetworkingMixin(object):
timeout -= 1
self.assertGreater(timeout, 0,
'timeout waiting for crash cleanup')
self.loop.run_until_complete(self.proxy.start())
# wait for it to settle down
self.loop.run_until_complete(self.wait_for_session(self.proxy))
self.loop.run_until_complete(self.start_vm(self.proxy))
self.assertEqual(self.run_cmd(self.testvm1, self.ping_ip), 0)
def test_200_fake_ip_simple(self):
@ -507,7 +503,7 @@ class VmNetworkingMixin(object):
self.testvm1.features['net.fake-gateway'] = '192.168.1.1'
self.testvm1.features['net.fake-netmask'] = '255.255.255.0'
self.app.save()
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertEqual(self.run_cmd(self.testvm1, self.ping_ip), 0)
self.assertEqual(self.run_cmd(self.testvm1, self.ping_name), 0)
@ -539,7 +535,7 @@ class VmNetworkingMixin(object):
'''
self.testvm1.features['net.fake-ip'] = '192.168.1.128'
self.app.save()
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertEqual(self.run_cmd(self.testvm1, self.ping_ip), 0)
self.assertEqual(self.run_cmd(self.testvm1, self.ping_name), 0)
@ -579,7 +575,7 @@ class VmNetworkingMixin(object):
qubes.firewall.Rule(None, action='accept', specialtarget='dns'),
]
self.testvm1.firewall.save()
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertTrue(self.proxy.is_running())
server = self.loop.run_until_complete(self.testnetvm.run(
@ -624,8 +620,8 @@ class VmNetworkingMixin(object):
self.testvm2.netvm = self.proxy
self.app.save()
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.testvm2.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.loop.run_until_complete(self.start_vm(self.testvm2))
cmd = 'iptables -I FORWARD -s {} -d {} -j ACCEPT'.format(
self.testvm2.ip, self.testvm1.ip)
@ -673,7 +669,7 @@ class VmNetworkingMixin(object):
self.proxy.features['net.fake-netmask'] = '255.255.255.0'
self.testvm1.netvm = self.proxy
self.app.save()
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertEqual(self.run_cmd(self.proxy, self.ping_ip), 0)
self.assertEqual(self.run_cmd(self.proxy, self.ping_name), 0)
@ -728,7 +724,7 @@ class VmNetworkingMixin(object):
'''
self.testvm1.ip = '192.168.1.1'
self.app.save()
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertEqual(self.run_cmd(self.testvm1, self.ping_ip), 0)
self.assertEqual(self.run_cmd(self.testvm1, self.ping_name), 0)
@ -747,7 +743,7 @@ class VmNetworkingMixin(object):
self.testvm1.netvm = self.proxy
self.app.save()
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertEqual(self.run_cmd(self.testvm1, self.ping_ip), 0)
self.assertEqual(self.run_cmd(self.testvm1, self.ping_name), 0)
@ -775,7 +771,7 @@ class VmNetworkingMixin(object):
qubes.firewall.Rule(None, action='accept', specialtarget='dns'),
]
self.testvm1.firewall.save()
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertTrue(self.proxy.is_running())
server = self.loop.run_until_complete(self.testnetvm.run(

View File

@ -84,7 +84,7 @@ class VmIPv6NetworkingMixin(VmNetworkingMixin):
'''
:type self: qubes.tests.SystemTestCase | VmIPv6NetworkingMixin
'''
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertEqual(self.run_cmd(self.testvm1, self.ping6_ip), 0)
self.assertEqual(self.run_cmd(self.testvm1, self.ping6_name), 0)
@ -102,7 +102,7 @@ class VmIPv6NetworkingMixin(VmNetworkingMixin):
self.testvm1.netvm = self.proxy
self.app.save()
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertTrue(self.proxy.is_running())
self.assertEqual(self.run_cmd(self.proxy, self.ping6_ip), 0,
"Ping by IP from ProxyVM failed")
@ -131,7 +131,7 @@ class VmIPv6NetworkingMixin(VmNetworkingMixin):
self.testvm1.netvm = self.proxy
self.app.save()
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertTrue(self.proxy.is_running())
self.assertEqual(self.run_cmd(self.testvm1, self.ping6_ip), 0,
"Ping by IP failed")
@ -187,7 +187,7 @@ class VmIPv6NetworkingMixin(VmNetworkingMixin):
self.testvm1.firewall.rules = [qubes.firewall.Rule(action='drop')]
self.testvm1.firewall.save()
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertTrue(self.proxy.is_running())
server = self.loop.run_until_complete(self.testnetvm.run(
@ -308,8 +308,8 @@ class VmIPv6NetworkingMixin(VmNetworkingMixin):
self.app.save()
self.loop.run_until_complete(asyncio.gather(
self.testvm1.start(),
self.testvm2.start()))
self.start_vm(self.testvm1),
self.start_vm(self.testvm2)))
self.assertNotEqual(self.run_cmd(self.testvm1,
self.ping_cmd.format(target=self.testvm2.ip6)), 0)
@ -335,7 +335,7 @@ class VmIPv6NetworkingMixin(VmNetworkingMixin):
:type self: qubes.tests.SystemTestCase | VmIPv6NetworkingMixin
'''
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertEqual(self.run_cmd(self.testvm1, self.ping6_ip), 0)
# add a simple rule counting packets
@ -369,7 +369,7 @@ class VmIPv6NetworkingMixin(VmNetworkingMixin):
'''
self.testvm1.ip6 = '2000:aaaa:bbbb::1'
self.app.save()
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertEqual(self.run_cmd(self.testvm1, self.ping6_ip), 0)
self.assertEqual(self.run_cmd(self.testvm1, self.ping6_name), 0)
@ -388,7 +388,7 @@ class VmIPv6NetworkingMixin(VmNetworkingMixin):
self.testvm1.netvm = self.proxy
self.app.save()
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertEqual(self.run_cmd(self.testvm1, self.ping6_ip), 0)
self.assertEqual(self.run_cmd(self.testvm1, self.ping6_name), 0)
@ -416,7 +416,7 @@ class VmIPv6NetworkingMixin(VmNetworkingMixin):
qubes.firewall.Rule(None, action='accept', specialtarget='dns'),
]
self.testvm1.firewall.save()
self.loop.run_until_complete(self.testvm1.start())
self.loop.run_until_complete(self.start_vm(self.testvm1))
self.assertTrue(self.proxy.is_running())
server = self.loop.run_until_complete(self.testnetvm.run(