Merge lp:~rvb/maas-test/add-log-files into lp:maas-test

Proposed by Raphaël Badin
Status: Merged
Merged at revision: 52
Proposed branch: lp:~rvb/maas-test/add-log-files
Merge into: lp:maas-test
Diff against target: 136 lines (+68/-6)
3 files modified
maastest/maasfixture.py (+28/-0)
maastest/main.py (+2/-0)
maastest/tests/test_maasfixture.py (+38/-6)
To merge this branch: bzr merge lp:~rvb/maas-test/add-log-files
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+196252@code.launchpad.net

Commit message

Include logs in the report when tests fail.

Description of the change

When tests fail, having the logs will help us debug issues.

The changes to test_import_maas_images_imports_pxe_images are nothing but drive-by fixes.

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Nice. This'll help. Ingenious trick for getting the files into the log... Not the prettiest presentation perhaps, but it'll get the job done.

FWIW the check_call parameter to the run_command functions defaults to False, so if you want to avoid breaking up that line in collect_logs, that might help. Not that I'm saying you should; you may have left it deliberately explicit.

review: Approve
Revision history for this message
Raphaël Badin (rvb) wrote :

> Nice. This'll help. Ingenious trick for getting the files into the log...
> Not the prettiest presentation perhaps, but it'll get the job done.
>
> FWIW the check_call parameter to the run_command functions defaults to False,
> so if you want to avoid breaking up that line in collect_logs, that might
> help. Not that I'm saying you should; you may have left it deliberately
> explicit.

