def test_build_email_body(self): run_name = self.reference['run_name'] with patch.multiple( report, ResultsReporter=DEFAULT, ): reporter = report.ResultsReporter() reporter.get_jobs.return_value = self.reference['jobs'] (subject, body) = results.build_email_body( run_name, _reporter=reporter) assert subject == self.reference['subject'] assert body == self.reference['body']
def kill_run(run_name, archive_base=None, owner=None, machine_type=None, preserve_queue=False): run_info = {} serializer = report.ResultsSerializer(archive_base) if archive_base: run_archive_dir = os.path.join(archive_base, run_name) if os.path.isdir(run_archive_dir): run_info = find_run_info(serializer, run_name) if 'machine_type' in run_info: machine_type = run_info['machine_type'] owner = run_info['owner'] else: log.warning("The run info does not have machine type: %s" % run_info) log.warning("Run archive used: %s" % run_archive_dir) log.info("Using machine type '%s' and owner '%s'" % (machine_type, owner)) elif machine_type is None: # no jobs found in archive and no machine type specified, # so we try paddles to see if there is anything scheduled run_info = report.ResultsReporter().get_run(run_name) machine_type = run_info.get('machine_type', None) if machine_type: log.info( f"Using machine type '{machine_type}' received from paddles." ) else: raise RuntimeError( f"Cannot find machine type for the run {run_name}; " + "you must also pass --machine-type") if not preserve_queue: remove_beanstalk_jobs(run_name, machine_type) remove_paddles_jobs(run_name) kill_processes(run_name, run_info.get('pids')) if owner is not None: targets = find_targets(run_name, owner) nuke_targets(targets, owner)
def remove_paddles_jobs(run_name): jobs = report.ResultsReporter().get_jobs(run_name, fields=['status']) job_ids = [job['job_id'] for job in jobs if job['status'] == 'queued'] if job_ids: log.info("Deleting jobs from paddles: %s", str(job_ids)) report.try_delete_jobs(run_name, job_ids)
def setup(self): self.archive = fake_archive.FakeArchive() self.archive.setup() self.archive_base = self.archive.archive_base self.reporter = report.ResultsReporter(archive_base=self.archive_base)