def save_report(self, results): for result in results: if result['result'] == 'Passed': self.success.append(result['suite']) elif result['result'] == 'Failed': self.failures.append(result['suite']) self.time_of_tests[result['suite']] = { 'duration': result.get('duration', '0s')} LOG.info(" * %s --- %s", result['result'], result['suite']) reporter = Reporter(os.path.dirname(__file__)) for record in results: reporter.save_report( os.path.join(self.path, record['suite'] + '.html'), 'ostf_template.html', {'reports': results} )
def _run_ostf_on_docker(self, task): # The task can be either a test or suite if ':' in task: _cmd = 'run_test' _arg = '--test' else: _cmd = 'run_suite' _arg = '--suite' cmd = ('docker exec -t {cid} ' '/mcv/execute.sh fuel-ostf.{mos_version} ' '"cloudvalidation-cli ' '--output-file={home}/ostf_report.json ' '--config-file={home}/conf/{conf_fname} ' 'cloud-health-check {cmd} ' '--validation-plugin-name fuel_health {arg} {task}"' ).format(cid=self.container_id, mos_version=self.mos_version, home=self.home, conf_fname=self.config_filename, cmd=_cmd, arg=_arg, task=task) utils.run_cmd(cmd) try: results = [] try: fpath = os.path.join(self.homedir, 'ostf_report.json') with open(fpath) as fp: results = json.load(fp) os.remove(fpath) # TODO(albartash): check if we need LOG.error here except IOError as e: LOG.error(('Error while extracting report ' 'from OSTF container: {err_msg}').format( err_msg=str(e))) except OSError as e: LOG.error(('Error while removing report ' 'file from container: {err_msg}').format( err_msg=str(e))) except ValueError as e: LOG.error(('Error while parsing report file: {' 'err_msg}').format(err_msg=str(e))) def fix_suite(result): result['suite'] = result['suite'].split(':')[1] return result map(fix_suite, results) # store raw results self.dump_raw_results(task, results) for result in results: if result['result'] == 'Passed': self.success.append(result['suite']) elif result['result'] == 'Failed': self.failures.append(result['suite']) self.time_of_tests[result['suite']] = { 'duration': result.get('duration', '0s')} LOG.info(" * %s --- %s" % (result['result'], result['suite'])) reporter = Reporter(os.path.dirname(__file__)) for record in results: reporter.save_report( os.path.join(self.path, record['suite'] + '.html'), 'ostf_template.html', {'reports': results} ) except subprocess.CalledProcessError as e: LOG.error("Task %s has failed with: %s" % (task, e)) self.failures.append(task) self.time_of_tests[task] = {'duration': '0s'} return