From 25103ca299211949fcf9aeb7ee6ba7d467b6cf13 Mon Sep 17 00:00:00 2001 From: "Bruno P. Kinoshita" Date: Sun, 13 Oct 2019 23:06:10 +1300 Subject: [PATCH] Prevent creating auth files when there is no suite service directory --- CHANGES.md | 5 +++++ cylc/flow/scheduler_cli.py | 10 ++++++++-- tests/cylc-run/01-invalid-suite.t | 29 +++++++++++++++++++++++++++++ tests/cylc-run/test_header | 1 + 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 tests/cylc-run/01-invalid-suite.t create mode 120000 tests/cylc-run/test_header diff --git a/CHANGES.md b/CHANGES.md index efd1d0cec75..d68d247512f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -46,6 +46,11 @@ Third alpha release of Cylc 8. status message retries (problems that prevent message transmission are almost never transient, and in practice job polling is the only way to recover). +### Fixes + +[#3409](https://github.com/cylc/cylc-flow/pull/3409) - prevent cylc-run from +creating directories when executed for suites that do not exist. + ------------------------------------------------------------------------------- ## __cylc-8.0a1 (2019-09-18)__ diff --git a/cylc/flow/scheduler_cli.py b/cylc/flow/scheduler_cli.py index 17ce5b21151..c7fa4bde589 100644 --- a/cylc/flow/scheduler_cli.py +++ b/cylc/flow/scheduler_cli.py @@ -232,13 +232,19 @@ def scheduler_cli(parser, options, args, is_restart=False): except SuiteServiceFileError as exc: sys.exit(exc) + suite_run_dir = get_suite_run_dir(reg) + + if not os.path.exists(suite_run_dir): + sys.stderr.write(f'suite service directory not found ' + f'at: {suite_run_dir}\n') + sys.exit(1) + # Create auth files if needed. SuiteSrvFilesManager().create_auth_files(reg) # Extract job.sh from library, for use in job scripts. extract_resources( - SuiteSrvFilesManager().get_suite_srv_dir(reg), - ['etc/job.sh']) + SuiteSrvFilesManager().get_suite_srv_dir(reg), ['etc/job.sh']) # Check whether a run host is explicitly specified, else select one. if not options.host: diff --git a/tests/cylc-run/01-invalid-suite.t b/tests/cylc-run/01-invalid-suite.t new file mode 100644 index 00000000000..1614c3b7821 --- /dev/null +++ b/tests/cylc-run/01-invalid-suite.t @@ -0,0 +1,29 @@ +#!/bin/bash +# THIS FILE IS PART OF THE CYLC SUITE ENGINE. +# Copyright (C) 2008-2019 NIWA & British Crown (Met Office) & Contributors. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +#------------------------------------------------------------------------------- +# Test that ``cylc-run`` does not create directories for invalid/not existent +# suites. See https://github.com/cylc/cylc-flow/issues/3097 for more. +. "$(dirname "$0")/test_header" +#------------------------------------------------------------------------------- +set_test_number 3 +#------------------------------------------------------------------------------- +INVALID_SUITE_NAME="broken-parachute-8877-mp5" +run_fail "${TEST_NAME_BASE}-run" cylc run "${INVALID_SUITE_NAME}" +grep_ok "suite service directory not found at" "${TEST_NAME_BASE}-run.stderr" +exists_fail "${HOME}/cylc-run/${INVALID_SUITE_NAME}" + +exit diff --git a/tests/cylc-run/test_header b/tests/cylc-run/test_header new file mode 120000 index 00000000000..90bd5a36f92 --- /dev/null +++ b/tests/cylc-run/test_header @@ -0,0 +1 @@ +../lib/bash/test_header \ No newline at end of file