Skip to content

Commit

Permalink
cat-log tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
hjoliver committed Mar 4, 2018
1 parent 8c3a5cb commit 1951509
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 42 deletions.
37 changes: 20 additions & 17 deletions bin/cylc-cat-log
Original file line number Diff line number Diff line change
Expand Up @@ -237,33 +237,36 @@ def get_task_job_attrs(options, suite_name, point, task, submit_num):
user_at_host = get_user_at_host(user, host)
# Use special batch system commands to view job out or err (e.g. "qcat
# [-f]") if the job is still running.

# TODO - OPTIONS.filename IS NOW INSUFFICIENT (allow literal job.out etc.)
if (options.mode in ['l', 'p'] or options.filename not in ['e', 'o'] or
not task_job_data["batch_sys_name"] or
not task_job_data["batch_sys_job_id"] or
not task_job_data["time_run"] or task_job_data["time_run_exit"]):
return (user_at_host, None)
key = None
if options.filename == OPT_JOB_OUT:
if options.mode == 'c':
key = "out viewer"
elif options.mode == 't':
key = "out tailer"
elif options.filename == OPT_JOB_ERR:
if options.mode == 'c':
key = "err viewer"
elif options.mode == 't':
key = "err tailer"
if key is None:
return (user_at_host, None)

user, host = get_user_and_host(user_at_host)
conf = GLOBAL_CFG.get_host_item("batch systems", host, user)
try:
user, host = get_user_and_host(user_at_host)
if options.filename == OPT_JOB_OUT:
if options.mode == 'c':
key = "out viewer"
elif options.mode == 't':
key = "out tailer"
elif options.filename == OPT_JOB_ERR:
if options.mode == 'c':
key = "err viewer"
elif options.mode == 't':
key = "err tailer"
conf = GLOBAL_CFG.get_host_item("batch systems", host, user)
command0_tmpl = conf[str(task_job_data["batch_sys_name"])][key]
except (KeyError, TypeError) as exc:
except KeyError:
return (user_at_host, None)
else:
if command0_tmpl:
return (user_at_host, command0_tmpl % {
return (user_at_host, command0_tmpl % {
"job_id": str(task_job_data["batch_sys_job_id"])})
else:
return (user_at_host, None)


def tmpfile_edit(filestr, logpath, geditor=False):
Expand Down
4 changes: 2 additions & 2 deletions bin/cylc-scan
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ def main():
elif not meta_items["title"]:
print indent + bold("Title:\n") + indent * 2 + "(no title)"
else:
print (indent + bold("Title:\n") + indent * 2 +
'"%s"' % meta_items["title"])
print indent + (bold("Title:\n") + indent * 2 +
'"%s"' % meta_items["title"])
for metaitem, metavalue in meta_items.items():
if metaitem != "title":
if metaitem == "description" or metaitem == "group":
Expand Down
2 changes: 1 addition & 1 deletion bin/cylc-trigger
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def main():
print "Editing done. I'm popping up a confirmation dialog now."

# Save a diff to record the changes made.
difflog = jobfile_path.replace(JOB_LOG_JOB, JOB_LOG_DIFF)
difflog = os.path.join(os.path.dirname(jobfile_path), JOB_LOG_DIFF)
with open(difflog, 'wb') as diff_file:
for line in difflib.unified_diff(
open(jobfile_copy_path).readlines(),
Expand Down
12 changes: 6 additions & 6 deletions lib/cylc/gui/app_gcylc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ def _get_task_extra_job_logs(self, task_id):
task_id]['logfiles']))
except KeyError:
return []

