Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cylc reg tweak. #2816

Merged
merged 3 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bin/cylc-register
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ Register the name REG for the suite definition in PATH. The suite server
program can then be started, stopped, and targeted by name REG. (Note that
"cylc run" can also register suites on the fly).

Registration creates a suite run directory "~/cylc-run/REG/" with a ".service/"
sub-directory containing authentication files and a "source" symlink to PATH.
Registration creates a suite run directory "~/cylc-run/REG/" containing a
".service/source" symlink to the suite definition PATH. The .service directory
will also be used for server authentication files at run time.

Suite names can be hierarchical, corresponding to the path under ~/cylc-run.

Expand Down
7 changes: 5 additions & 2 deletions lib/cylc/scheduler_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ def main(is_restart=False):
options, args = parse_commandline(is_restart)
if not args:
# Auto-registration: "cylc run" (no args) in source dir.
reg = SuiteSrvFilesManager().register()
# Replace this process with "cylc run REG ..." for easy identification.
try:
reg = SuiteSrvFilesManager().register()
except SuiteServiceFileError as exc:
sys.exit(exc)
# Replace this process with "cylc run REG ..." for 'ps -f'.
os.execv(sys.argv[0], [sys.argv[0]] + [reg] + sys.argv[1:])

# Check suite is not already running before start of host selection.
Expand Down
58 changes: 27 additions & 31 deletions lib/cylc/suite_srv_files_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,59 +431,55 @@ def register(self, reg=None, source=None, redirect=False):
Another suite already has this name (unless --redirect).
"""
if reg is None:
# Take name of parent dir as suite name.
reg = os.path.basename(os.getcwd())

if os.path.isabs(reg):
raise SuiteServiceFileError(
"ERROR: suite name cannot be an absolute path: %s" % reg)

# Suite service directory.
srv_d = self.get_suite_srv_dir(reg)

# Check if reg is already used.
target = os.path.join(srv_d, self.FILE_BASE_SOURCE)
try:
# Already used?
orig_source = os.readlink(target)
except OSError:
orig_source = None

if source is not None:
# Regularize: want suite dir name only (not dir/suite.rc).
if os.path.basename(source) == self.FILE_BASE_SUITE_RC:
source = os.path.dirname(source)
else:
# Assume source is $PWD unless reg is already used.
if orig_source is None:
source = os.getcwd()
else:
source = orig_source
source = os.getcwd()

# suite.rc must exist so we can detect accidentally reversed args.
source = os.path.abspath(source)
if not os.path.isfile(os.path.join(source, self.FILE_BASE_SUITE_RC)):
raise SuiteServiceFileError("ERROR: no suite.rc in %s" % source)

if orig_source is None:
mkdir_p(srv_d)
os.symlink(source, target)
# Suite service directory.
srv_d = self.get_suite_srv_dir(reg)

elif orig_source != source:
# Redirecting an existing name and run directory to another suite.
# Does symlink to suite source already exist?
target = os.path.join(srv_d, self.FILE_BASE_SOURCE)
try:
orig_source = os.readlink(target)
except OSError:
orig_source = None

# Create service dir if necessary.
mkdir_p(srv_d)

# Redirect an existing name to another suite?
if orig_source is not None and source != orig_source:
if not redirect:
raise SuiteServiceFileError(
"ERROR: the suite name '%s' is already used for %s." % (
reg, orig_source))
else:
sys.stderr.write(
"WARNING: the suite name '%s' was used for %s.\n"
"The run directory will be reused for %s.\n" % (
reg, orig_source, source))
"ERROR: the name '%s' already points to %s.\nUse "
"--redirect to re-use an existing name and run "
"directory." % (reg, orig_source))
sys.stderr.write(
"WARNING: the name '%(reg)s' points to %(old)s.\nIt will now"
" be redirected to %(new)s.\nFiles in the existing %(reg)s run"
" directory will be overwritten.\n" % {
'reg': reg, 'old': orig_source, 'new': source})
# Remove symlink to the original suite.
os.unlink(target)

# Create symlink to the suite, if it doesn't already exist.
if source != orig_source:
os.symlink(source, target)

# Report the new (or renewed) registration.
print 'REGISTERED %s -> %s' % (reg, source)
return reg

Expand Down
8 changes: 5 additions & 3 deletions tests/registration/00-simple.t
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,18 @@ run_ok "${TEST_NAME}" cylc register $CHEESE $CHEESE
TEST_NAME="${TEST_NAME_BASE}-repurpose1"
run_fail "${TEST_NAME}" cylc register $CHEESE $YOGHURT
contains_ok "${TEST_NAME}.stderr" <<__ERR__
ERROR: the suite name '$CHEESE' is already used for ${PWD}/$CHEESE.
ERROR: the name '$CHEESE' already points to ${PWD}/$CHEESE.
Use --redirect to re-use an existing name and run directory.
__ERR__

# Test succeed "cylc reg REG PATH" where REG already points to PATH2
TEST_NAME="${TEST_NAME_BASE}-repurpose2"
cp -r $CHEESE $YOGHURT
run_ok "${TEST_NAME}" cylc register --redirect $CHEESE $YOGHURT
contains_ok "${TEST_NAME}.stderr" <<__ERR__
WARNING: the suite name '$CHEESE' was used for ${PWD}/$CHEESE.
The run directory will be reused for ${PWD}/$YOGHURT.
WARNING: the name '$CHEESE' points to ${PWD}/$CHEESE.
It will now be redirected to ${PWD}/$YOGHURT.
Files in the existing $CHEESE run directory will be overwritten.
__ERR__
contains_ok "${TEST_NAME}.stdout" <<__OUT__
REGISTERED $CHEESE -> ${PWD}/$YOGHURT
Expand Down