Skip to content

Commit

Permalink
tests: collect detailed diagnostics on failure
Browse files Browse the repository at this point in the history
Help debugging test failures by collecting detailed information on
failure. It will be logger to the standard logger, which will end up
either on stderr or in journalctl.

(cherry picked from commit 46cc4ca)
  • Loading branch information
marmarek committed Oct 22, 2020
1 parent fe6bf0e commit b61690e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
28 changes: 27 additions & 1 deletion qubes/tests/integ/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, see <https://www.gnu.org/licenses/>.
#

import contextlib
from distutils import spawn

import asyncio
Expand Down Expand Up @@ -87,6 +87,32 @@ def setUp(self):

self.configure_netvm()

def _run_cmd_and_log_output(self, vm, cmd):
"""Used in tearDown to collect more info"""
if not vm.is_running():
return
with contextlib.suppress(subprocess.CalledProcessError):
output = self.loop.run_until_complete(
self.testnetvm.run_for_stdio(cmd, user='root'))
self.log.error('{}: {}: {}'.format(vm.name, cmd, output))

def tearDown(self):
# collect more info on failure
if self._outcome and not self._outcome.success:
for vm in (self.testnetvm, self.testvm1, getattr(self, 'proxy', None)):
if vm is None:
continue
self._run_cmd_and_log_output(vm, 'ip a')
self._run_cmd_and_log_output(vm, 'ip r')
self._run_cmd_and_log_output(vm, 'iptables -vnL')
self._run_cmd_and_log_output(vm, 'iptables -vnL -t nat')
self._run_cmd_and_log_output(vm, 'nft list table qubes-firewall')
self._run_cmd_and_log_output(vm, 'systemctl --no-pager status qubes-firewall')
self._run_cmd_and_log_output(vm, 'systemctl --no-pager status qubes-iptables')
self._run_cmd_and_log_output(vm, 'systemctl --no-pager status xendriverdomain')

super(VmNetworkingMixin, self).tearDown()


def configure_netvm(self):
'''
Expand Down
13 changes: 13 additions & 0 deletions qubes/tests/integ/network_ipv6.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ def setUp(self):
self.ping6_ip = self.ping6_cmd.format(target=self.test_ip6)
self.ping6_name = self.ping6_cmd.format(target=self.test_name)

def tearDown(self):
# collect more info on failure (ipv4 info collected in parent)
if self._outcome and not self._outcome.success:
for vm in (self.testnetvm, self.testvm1, getattr(self, 'proxy', None)):
if vm is None:
continue
self._run_cmd_and_log_output(vm, 'ip -6 r')
self._run_cmd_and_log_output(vm, 'ip6tables -vnL')
self._run_cmd_and_log_output(vm, 'ip6tables -vnL -t nat')
self._run_cmd_and_log_output(vm, 'nft list table ip6 qubes-firewall')

super().tearDown()

def configure_netvm(self):
'''
:type self: qubes.tests.SystemTestCase | VmIPv6NetworkingMixin
Expand Down

0 comments on commit b61690e

Please sign in to comment.