Yes, it's deliberately explicit. I set it to Fasle because I don't want the execution to stop if a file doesn't exist.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'maastest/maasfixture.py'
--- maastest/maasfixture.py 2013-11-21 13:33:05 +0000
+++ maastest/maasfixture.py 2013-11-22 10:41:25 +0000
@@ -56,6 +56,23 @@
56 config_file,56 config_file,
57 ]57 ]
5858
59# Log files that are interesting when debugging MAAS issues. They will
60# be collected just before the fixture is disposed of.
61LOG_FILES = [
62 # Syslog contains DHCP requests.
63 '/var/log/syslog',
64 # DHCP lease file.
65 '/var/lib/maas/dhcp/dhcpd.leases',
66 # MAAS logs.
67 '/var/log/maas/maas.log',
68 '/var/log/maas/pserv.log',
69 '/var/log/maas/celery-region.log',
70 '/var/log/maas/celery.log',
71 # Apache logs.
72 '/var/log/apache2/access.log',
73 '/var/log/apache2/error.log',
74]
75
5976
60class MAASFixture(Fixture):77class MAASFixture(Fixture):
61 """A fixture for a MAAS server."""78 """A fixture for a MAAS server."""
@@ -176,6 +193,17 @@
176 if self.kvm_fixture.direct_ip is not None:193 if self.kvm_fixture.direct_ip is not None:
177 self.check_cluster_connected()194 self.check_cluster_connected()
178 self.configure_cluster()195 self.configure_cluster()
196 # Cleanups registration.
197 self.addCleanup(self.collect_logs)
198
199 def collect_logs(self):
200 for filename in LOG_FILES:
201 # The result of every command run on the VM goes through
202 # testtools.TestCase.addDetail() so we just need to
203 # 'cat' the files to get their content included in the
204 # report.
205 self.kvm_fixture.run_command([
206 'sudo', 'cat', filename], check_call=False)
179207
180 def get_maas_api_client(self, api_key):208 def get_maas_api_client(self, api_key):
181 """Create and return a MAASClient.209 """Create and return a MAASClient.
182210
=== modified file 'maastest/main.py'
--- maastest/main.py 2013-11-21 13:39:24 +0000
+++ maastest/main.py 2013-11-22 10:41:25 +0000
@@ -48,11 +48,13 @@
48 cls.maas = MAASFixture(cls.machine)48 cls.maas = MAASFixture(cls.machine)
49 cls.maas.setUp()49 cls.maas.setUp()
50 except:50 except:
51 cls.maas.cleanUp()
51 cls.machine.cleanUp()52 cls.machine.cleanUp()
52 raise53 raise
5354
54 @classmethod55 @classmethod
55 def tearDownClass(cls):56 def tearDownClass(cls):
57 cls.maas.cleanUp()
56 cls.machine.cleanUp()58 cls.machine.cleanUp()
57 super(TestMAAS, cls).tearDownClass()59 super(TestMAAS, cls).tearDownClass()
5860
5961
=== modified file 'maastest/tests/test_maasfixture.py'
--- maastest/tests/test_maasfixture.py 2013-11-21 13:33:05 +0000
+++ maastest/tests/test_maasfixture.py 2013-11-22 10:41:25 +0000
@@ -335,6 +335,19 @@
335 ),335 ),
336 (call_mock.mock_calls, put_mock.mock_calls))336 (call_mock.mock_calls, put_mock.mock_calls))
337337
338 def test_collect_logs_collects_logs(self):
339 kvm_fixture = self.make_kvm_fixture()
340 maas_fixture = maasfixture.MAASFixture(kvm_fixture)
341
342 maas_fixture.collect_logs()
343
344 expected_calls = [
345 mock.call(['sudo', 'cat', filename], check_call=False)
346 for filename in maasfixture.LOG_FILES]
347 self.assertEqual(
348 expected_calls,
349 kvm_fixture.run_command.mock_calls)
350
338 def test_setUp_sets_admin_details(self):351 def test_setUp_sets_admin_details(self):
339 fixture = self.make_kvm_fixture()352 fixture = self.make_kvm_fixture()
340 maas_fixture = maasfixture.MAASFixture(fixture)353 maas_fixture = maasfixture.MAASFixture(fixture)
@@ -364,6 +377,26 @@
364 client_key,377 client_key,
365 ))378 ))
366379
380 def test_setUp_calls_cleanup_methods(self):
381 fixture = self.make_kvm_fixture()
382 maas_fixture = maasfixture.MAASFixture(fixture)
383 self.patch(
384 maas_fixture, 'query_api_key',
385 mock.MagicMock(return_value='fake:api:key'))
386 self.patch(
387 maas_fixture, 'collect_logs', mock.MagicMock())
388
389 with maas_fixture:
390 pass
391
392 self.assertEqual(
393 [
394 [mock.call()],
395 ],
396 [
397 maas_fixture.collect_logs.mock_calls,
398 ])
399
367 def test_setUp_calls_methods_if_direct_ip_set(self):400 def test_setUp_calls_methods_if_direct_ip_set(self):
368 fixture = self.make_kvm_fixture()401 fixture = self.make_kvm_fixture()
369 fixture.direct_ip = '127.11.24.38'402 fixture.direct_ip = '127.11.24.38'
@@ -419,16 +452,15 @@
419 maas_fixture.configure_cluster.mock_calls,452 maas_fixture.configure_cluster.mock_calls,
420 ])453 ])
421454
422 def test_import_mmas_images_imports_pxe_images(self):455 def test_import_maas_images_imports_pxe_images(self):
423 kvm_fixture = self.make_kvm_fixture()456 kvm_fixture = self.make_kvm_fixture()
424 self.patch(kvm_fixture, 'run_command', mock.MagicMock())
425 maas_fixture = maasfixture.MAASFixture(kvm_fixture)457 maas_fixture = maasfixture.MAASFixture(kvm_fixture)
426 maas_fixture.import_maas_images()458 maas_fixture.import_maas_images()
427 self.assertEqual(459 self.assertEqual(
428 mock.call([460 mock.call([
429 u'sudo',461 'sudo',
430 u'RELEASES=precise',462 'RELEASES=precise',
431 u'ARCHES=amd64/generic i386/generic',463 'ARCHES=amd64/generic i386/generic',
432 u'maas-import-pxe-files',464 'maas-import-pxe-files',
433 ], check_call=True),465 ], check_call=True),
434 kvm_fixture.run_command.mock_calls[-1])466 kvm_fixture.run_command.mock_calls[-1])

Subscribers

People subscribed via source and target branches