X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/65f13986f98a75f8da7cfe695ea5960ff741d402..48ee36541552d5394234d3057a6c1d5957f40d2e:/tools/crunchstat-summary/tests/test_examples.py diff --git a/tools/crunchstat-summary/tests/test_examples.py b/tools/crunchstat-summary/tests/test_examples.py index f5fde5fdc4..af92becd80 100644 --- a/tools/crunchstat-summary/tests/test_examples.py +++ b/tools/crunchstat-summary/tests/test_examples.py @@ -61,7 +61,7 @@ class SummarizeEdgeCases(unittest.TestCase): class SummarizeContainer(ReportDiff): fake_container = { - 'uuid': '9tee4-dz642-mjfb0i5hzojp16a', + 'uuid': '9tee4-dz642-lymtndkpy39eibk', 'created_at': '2017-08-18T14:27:25.371388141', 'log': '9tee4-4zz18-ihyzym9tcwjwg4r', } @@ -71,8 +71,12 @@ class SummarizeContainer(ReportDiff): 'created_at': '2017-08-18T14:27:25.242339223Z', 'container_uuid': fake_container['uuid'], } + reportfile = os.path.join( + TESTS_DIR, 'container_9tee4-dz642-lymtndkpy39eibk.txt.gz') logfile = os.path.join( - TESTS_DIR, 'container_9tee4-dz642-mjfb0i5hzojp16a-crunchstat.txt.gz') + TESTS_DIR, 'container_9tee4-dz642-lymtndkpy39eibk-crunchstat.txt.gz') + arvmountlog = os.path.join( + TESTS_DIR, 'container_9tee4-dz642-lymtndkpy39eibk-arv-mount.txt.gz') @mock.patch('arvados.collection.CollectionReader') @mock.patch('arvados.api') @@ -82,13 +86,18 @@ class SummarizeContainer(ReportDiff): mock_api().containers().get().execute.return_value = self.fake_container mock_cr().__iter__.return_value = [ 'crunch-run.txt', 'stderr.txt', 'node-info.txt', - 'container.json', 'crunchstat.txt'] - mock_cr().open.return_value = gzip.open(self.logfile) + 'container.json', 'crunchstat.txt', 'arv-mount.txt'] + def _open(n): + if n == "crunchstat.txt": + return gzip.open(self.logfile) + elif n == "arv-mount.txt": + return gzip.open(self.arvmountlog) + mock_cr().open.side_effect = _open args = crunchstat_summary.command.ArgumentParser().parse_args( ['--job', self.fake_request['uuid']]) cmd = crunchstat_summary.command.Command(args) cmd.run() - self.diff_known_report(self.logfile, cmd) + self.diff_known_report(self.reportfile, cmd) class SummarizeJob(ReportDiff): @@ -180,7 +189,7 @@ class SummarizePipeline(ReportDiff): job_report + ['\n'] + ['### Summary for bar (zzzzz-8i9sb-000000000000001)\n'] + job_report + ['\n'] + - ['### Summary for unfinished-job (zzzzz-8i9sb-xxxxxxxxxxxxxxx)\n', + ['### Summary for unfinished-job (partial) (zzzzz-8i9sb-xxxxxxxxxxxxxxx)\n', '(no report generated)\n', '\n'] + ['### Summary for baz (zzzzz-8i9sb-000000000000002)\n'] + @@ -193,3 +202,82 @@ class SummarizePipeline(ReportDiff): mock.call('fake-log-pdh-2'), ], any_order=True) mock_cr().open.assert_called_with('fake-logfile.txt') + + +class SummarizeACRJob(ReportDiff): + fake_job = { + 'uuid': 'zzzzz-8i9sb-i3e77t9z5y8j9cc', + 'owner_uuid': 'zzzzz-tpzed-xurymjxw79nv3jz', + 'components': { + 'foo': 'zzzzz-8i9sb-000000000000000', + 'bar': 'zzzzz-8i9sb-000000000000001', + 'unfinished-job': 'zzzzz-8i9sb-xxxxxxxxxxxxxxx', + 'baz': 'zzzzz-8i9sb-000000000000002', + } + } + fake_jobs_index = { 'items': [ + { + 'uuid': 'zzzzz-8i9sb-000000000000000', + 'log': 'fake-log-pdh-0', + 'runtime_constraints': { + 'min_ram_mb_per_node': 900, + 'min_cores_per_node': 1, + }, + }, + { + 'uuid': 'zzzzz-8i9sb-000000000000001', + 'log': 'fake-log-pdh-1', + 'runtime_constraints': { + 'min_ram_mb_per_node': 900, + 'min_cores_per_node': 1, + }, + }, + { + 'uuid': 'zzzzz-8i9sb-xxxxxxxxxxxxxxx', + }, + { + 'uuid': 'zzzzz-8i9sb-000000000000002', + 'log': 'fake-log-pdh-2', + 'runtime_constraints': { + 'min_ram_mb_per_node': 900, + 'min_cores_per_node': 1, + }, + }, + ]} + @mock.patch('arvados.collection.CollectionReader') + @mock.patch('arvados.api') + def test_acr_job(self, mock_api, mock_cr): + logfile = os.path.join(TESTS_DIR, 'logfile_20151204190335.txt.gz') + mock_api().jobs().index().execute.return_value = self.fake_jobs_index + mock_api().jobs().get().execute.return_value = self.fake_job + mock_cr().__iter__.return_value = ['fake-logfile.txt'] + mock_cr().open.side_effect = [gzip.open(logfile) for _ in range(3)] + args = crunchstat_summary.command.ArgumentParser().parse_args( + ['--job', self.fake_job['uuid']]) + cmd = crunchstat_summary.command.Command(args) + cmd.run() + + job_report = [ + line for line in open(logfile+'.report').readlines() + if not line.startswith('#!! ')] + expect = ( + ['### Summary for zzzzz-8i9sb-i3e77t9z5y8j9cc (partial) (zzzzz-8i9sb-i3e77t9z5y8j9cc)\n', + '(no report generated)\n', + '\n'] + + ['### Summary for bar (zzzzz-8i9sb-000000000000001)\n'] + + job_report + ['\n'] + + ['### Summary for baz (zzzzz-8i9sb-000000000000002)\n'] + + job_report + ['\n'] + + ['### Summary for foo (zzzzz-8i9sb-000000000000000)\n'] + + job_report + ['\n'] + + ['### Summary for unfinished-job (partial) (zzzzz-8i9sb-xxxxxxxxxxxxxxx)\n', + '(no report generated)\n'] + ) + self.diff_report(cmd, expect) + mock_cr.assert_has_calls( + [ + mock.call('fake-log-pdh-0'), + mock.call('fake-log-pdh-1'), + mock.call('fake-log-pdh-2'), + ], any_order=True) + mock_cr().open.assert_called_with('fake-logfile.txt')