Merge lp:~mars/tarmac/fix-test-command-call into lp:~launchpad/tarmac/lp-tarmac

Proposed by Māris Fogels
Status: Merged
Approved by: Māris Fogels
Approved revision: 394
Merged at revision: 393
Proposed branch: lp:~mars/tarmac/fix-test-command-call
Merge into: lp:~launchpad/tarmac/lp-tarmac
Diff against target: 90 lines (+29/-28)
1 file modified
tarmac/plugins/bundlecommand.py (+29/-28)
To merge this branch: bzr merge lp:~mars/tarmac/fix-test-command-call
Reviewer Review Type Date Requested Status
Gary Poster (community) Approve
Review via email: mp+45767@code.launchpad.net

Commit message

Fixed calling the program defined by bundle_verify_command.

Description of the change

Hi,

This branch fixes calls to the program defined by bundle_verify_command. The subprocess call for the command must use a file that is opened in 'w' mode, not 'rw'.

I also took a moment to clean up how the current working directory for the subprocess is set. I added comments and whitespace to make the function body more readable.

Maris

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

Looks good, thank you.

As the smallest of niggles, line 37 of the diff feels like a bit too much whitespace within the function to me, but that's one of those "sprinkle to taste" things. Just a thought.

Thanks again

Gary

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tarmac/plugins/bundlecommand.py'
--- tarmac/plugins/bundlecommand.py 2011-01-05 17:09:54 +0000
+++ tarmac/plugins/bundlecommand.py 2011-01-10 22:15:30 +0000
@@ -136,6 +136,7 @@
136 proposals merged into target and then runs the verify command.136 proposals merged into target and then runs the verify command.
137 Updating the list of proposals in case of failure.137 Updating the list of proposals in case of failure.
138 """138 """
139 # Try and find the command that runs the test suite.
139 try:140 try:
140 self.verify_command = target.config.bundle_verify_command141 self.verify_command = target.config.bundle_verify_command
141 except AttributeError:142 except AttributeError:
@@ -149,11 +150,7 @@
149 except AttributeError:150 except AttributeError:
150 return151 return
151152
152 start_time = datetime.datetime.utcnow()153 # Rotate the test output logs.
153 self.logger.debug('Running test command: %s' % self.verify_command)
154 cwd = os.getcwd()
155 os.chdir(target.tree.abspath(''))
156 # Output must be logged and kept in the filesystem to help debugging.
157 current_log = os.path.join(154 current_log = os.path.join(
158 target.config.debug_log_location, 'current.log')155 target.config.debug_log_location, 'current.log')
159 previous_log = os.path.join(156 previous_log = os.path.join(
@@ -161,39 +158,43 @@
161 if os.path.exists(current_log):158 if os.path.exists(current_log):
162 # Move it out of the way. Trashes previous.log.159 # Move it out of the way. Trashes previous.log.
163 os.rename(current_log, previous_log)160 os.rename(current_log, previous_log)
164 # Create a new empty file to log the output.161
165 open(current_log, 'w').close()162 # Run our test command.
166 # File must be opened for read and write.163 start_time = datetime.datetime.utcnow()
167 output = open(current_log, 'rw')164 self.logger.debug('Running test command: %s' % self.verify_command)
165
166 output = open(current_log, 'w')
168 try:167 try:
169 proc = subprocess.Popen(168 proc = subprocess.Popen(
170 self.verify_command,169 self.verify_command,
171 shell=True,170 shell=True,
171 cwd=target.tree.abspath(''),
172 stdout=output,172 stdout=output,
173 stderr=subprocess.STDOUT)173 stderr=subprocess.STDOUT)
174 return_code = proc.wait()174 return_code = proc.wait()
175 output.seek(0)
176 os.chdir(cwd)
177 self.logger.debug('Completed test command: %s' % self.verify_command)
178 end_time = datetime.datetime.utcnow()
179
180 if return_code != 0:
181 for source, proposal in collected_proposals:
182 self.do_failed(
183 target, start_time, end_time, proposal, output)
184 # XXX matsubara 2010-12-17: The command code should be
185 # handling this, but due to the way we want emails formatted
186 # and sent, this is done here for now.
187 # See bug 691563 for more details.
188 # Uncommit and revert changes up to the point where target
189 # was before the merge.
190 target.uncommit_and_revert(restore_revno)
191 else:
192 self.logger.info('==========')
193 self.logger.info(output.read())
194 finally:175 finally:
195 output.close()176 output.close()
196177
178 self.logger.debug('Completed test command: %s' % self.verify_command)
179 end_time = datetime.datetime.utcnow()
180
181 # Handle the test command output.
182 testlog = open(current_log)
183 if return_code != 0:
184 for source, proposal in collected_proposals:
185 self.do_failed(
186 target, start_time, end_time, proposal, testlog)
187 # XXX matsubara 2010-12-17: The command code should be
188 # handling this, but due to the way we want emails formatted
189 # and sent, this is done here for now.
190 # See bug 691563 for more details.
191 # Uncommit and revert changes up to the point where target
192 # was before the merge.
193 target.uncommit_and_revert(restore_revno)
194 else:
195 self.logger.info('==========')
196 self.logger.info(testlog.read())
197
197 def do_failed(self, target, start_time, end_time, proposal, output):198 def do_failed(self, target, start_time, end_time, proposal, output):
198 '''Perform failure tests.199 '''Perform failure tests.
199200

Subscribers

People subscribed via source and target branches

to all changes: