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
1=== modified file 'maastest/maasfixture.py'
2--- maastest/maasfixture.py 2013-11-21 13:33:05 +0000
3+++ maastest/maasfixture.py 2013-11-22 10:41:25 +0000
4@@ -56,6 +56,23 @@
5 config_file,
6 ]
7
8+# Log files that are interesting when debugging MAAS issues. They will
9+# be collected just before the fixture is disposed of.
10+LOG_FILES = [
11+ # Syslog contains DHCP requests.
12+ '/var/log/syslog',
13+ # DHCP lease file.
14+ '/var/lib/maas/dhcp/dhcpd.leases',
15+ # MAAS logs.
16+ '/var/log/maas/maas.log',
17+ '/var/log/maas/pserv.log',
18+ '/var/log/maas/celery-region.log',
19+ '/var/log/maas/celery.log',
20+ # Apache logs.
21+ '/var/log/apache2/access.log',
22+ '/var/log/apache2/error.log',
23+]
24+
25
26 class MAASFixture(Fixture):
27 """A fixture for a MAAS server."""
28@@ -176,6 +193,17 @@
29 if self.kvm_fixture.direct_ip is not None:
30 self.check_cluster_connected()
31 self.configure_cluster()
32+ # Cleanups registration.
33+ self.addCleanup(self.collect_logs)
34+
35+ def collect_logs(self):
36+ for filename in LOG_FILES:
37+ # The result of every command run on the VM goes through
38+ # testtools.TestCase.addDetail() so we just need to
39+ # 'cat' the files to get their content included in the
40+ # report.
41+ self.kvm_fixture.run_command([
42+ 'sudo', 'cat', filename], check_call=False)
43
44 def get_maas_api_client(self, api_key):
45 """Create and return a MAASClient.
46
47=== modified file 'maastest/main.py'
48--- maastest/main.py 2013-11-21 13:39:24 +0000
49+++ maastest/main.py 2013-11-22 10:41:25 +0000
50@@ -48,11 +48,13 @@
51 cls.maas = MAASFixture(cls.machine)
52 cls.maas.setUp()
53 except:
54+ cls.maas.cleanUp()
55 cls.machine.cleanUp()
56 raise
57
58 @classmethod
59 def tearDownClass(cls):
60+ cls.maas.cleanUp()
61 cls.machine.cleanUp()
62 super(TestMAAS, cls).tearDownClass()
63
64
65=== modified file 'maastest/tests/test_maasfixture.py'
66--- maastest/tests/test_maasfixture.py 2013-11-21 13:33:05 +0000
67+++ maastest/tests/test_maasfixture.py 2013-11-22 10:41:25 +0000
68@@ -335,6 +335,19 @@
69 ),
70 (call_mock.mock_calls, put_mock.mock_calls))
71
72+ def test_collect_logs_collects_logs(self):
73+ kvm_fixture = self.make_kvm_fixture()
74+ maas_fixture = maasfixture.MAASFixture(kvm_fixture)
75+
76+ maas_fixture.collect_logs()
77+
78+ expected_calls = [
79+ mock.call(['sudo', 'cat', filename], check_call=False)
80+ for filename in maasfixture.LOG_FILES]
81+ self.assertEqual(
82+ expected_calls,
83+ kvm_fixture.run_command.mock_calls)
84+
85 def test_setUp_sets_admin_details(self):
86 fixture = self.make_kvm_fixture()
87 maas_fixture = maasfixture.MAASFixture(fixture)
88@@ -364,6 +377,26 @@
89 client_key,
90 ))
91
92+ def test_setUp_calls_cleanup_methods(self):
93+ fixture = self.make_kvm_fixture()
94+ maas_fixture = maasfixture.MAASFixture(fixture)
95+ self.patch(
96+ maas_fixture, 'query_api_key',
97+ mock.MagicMock(return_value='fake:api:key'))
98+ self.patch(
99+ maas_fixture, 'collect_logs', mock.MagicMock())
100+
101+ with maas_fixture:
102+ pass
103+
104+ self.assertEqual(
105+ [
106+ [mock.call()],
107+ ],
108+ [
109+ maas_fixture.collect_logs.mock_calls,
110+ ])
111+
112 def test_setUp_calls_methods_if_direct_ip_set(self):
113 fixture = self.make_kvm_fixture()
114 fixture.direct_ip = '127.11.24.38'
115@@ -419,16 +452,15 @@
116 maas_fixture.configure_cluster.mock_calls,
117 ])
118
119- def test_import_mmas_images_imports_pxe_images(self):
120+ def test_import_maas_images_imports_pxe_images(self):
121 kvm_fixture = self.make_kvm_fixture()
122- self.patch(kvm_fixture, 'run_command', mock.MagicMock())
123 maas_fixture = maasfixture.MAASFixture(kvm_fixture)
124 maas_fixture.import_maas_images()
125 self.assertEqual(
126 mock.call([
127- u'sudo',
128- u'RELEASES=precise',
129- u'ARCHES=amd64/generic i386/generic',
130- u'maas-import-pxe-files',
131+ 'sudo',
132+ 'RELEASES=precise',
133+ 'ARCHES=amd64/generic i386/generic',
134+ 'maas-import-pxe-files',
135 ], check_call=True),
136 kvm_fixture.run_command.mock_calls[-1])

Subscribers

People subscribed via source and target branches