Skip to content

Commit

Permalink
Merge pull request #1363 from ESMCI/jgfouca/big_cs_status_upgrade
Browse files Browse the repository at this point in the history
Big cs.status upgrade
  • Loading branch information
jedwards4b authored Apr 17, 2017
2 parents dd5a30b + ad0a5c1 commit d0e277d
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 67 deletions.
83 changes: 83 additions & 0 deletions scripts/Tools/cs.status
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env python
"""
List test results based on TestStatus files. Returns True if
no errors occured (not based on test statuses).
"""

from standard_script_setup import *
import argparse, sys, os, logging, glob
from CIME.test_status import *

###############################################################################
def parse_command_line(args, description):
###############################################################################
parser = argparse.ArgumentParser(
usage="""\n%s <Glob of TestStatus> [<Path/Glob to TestStatus> ...] [--verbose]
OR
%s --help
OR
%s --test
\033[1mEXAMPLES:\033[0m
\033[1;32m# Wait for all tests in a test area\033[0m
> %s path/to/testarea/*/TestStatus
""" % ((os.path.basename(args[0]), ) * 4),

description=description,

formatter_class=argparse.ArgumentDefaultsHelpFormatter
)

parser.add_argument("paths", nargs="*", help="Paths to TestStatus files.")

parser.add_argument("-s", "--summary", action="store_true",
help="Only show summary")

parser.add_argument("-t", "--test-id", action="append", default=[],
help="Only show summary")

parser.add_argument("-r", "--test-root", default=os.getcwd(),
help="Only show summary")

args = parser.parse_args(args[1:])

return args.paths, args.summary, args.test_id, args.test_root

###############################################################################
def cs_status(test_paths, summary=False):
###############################################################################
test_id_output = {}
for test_path in test_paths:
test_dir=os.path.dirname(test_path)
ts = TestStatus(test_dir=test_dir)
test_id = os.path.basename(test_dir).split(".")[-1]
test_name = ts.get_name()
status = ts.get_overall_test_status()
if not summary:
output = " %s (Overall: %s) details:\n" % (test_name, status)
output += ts.phase_statuses_dump(prefix=" ")
else:
output = " %s %s\n" % (status, test_name)

if test_id in test_id_output:
test_id_output[test_id] += output
else:
test_id_output[test_id] = output

for test_id in sorted(test_id_output):
print test_id
print test_id_output[test_id],

###############################################################################
def _main_func(description):
###############################################################################
test_paths, summary, test_ids, test_root = parse_command_line(sys.argv, description)
for test_id in test_ids:
test_paths.extend(glob.glob(os.path.join(test_root, "*%s/TestStatus" % test_id)))

cs_status(test_paths, summary)

###############################################################################

if (__name__ == "__main__"):
_main_func(__doc__)
60 changes: 0 additions & 60 deletions scripts/Tools/cs_status

This file was deleted.

3 changes: 2 additions & 1 deletion scripts/lib/CIME/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,8 @@ def _setup_cs_files(self):
template = open(template_file, "r").read()
template = template.replace("<PATH>",
os.path.join(self._cime_root,"scripts","Tools")).replace\
("<TESTID>", self._test_id)
("<TESTID>", self._test_id).replace\
("<TESTROOT>", self._test_root)
if not os.path.exists(self._test_root):
os.makedirs(self._test_root)
cs_status_file = os.path.join(self._test_root, "cs.status.%s" % self._test_id)
Expand Down
12 changes: 7 additions & 5 deletions scripts/lib/CIME/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,24 +207,26 @@ def get_status(self, phase):
def get_comment(self, phase):
return self._phase_statuses[phase][1] if phase in self._phase_statuses else None

def phase_statuses_dump(self, fd, prefix=''):
def phase_statuses_dump(self, prefix=''):
"""
Args:
fd: file open for writing
prefix: string printed at the start of each line
"""
result = ""
if self._phase_statuses:
for phase, data in self._phase_statuses.iteritems():
status, comments = data
if not comments:
fd.write("%s%s %s %s\n" % (prefix, status, self._test_name, phase))
result += "%s%s %s %s\n" % (prefix, status, self._test_name, phase)
else:
fd.write("%s%s %s %s %s\n" % (prefix, status, self._test_name, phase, comments))
result += "%s%s %s %s %s\n" % (prefix, status, self._test_name, phase, comments)

return result

def flush(self):
if self._phase_statuses and not self._no_io:
with open(self._filename, "w") as fd:
self.phase_statuses_dump(fd)
fd.write(self.phase_statuses_dump())

def _parse_test_status(self, file_contents):
"""
Expand Down
2 changes: 1 addition & 1 deletion scripts/lib/cs.status.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#! /bin/bash

<PATH>/cs_status *.<TESTID>/TestStatus
<PATH>/cs.status "$@" <TESTROOT>/*.<TESTID>/TestStatus

0 comments on commit d0e277d

Please sign in to comment.