def get_right_click_menu(self, task_ids, t_states, task_is_family=False,
is_graph_view=False):
"""Return the default menu for a list of tasks."""
Expand Down Expand Up @@ -1337,7 +1337,7 @@ def get_right_click_menu(self, task_ids, t_states, task_is_family=False,

# View.
view_menu = gtk.Menu()
view_item = gtk.ImageMenuItem("View All Job Logs (Viewer)")
view_item = gtk.ImageMenuItem("View Job Logs (Viewer)")
img = gtk.image_new_from_stock(gtk.STOCK_DND,
gtk.ICON_SIZE_MENU)
view_item.set_image(img)
Expand All @@ -1346,7 +1346,7 @@ def get_right_click_menu(self, task_ids, t_states, task_is_family=False,

# View In Editor.
view_editor_menu = gtk.Menu()
view_editor_item = gtk.ImageMenuItem("View One Job Log (Editor)")
view_editor_item = gtk.ImageMenuItem("View Job Log (Editor)")
img = gtk.image_new_from_stock(gtk.STOCK_DND,
gtk.ICON_SIZE_MENU)
view_editor_item.set_image(img)
Expand All @@ -1362,7 +1362,7 @@ def get_right_click_menu(self, task_ids, t_states, task_is_family=False,
fnames = ['job-preview']
else:
fnames = (JOB_LOG_OPTS.values() +
self._get_task_extra_job_logs(task_ids[0]))
self._get_task_extra_job_logs(task_ids[0]))
for fname in fnames:
for handler, vmenu in [
(self.view_task_logs, view_menu),
Expand Down Expand Up @@ -2208,8 +2208,8 @@ def _popup_logview(self, task_id, task_state_summary, choice=None):

nsubmits = len(task_state_summary.get('job_hosts', {}))
viewer = ComboLogViewer(self.cfg.suite, task_id, choice,
self._get_task_extra_job_logs(task_id),
nsubmits, self.get_remote_run_opts())
self._get_task_extra_job_logs(task_id),
nsubmits, self.get_remote_run_opts())
self.quitters.append(viewer)
window.add(viewer.get_widget())
quit_button = gtk.Button("_Close")
Expand Down
4 changes: 2 additions & 2 deletions lib/cylc/gui/combo_logviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ class ComboLogViewer(logviewer):
"""Implement a viewer for task job logs in the GUI, via "cylc cat-log".
It has a a combo box for log file selection.
"""
LABEL_TEXT = "File: "
LABEL_TEXT2 = "Submit: "

def __init__(self, suite, task_id, choice, extra_logs, nsubmits,
remote_run_opts):
remote_run_opts):
self.suite_name = suite
self.task_id = task_id
self.nsubmits = nsubmits
Expand Down
2 changes: 1 addition & 1 deletion lib/cylc/gui/tailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def run(self):
try:
self.proc = Popen(
command, stdin=open(os.devnull), stdout=PIPE, stderr=STDOUT,
preexec_fn=os.setsid)
preexec_fn=os.setsid)
except OSError as exc:
dialog = warning_dialog("%s: %s" % (
exc, " ".join(quote(item) for item in command)))
Expand Down
2 changes: 1 addition & 1 deletion tests/cylc-cat-log/00-local.t
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ cylc cat-log -f a $SUITE_NAME a-task.1 >$TEST_NAME.out
grep_ok '\[jobs-submit ret_code\] 0' $TEST_NAME.out
#-------------------------------------------------------------------------------
TEST_NAME=$TEST_NAME_BASE-task-custom
cylc cat-log -c 'job.custom-log' $SUITE_NAME a-task.1 >$TEST_NAME.out
cylc cat-log -f 'job.custom-log' $SUITE_NAME a-task.1 >$TEST_NAME.out
grep_ok "drugs and money" $TEST_NAME.out
#-------------------------------------------------------------------------------
TEST_NAME=$TEST_NAME_BASE-task-list-local-NN
Expand Down
2 changes: 1 addition & 1 deletion tests/cylc-cat-log/01-remote.t
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ grep_ok '\[jobs-submit ret_code\] 0' $TEST_NAME.out
#-------------------------------------------------------------------------------
# remote
TEST_NAME=$TEST_NAME_BASE-task-custom
cylc cat-log -c 'job.custom-log' $SUITE_NAME a-task.1 >$TEST_NAME.out
cylc cat-log -f 'job.custom-log' $SUITE_NAME a-task.1 >$TEST_NAME.out
grep_ok "drugs and money" $TEST_NAME.out
#-------------------------------------------------------------------------------
# local
Expand Down
2 changes: 2 additions & 0 deletions tests/cylc-cat-log/05-remote-tail.t
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ CYLC_TEST_OWNER="$( \
if [[ -z "${CYLC_TEST_HOST}${CYLC_TEST_OWNER}" ]]; then
skip_all '"[test battery]remote host/owner": not defined'
fi
CYLC_TEST_HOST=${CYLC_TEST_HOST:-"localhost"}
CYLC_TEST_OWNER=${CYLC_TEST_OWNER:-${USER}}
export CYLC_TEST_HOST
set_test_number 4
install_suite $TEST_NAME_BASE $TEST_NAME_BASE
Expand Down
2 changes: 2 additions & 0 deletions tests/cylc-cat-log/08-editor-remote.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ OWNER="$( cylc get-global-config -i '[test battery]remote owner' 2>'/dev/null')"
if [[ -z "${OWNER}${HOST}" ]]; then
skip_all '"[test battery]remote host/owner": not defined'
fi
CYLC_TEST_HOST=${CYLC_TEST_HOST:-"localhost"}
CYLC_TEST_OWNER=${CYLC_TEST_OWNER:-${USER}}

