def _get_run_attachments(test_run_dir, testdef, stdout): attachments = [create_attachment('stdout.log', stdout), create_attachment('testdef.yaml', testdef)] return_code = read_content(os.path.join(test_run_dir, 'return_code'), ignore_missing=True) if return_code: attachments.append(create_attachment('return_code', return_code)) attachments.extend( _attachments_from_dir(os.path.join(test_run_dir, 'attachments'))) return attachments
def _get_run_attachments(test_run_dir, testdef, stdout): attachments = [ create_attachment('stdout.log', stdout), create_attachment('testdef.yaml', testdef) ] return_code = read_content(os.path.join(test_run_dir, 'return_code'), ignore_missing=True) if return_code: attachments.append(create_attachment('return_code', return_code)) attachments.extend( _attachments_from_dir(os.path.join(test_run_dir, 'attachments'))) return attachments
def _get_results_from_host(self): bundles = [] errors = [] try: bundle_list = os.listdir(self.context.host_result_dir) for bundle_name in bundle_list: bundle = "%s/%s" % (self.context.host_result_dir, bundle_name) content = None try: with open(bundle) as f: doc = DocumentIO.load(f)[1] DocumentEvolution.evolve_document(doc) bundles.append(doc) except ValueError: msg = 'Error adding host result bundle %s' % bundle errors.append(msg) logging.exception(msg) if content: logging.info('Adding bundle as attachment') attachment = create_attachment(bundle, content) self.context.test_data.add_attachments([attachment]) except: msg = 'Error getting all results from host' logging.exception(msg) raise GatherResultsError(msg, bundles) if len(errors) > 0: msg = ' '.join(errors) raise GatherResultsError(msg, bundles) return bundles
def _get_bundles(self, files): bundles = [] errors = [] for fname in files: if os.path.splitext(fname)[1] != ".bundle": continue content = None try: with open(fname, 'r') as f: doc = DocumentIO.load(f)[1] DocumentEvolution.evolve_document(doc) bundles.append(doc) except ValueError: msg = 'Error adding result bundle %s' % fname errors.append(msg) logging.exception(msg) if content: logging.info('Adding bundle as attachment') attachment = create_attachment(fname, content) self.context.test_data.add_attachments([attachment]) except KeyboardInterrupt: raise KeyboardInterrupt except: msg = 'Unknown error processing bundle' % fname logging.exception(msg) errors.append(msg) if len(errors) > 0: msg = ' '.join(errors) raise GatherResultsError(msg, bundles) return bundles
def get_test_data_attachments(self): """returns attachments to go in the "lava_results" test run""" # if the simulator never got started we won't even get to a logfile if getattr(self._sim_proc, 'logfile', None) is not None: if getattr(self._sim_proc.logfile, 'getvalue', None) is not None: content = self._sim_proc.logfile.getvalue() return [create_attachment('rtsm.log', content)] return []
def _get_test_runs(self): now = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ') attachment = [create_attachment(os.path.basename(self._logfile), read_content(self._logfile))] results = self._get_test_results() return { 'test_id': 'lava-command', 'analyzer_assigned_date': now, 'analyzer_assigned_uuid': str(uuid4()), 'time_check_performed': False, 'test_results': results, 'attachments': attachment }
def postprocess_test_result(self, test_result, case_data): with self._result_as_dir(test_result) as result_dir: case_data['postprocess_test_result_output'] = self._invoke_hook( 'postprocess_test_result', case_data['case_dir'], [result_dir]) for key in 'start_testcase_output', 'end_testcase_output', \ 'postprocess_test_result_output': path = case_data.get(key) if path is None: continue content = read_content(path, ignore_missing=True) if content: test_result['attachments'].append( create_attachment(key + '.txt', read_content(path)))
def _attachments_from_dir(from_dir): attachments = [] if from_dir: for dirpath, dirnames, filenames in os.walk(from_dir): for f in filenames: if f.endswith('.mimetype'): continue filepath = os.path.join(dirpath, f) mime_type = read_content(filepath + '.mimetype', ignore_missing=True).strip() if not mime_type: mime_type = mimetypes.guess_type(filepath)[0] if mime_type is None: mime_type = 'application/octet-stream' filename = filepath[len(from_dir) + 1:] attachments.append( create_attachment(filename, read_content(filepath), mime_type)) return attachments