Merge lp:~matsubara/tarmac/better-debug-output into lp:~launchpad/tarmac/lp-tarmac

Proposed by Diogo Matsubara
Status: Merged
Approved by: Gary Poster
Approved revision: 390
Merged at revision: 391
Proposed branch: lp:~matsubara/tarmac/better-debug-output
Merge into: lp:~launchpad/tarmac/lp-tarmac
Diff against target: 80 lines (+43/-2)
2 files modified
tarmac/plugins/bundlecommand.py (+12/-1)
tarmac/plugins/tests/test_bundlecommand.py (+31/-1)
To merge this branch: bzr merge lp:~matsubara/tarmac/better-debug-output
Reviewer Review Type Date Requested Status
Gary Poster (community) Approve
Review via email: mp+45267@code.launchpad.net

Commit message

[r=gary] Changes the bundle lander plugin to keep a persistent log file on disk.

Description of the change

This changes the bundle lander plugin to keep a persistent log file on disk. After an initial review from Gary, I added some more tests showing the the logs are correctly moved and replaced.

To post a comment you must log in.
Revision history for this message
Gary Poster (gary) wrote :

We could have yet more test coverage, but I'm OK with this for now

Thank you

Gary

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tarmac/plugins/bundlecommand.py'
2--- tarmac/plugins/bundlecommand.py 2010-12-17 14:19:01 +0000
3+++ tarmac/plugins/bundlecommand.py 2011-01-05 17:24:57 +0000
4@@ -153,7 +153,18 @@
5 self.logger.debug('Running test command: %s' % self.verify_command)
6 cwd = os.getcwd()
7 os.chdir(target.tree.abspath(''))
8- output = tempfile.TemporaryFile()
9+ # Output must be logged and kept in the filesystem to help debugging.
10+ current_log = os.path.join(
11+ target.config.debug_log_location, 'current.log')
12+ previous_log = os.path.join(
13+ target.config.debug_log_location, 'previous.log')
14+ if os.path.exists(current_log):
15+ # Move it out of the way. Trashes previous.log.
16+ os.rename(current_log, previous_log)
17+ # Create a new empty file to log the output.
18+ open(current_log, 'w').close()
19+ # File must be opened for read and write.
20+ output = open(current_log, 'rw')
21 try:
22 proc = subprocess.Popen(
23 self.verify_command,
24
25=== modified file 'tarmac/plugins/tests/test_bundlecommand.py'
26--- tarmac/plugins/tests/test_bundlecommand.py 2010-12-17 12:58:39 +0000
27+++ tarmac/plugins/tests/test_bundlecommand.py 2011-01-05 17:24:57 +0000
28@@ -223,7 +223,8 @@
29 def test_run(self):
30 """Test that the plug-in run without errors."""
31 target = Thing(config=Thing(
32- bundle_verify_command="/bin/true"),
33+ bundle_verify_command="/bin/true",
34+ debug_log_location=self.TEST_ROOT),
35 tree=Thing(abspath=os.path.abspath))
36 self.plugin.run(
37 command=self.command, target=target, restore_revno=123,
38@@ -244,6 +245,7 @@
39 target = self.branch1
40 # Include the config to run the bundle verify command.
41 setattr(target.config, 'bundle_verify_command', '/bin/false')
42+ setattr(target.config, 'debug_log_location', self.TEST_ROOT)
43 # Set a fake method to target, so we can make sure it's called when
44 # the plugin fails to run.
45 def fake_uncommit_and_revert(restore_revno):
46@@ -279,6 +281,34 @@
47 # Check the patched target.uncommit_and_revert() was run.
48 self.assertEqual(target.fake_revno, 123)
49
50+ def test_debug_log(self):
51+ """Test logs are kept after plugin run."""
52+ current_log = os.path.join(self.TEST_ROOT, 'current.log')
53+ previous_log = os.path.join(self.TEST_ROOT, 'previous.log')
54+ self.assertFalse(os.path.exists(current_log))
55+ # Create a fake log file in current.log, so it can be moved to
56+ # previous.log
57+ log_file = open(current_log, 'w')
58+ log_file.write('Foobar')
59+ log_file.close()
60+ # Set up config for plugin.
61+ target = Thing(config=Thing(
62+ bundle_verify_command='/bin/true',
63+ debug_log_location=self.TEST_ROOT),
64+ tree=Thing(abspath=os.path.abspath))
65+ # Run.
66+ self.plugin.run(
67+ command=self.command, target=target, restore_revno=123,
68+ collected_proposals=self.collected_proposals)
69+ # Check we have current.log in place with no content since /bin/true
70+ # doesn't actually gives any output.
71+ self.assertTrue(os.path.exists(current_log))
72+ self.assertEqual('', open(current_log, 'r').read())
73+ # Check fake log was moved correctly to previous.log and the content
74+ # match.
75+ self.assertTrue(os.path.exists(previous_log))
76+ self.assertEqual('Foobar', open(previous_log, 'r').read())
77+
78 def test_send_report_email(self):
79 """Test send_report_email()."""
80 formatter = self.make_formatter()

Subscribers

People subscribed via source and target branches

to all changes: