vm/mix/net: fix handling network detach/attach on VM startup

- catch both QubesException and libvirtError - do not kill starting VM
just because an error while connecting _other_ VMs to it
- try to detach network first (and do not abort on error) - if
libvirt/libxl will manage to cleanup stale interface this way, the
attach operation below may succeed.

Fixes QubesOS/qubes-issues#3163
This commit is contained in:
Marek Marczykowski-Górecki 2018-01-29 23:06:21 +01:00
parent 86026e364f
commit a6a7efc9a7
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -262,15 +262,13 @@ class NetVMMixin(qubes.events.Emitter):
vm.log.info('Attaching network') vm.log.info('Attaching network')
try: try:
# 1426 vm.detach_network()
vm.run('modprobe -r xen-netfront xennet', except (qubes.exc.QubesException, libvirt.libvirtError):
user='root', wait=True) vm.log.warning('Cannot detach old network', exc_info=1)
except: # pylint: disable=bare-except
pass
try: try:
vm.attach_network() vm.attach_network()
except qubes.exc.QubesException: except (qubes.exc.QubesException, libvirt.libvirtError):
vm.log.warning('Cannot attach network', exc_info=1) vm.log.warning('Cannot attach network', exc_info=1)
@qubes.events.handler('domain-pre-shutdown') @qubes.events.handler('domain-pre-shutdown')