From bac2965af6d991acf4cce685842ced74bbe9c684 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Mon, 14 Oct 2013 16:34:45 -0500 Subject: [PATCH] ResultsSerializer.running_jobs_for_run() and test Signed-off-by: Zack Cerza --- teuthology/report.py | 13 +++++++++++++ teuthology/test/fake_archive.py | 9 +++++++-- teuthology/test/test_report.py | 11 +++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/teuthology/report.py b/teuthology/report.py index eb425f8c97..d9a83efd61 100644 --- a/teuthology/report.py +++ b/teuthology/report.py @@ -115,6 +115,19 @@ class ResultsSerializer(object): jobs[job_id] = job_dir return jobs + def running_jobs_for_run(self, run_name): + """ + Like jobs_for_run(), but only returns jobs with no summary.yaml + + :param run_name: The name of the run. + :returns: A dict like: {'1': '/path/to/1', '2': 'path/to/2'} + """ + jobs = self.jobs_for_run(run_name) + for name in jobs.keys(): + if not os.path.exists(os.path.join(jobs[name], 'summary.yaml')): + jobs.pop(name) + return jobs + @property def all_runs(self): """ diff --git a/teuthology/test/fake_archive.py b/teuthology/test/fake_archive.py index 0a4f2af1ac..38d5864b50 100644 --- a/teuthology/test/fake_archive.py +++ b/teuthology/test/fake_archive.py @@ -79,7 +79,7 @@ class FakeArchive(object): with file(summary_path, 'w') as yfile: yaml.safe_dump(job['summary'], yfile) - def create_fake_run(self, run_name, job_count, yaml_path): + def create_fake_run(self, run_name, job_count, yaml_path, num_hung=0): """ Creates a fake run using run_name. Uses the YAML specified for each job's config.yaml @@ -89,8 +89,13 @@ class FakeArchive(object): assert os.path.exists(yaml_path) assert job_count > 0 jobs = [] + made_hung = 0 for i in range(job_count): - jobs.append(self.get_random_metadata(run_name)) + if made_hung < num_hung: + jobs.append(self.get_random_metadata(run_name, hung=True)) + made_hung += 1 + else: + jobs.append(self.get_random_metadata(run_name, hung=False)) #job_config = yaml.safe_load(yaml_path) self.populate_archive(run_name, jobs) for job in jobs: diff --git a/teuthology/test/test_report.py b/teuthology/test/test_report.py index 26501afd4e..804254da43 100644 --- a/teuthology/test/test_report.py +++ b/teuthology/test/test_report.py @@ -45,6 +45,17 @@ class TestSerializer(object): got_jobs = self.reporter.serializer.jobs_for_run(run_name) assert sorted(job_ids) == sorted(got_jobs.keys()) + def test_running_jobs_for_run(self): + run_name = "test_jobs_for_run" + yaml_path = "examples/3node_ceph.yaml" + job_count = 10 + num_hung = 3 + self.archive.create_fake_run(run_name, job_count, yaml_path, + num_hung=num_hung) + + got_jobs = self.reporter.serializer.running_jobs_for_run(run_name) + assert len(got_jobs) == job_count - num_hung + def test_json_for_job(self): run_name = "test_json_for_job" yaml_path = "examples/3node_ceph.yaml" -- 2.39.5