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 clean - initial implementation #3961

Merged
merged 14 commits into from
Dec 2, 2020
Merged

Conversation

MetRonnie
Copy link
Member

@MetRonnie MetRonnie commented Nov 24, 2020

These changes partially address #3887

  1. Remove stopped workflows on the local scheduler filesystem

Implements a new command

$ cylc clean workflow_name

Note: Cleaning remote directories will come in a later PR.

Requirements check-list

  • I have read CONTRIBUTING.md and added my name as a Code Contributor.
  • Contains logically grouped changes (else tidy your branch by rebase).
  • Does not contain off-topic changes (use other PRs for other changes).
  • Appropriate tests are included (unit and functional).
  • Appropriate change log entry included.
  • Documentation will be handled by Document cylc clean cylc-doc#256
  • No dependency changes.

- Ensure passed "reg" is not a path that points to the cylc-run dir or
higher
- Ensure symlinks to be deleted have expected form i.e.
`something/cylc-run/reg/log` etc
@MetRonnie MetRonnie added this to the cylc-8.0.0 milestone Nov 24, 2020
@MetRonnie MetRonnie self-assigned this Nov 24, 2020
@MetRonnie
Copy link
Member Author

MetRonnie commented Nov 24, 2020

Should the docs update come later as part of the 7-to-8 guide?

cylc/flow/suite_files.py Outdated Show resolved Hide resolved
Comment on lines 606 to 609
if os.path.isdir(target_top_parent):
remove_dir(target_top_parent)
run_dir_top_parent = get_suite_run_dir(Path(reg).parts[0])
remove_dir(run_dir_top_parent)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes, we don't want to remove the entire hierarchy in the process of removing something a the bottom of the hierarchy.

For example here are two flows, a/b/c and a/d:

$ tree a
a
|-- b
|   `-- c
|       `-- suite.rc
`-- d
    `-- suite.rc

If removing one flow, the other should remain:

$ cylc clean a/b/c
$ tree a
a
`-- d
    `-- suite.rc

Though we can remove any empty dirs between the REG and ~/cylc-run:

$ cylc clean a/d
$ tree a

Aside: We can extend this at some point to discover flows in a hierarchy using the suite detecting "scan" logic already implemented:

$ tree a
a
|-- b
|   `-- c
|       `-- suite.rc
`-- d
    `-- suite.rc
$ cylc clean a
$ tree a -r

@MetRonnie MetRonnie marked this pull request as draft November 24, 2020 14:21
@MetRonnie MetRonnie marked this pull request as ready for review November 25, 2020 11:01
"""
_validate_reg(reg)
reg = os.path.normpath(reg)
if reg.startswith('.'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW the suite name validator has you covered here:

not_starts_with(r'\.', r'\-'),

Copy link
Member Author

@MetRonnie MetRonnie Nov 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference is I'm checking after normalising the path, because you could have cylc clean foo/../.. which normalises to cylc clean .., i.e. rm $HOME. However, I guess I could change the order to

reg = os.path.normpath(reg)
_validate_reg(reg)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should accept path manipulations, though I'm unaware of a simple method to block them (testing for .. doesn't work for all cases).

Probs good enough to ensure that the flow exists within the cylc-run dir:

reg = Path(reg)
reg.resolve()
try:
    reg.relative_to(run_dir_path)
except ValueError:
    raise Exception('Flow not found')

Anyway, not a problem for this PR.

raise WorkflowFilesError(
f'Invalid Cylc symlink directory {path} -> {target}\n'
f'Target is not a directory')
expected_end = str(Path('cylc-run', reg, name))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

str(Path( 😆

sed -i '$d' "${TEST_NAME}.stdout"
# Note: backticks need to be escaped in the heredoc
cmp_ok "${TEST_NAME}.stdout" << __TREE__
${TEST_DIR}/sym-cycle
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice human readable test.

Copy link
Contributor

@datamel datamel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have read code, checked this branch out and run tests. I have one comment that needs addressing, other than that I'm pretty sure it is good to go!

${TEST_DIR}/sym-log
\`-- cylc-run
\`-- cylctb-${CYLC_TEST_TIME_INIT}
|-- f
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests will fail when running tests using the functional directory name, rather than the f one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been fixed.

@@ -62,23 +67,23 @@ cmp_ok "${TEST_NAME}.stdout" << __TREE__
${TEST_DIR}/sym-cycle
\`-- cylc-run
\`-- cylctb-${CYLC_TEST_TIME_INIT}
\`-- f
\`-- ${FUNCTIONAL_DIR}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realised that if another test gets added to this directory (i.e. 01-<name>.t) then this test will break.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried copying another test file into tests/functional/cylc-clean/01-something.t and 00-basic.t still works

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If 01-something creates a workflow and the two tests are run together then 01-something will change the output of tree based on the order in which the tests are run.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried making a copy of 00-basic.t called 01-foo.t that has a slightly different expected tree (no symlink work dir or leave-me-alone dir) and both pass? Doesn't purge take care of removing the old stuff?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, but only once the test has passed but tests run in parallel.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully b35b10b prevents that

Copy link
Contributor

@datamel datamel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with these changes. Thanks @MetRonnie!

@oliver-sanders oliver-sanders merged commit eece5ac into cylc:master Dec 2, 2020
@MetRonnie MetRonnie deleted the cylc-clean branch December 2, 2020 10:38
@MetRonnie MetRonnie modified the milestones: cylc-8.0.0, cylc-8.0a3 Dec 2, 2020
@MetRonnie MetRonnie linked an issue Dec 10, 2020 that may be closed by this pull request
@MetRonnie MetRonnie mentioned this pull request Dec 11, 2020
@hjoliver hjoliver modified the milestones: cylc-8.0a3, cylc-8.0b0 Feb 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cylc clean
4 participants