From: Tom Clegg Date: Wed, 6 Sep 2017 21:06:23 +0000 (-0400) Subject: 10472: Un-bork text reports. X-Git-Tag: 1.1.0~59^2~6 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/bc4e237bdbd23418fa21b7f13285deec2c079f0d 10472: Un-bork text reports. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- diff --git a/tools/crunchstat-summary/crunchstat_summary/reader.py b/tools/crunchstat-summary/crunchstat_summary/reader.py index c215228ff5..e8f0861be4 100644 --- a/tools/crunchstat-summary/crunchstat_summary/reader.py +++ b/tools/crunchstat-summary/crunchstat_summary/reader.py @@ -94,3 +94,9 @@ class LiveLogReader(object): self._thread.join() raise StopIteration return line + + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + pass diff --git a/tools/crunchstat-summary/crunchstat_summary/summarizer.py b/tools/crunchstat-summary/crunchstat_summary/summarizer.py index 6e08c5e1b0..6552708845 100644 --- a/tools/crunchstat-summary/crunchstat_summary/summarizer.py +++ b/tools/crunchstat-summary/crunchstat_summary/summarizer.py @@ -227,6 +227,8 @@ class Summarizer(object): def long_label(self): label = self.label + if hasattr(self, 'process') and self.process['uuid'] not in label: + label = '{} ({})'.format(label, self.process['uuid']) if self.finishtime: label += ' -- elapsed time ' s = (self.finishtime - self.starttime).total_seconds() @@ -528,10 +530,11 @@ class MultiSummarizer(object): def text_report(self): txt = '' - for cname, child in self._descendants(): - if len(self.children) > 1: + d = self._descendants() + for cname, child in d.iteritems(): + if len(d) > 1: txt += '### Summary for {} ({})\n'.format( - cname, child.process['uuid']) + child.label, child.process['uuid']) txt += child.text_report() txt += '\n' return txt @@ -539,12 +542,13 @@ class MultiSummarizer(object): def _descendants(self): """Dict of self and all descendants. - Wrappers with nothing of their own to report are omitted. + Nodes with nothing of their own to report (like + MultiSummarizers) are omitted. """ d = collections.OrderedDict() - for cname, child in self.children.iteritems(): + for key, child in self.children.iteritems(): if isinstance(child, Summarizer): - d[cname] = child + d[key] = child if isinstance(child, MultiSummarizer): d.update(child._descendants()) return d @@ -557,14 +561,10 @@ class JobTreeSummarizer(MultiSummarizer): """Summarizes a job and all children listed in its components field.""" def __init__(self, job, label=None, **kwargs): arv = arvados.api('v1', model=OrderedJsonModel()) - label = label or job.get('name', None) - if label is None: - label = job['uuid'] - else: - label = ' '.join([label, job['uuid']]) + label = label or job.get('name', job['uuid']) children = collections.OrderedDict() children[job['uuid']] = JobSummarizer(job, label=label, **kwargs) - if job['components']: + if job.get('components', None): preloaded = {} for j in arv.jobs().index( limit=len(job['components']), @@ -592,7 +592,7 @@ class PipelineSummarizer(MultiSummarizer): else: logger.info( "%s: job %s", cname, component['job']['uuid']) - summarizer = JobTreeSummarizer(component['job'], **kwargs) + summarizer = JobTreeSummarizer(component['job'], label=cname, **kwargs) summarizer.label = '{} {}'.format( cname, component['job']['uuid']) children[cname] = summarizer diff --git a/tools/crunchstat-summary/tests/test_examples.py b/tools/crunchstat-summary/tests/test_examples.py index f5fde5fdc4..ecc8b9d300 100644 --- a/tools/crunchstat-summary/tests/test_examples.py +++ b/tools/crunchstat-summary/tests/test_examples.py @@ -180,7 +180,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'] +