def test_log_file_collection(self): self.build.updateStatus(BuildStatus.FULLYBUILT) old_tmps = sorted(os.listdir('/tmp')) slave = WaitingSlave('BuildStatus.OK') def got_log(logfile_lfa_id): # Grabbing logs should not leave new files in /tmp (bug #172798) logfile_lfa = getUtility(ILibraryFileAliasSet)[logfile_lfa_id] new_tmps = sorted(os.listdir('/tmp')) self.assertEqual(old_tmps, new_tmps) # The new librarian file is stored compressed with a .gz # extension and text/plain file type for easy viewing in # browsers, as it decompresses and displays the file inline. self.assertTrue( logfile_lfa.filename.endswith('_FULLYBUILT.txt.gz')) self.assertEqual('text/plain', logfile_lfa.mimetype) self.layer.txn.commit() # LibrarianFileAlias does not implement tell() or seek(), which # are required by gzip.open(), so we need to read the file out # of the librarian first. fd, fname = tempfile.mkstemp() self.addCleanup(os.remove, fname) tmp = os.fdopen(fd, 'wb') tmp.write(logfile_lfa.read()) tmp.close() uncompressed_file = gzip.open(fname).read() # Now make a temp filename that getFile() can write to. fd, tmp_orig_file_name = tempfile.mkstemp() self.addCleanup(os.remove, tmp_orig_file_name) # Check that the original file from the slave matches the # uncompressed file in the librarian. def got_orig_log(ignored): orig_file_content = open(tmp_orig_file_name).read() self.assertEqual(orig_file_content, uncompressed_file) d = removeSecurityProxy(slave).getFile( 'buildlog', tmp_orig_file_name) return d.addCallback(got_orig_log) behavior = IBuildFarmJobBehavior(self.candidate.specific_job) behavior.setBuilder(self.builder, slave) d = behavior.getLogFromSlave(self.build.buildqueue_record) return d.addCallback(got_log)
def test_log_file_collection(self): self.build.updateStatus(BuildStatus.FULLYBUILT) old_tmps = sorted(os.listdir('/tmp')) slave = WaitingSlave('BuildStatus.OK') def got_log(logfile_lfa_id): # Grabbing logs should not leave new files in /tmp (bug #172798) logfile_lfa = getUtility(ILibraryFileAliasSet)[logfile_lfa_id] new_tmps = sorted(os.listdir('/tmp')) self.assertEqual(old_tmps, new_tmps) # The new librarian file is stored compressed with a .gz # extension and text/plain file type for easy viewing in # browsers, as it decompresses and displays the file inline. self.assertTrue( logfile_lfa.filename.endswith('_FULLYBUILT.txt.gz')) self.assertEqual('text/plain', logfile_lfa.mimetype) self.layer.txn.commit() # LibrarianFileAlias does not implement tell() or seek(), which # are required by gzip.open(), so we need to read the file out # of the librarian first. fd, fname = tempfile.mkstemp() self.addCleanup(os.remove, fname) tmp = os.fdopen(fd, 'wb') tmp.write(logfile_lfa.read()) tmp.close() uncompressed_file = gzip.open(fname).read() # Now make a temp filename that getFile() can write to. fd, tmp_orig_file_name = tempfile.mkstemp() self.addCleanup(os.remove, tmp_orig_file_name) # Check that the original file from the slave matches the # uncompressed file in the librarian. def got_orig_log(ignored): orig_file_content = open(tmp_orig_file_name).read() self.assertEqual(orig_file_content, uncompressed_file) d = removeSecurityProxy(slave).getFile('buildlog', tmp_orig_file_name) return d.addCallback(got_orig_log) behavior = IBuildFarmJobBehavior(self.candidate.specific_job) behavior.setBuilder(self.builder, slave) d = behavior.getLogFromSlave(self.build.buildqueue_record) return d.addCallback(got_log)