. "${TEST_SOURCE_DIR}"/editor/bin/run_tests.sh
export PATH="${TEST_SOURCE_DIR}/editor/bin/":"${PATH}"
Expand Down
9 changes: 3 additions & 6 deletions tests/cylc-cat-log/editor/bin/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,12 @@ function run_tests {
LOG_DIR="$(cylc get-global-config --print-run-dir)/${SUITE_NAME}"
JOB_LOG_DIR="${LOG_DIR}/log/job/1/foo/01"

for OPT_JOBFILE in "-f j_job" "-f o_job.out" "-f e_job.err" \
"-f s_job.status" "-f a_job-activity.log" \
"-c job.custom_job.custom"; do
OPT="${OPT_JOBFILE%_*}"
JOBFILE="${OPT_JOBFILE#*_}"
for JOBFILE in "job" "job.out" "job.err" "job.status" "job-activity.log" \
"job.custom"; do
TEST_NAME="${TEST_NAME_BASE}-${JOBFILE}"
export DESTFILE="${JOBFILE}.edit"
# Check we can view the job log file in the "editor".
run_ok "${TEST_NAME}" cylc cat-log ${OPT} -m e "${SUITE_NAME}" foo.1
run_ok "${TEST_NAME}" cylc cat-log -f ${JOBFILE} -m e "${SUITE_NAME}" foo.1
# Compare viewed (i.e. copied by the fake editor) file with the original.
cmp_ok "${DESTFILE}" "${JOB_LOG_DIR}/${JOBFILE}"
done
Expand Down
2 changes: 1 addition & 1 deletion tests/cylc-get-config/04-dummy-mode-output.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ suite_run_ok "${TEST_NAME_BASE}-run-dummy" \
suite_run_ok "${TEST_NAME_BASE}-run-simulation" \
cylc run -m 'simulation' --reference-test --debug --no-detach ${SUITE_NAME}

LOG=$(cylc log --location $SUITE_NAME)
LOG=$(cylc log -m p $SUITE_NAME)
count_ok '> meet' ${LOG} 1
count_ok '> greet' ${LOG} 1

Expand Down
2 changes: 1 addition & 1 deletion tests/cylc-trigger/03-edit-run.t
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ TEST_NAME="${TEST_NAME_BASE}-run"
run_ok "${TEST_NAME}" cylc run --no-detach "${SUITE_NAME}"
#-------------------------------------------------------------------------------
TEST_NAME="${TEST_NAME_BASE}-diff"
DIFF_LOG=$(cylc cat-log -dl $SUITE_NAME broken-task.1)
DIFF_LOG=$(cylc cat-log -m p -f d $SUITE_NAME broken-task.1)
# Python 2.6 difflib adds an extra space after the filename,
# but Python 2.7 does not. Remove it if it exists.
sed -i 's/^--- original $/--- original/; s/^+++ edited $/+++ edited/' $DIFF_LOG
Expand Down
2 changes: 1 addition & 1 deletion tests/cylc-trigger/08-edit-run-host-select.t
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ TEST_NAME="${TEST_NAME_BASE}-run"
run_ok "${TEST_NAME}" cylc run --no-detach "${SUITE_NAME}"
#-------------------------------------------------------------------------------
TEST_NAME="${TEST_NAME_BASE}-diff"
DIFF_LOG="$(cylc cat-log -dl "${SUITE_NAME}" 'broken-task.1')"
DIFF_LOG="$(cylc cat-log -m p -f d "${SUITE_NAME}" 'broken-task.1')"
# Python 2.6 difflib adds an extra space after the filename,
# but Python 2.7 does not. Remove it if it exists.
sed -i 's/^--- original $/--- original/; s/^+++ edited $/+++ edited/' "${DIFF_LOG}"
Expand Down
3 changes: 2 additions & 1 deletion tests/events/39-task-event-template-all/bin/checkargs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ from subprocess import Popen, PIPE
args = dict([arg.split('=', 1) for arg in sys.argv[1:]])

suite = os.environ['CYLC_SUITE_NAME']
proc = Popen(['cylc', 'cat-log', '-la', suite, 'foo.1'], stdout=PIPE)
proc = Popen(['cylc', 'cat-log', '-m', 'p', '-f', 'a', suite, 'foo.1'],
stdout=PIPE)
alog = proc.communicate()[0].strip()
proc.wait()
for line in open(alog):
Expand Down
2 changes: 1 addition & 1 deletion tests/job-kill/01-remote.t
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ suite_run_ok $TEST_NAME cylc run --reference-test --debug --no-detach $SUITE_NAM
TEST_NAME=$TEST_NAME_BASE-ps
run_fail $TEST_NAME \
${SSH} -n "${CYLC_TEST_HOST}" \
"ps \$(cat cylc-run/$SUITE_NAME/work/*/t*/file)"
"bash -c 'ps \$(cat cylc-run/$SUITE_NAME/work/*/t*/file)'"
#-------------------------------------------------------------------------------
purge_suite_remote "${CYLC_TEST_HOST}" "${SUITE_NAME}"
purge_suite $SUITE_NAME
Expand Down

0 comments on commit 1951509

Please sign in to comment.