Rose Stem: Update for maintainers of test workflows

What is Rose Stem?

The Rose Stem test framework is a thin wrapper around cylc install which provides some basic SVN integration features. It is accessed via the rose stem CLI which implements the --tasks/--groups and --sources options.

It is used to implement test workflows (historically called Rose Stem suites).

Functionally speaking, Rose Stem:

  • Sets the workflow ID:
    • Derived from SVN project metadata (if it is an SVN project).
  • As well as a few template variables:
    • RUN_NAME - derived from the --tasks/--groups CLI option.
    • SOURCE_* - primary source is derived from SVN and or the --source CLI argument.
    • SITE - (by convention) extracted from the Rose site configuration.

The rose stem command is effectively just pre-populating some cylc install CLI arguments. After that, everything else is pure Cylc.

Note: Rose Stem is not actually linked to rose_ana, although the two are often used together, they can also be used independently of each other.

Can I use Rose Stem with Git?

Yes.

SVN integration features won’t work of course:

  • It won’t automatically detect the primary source (specify manually with --source).
  • It won’t derive the workflow ID from SVN metadata.

But it is functional.

What are the issues with Rose Stem?

Rose Stem is a somewhat clunky wrapper around cylc install:

  • We have to run rose stem, followed by cylc play.
  • We cannot use cylc reinstall on rose stem-installed workflows.
  • Static analysis tools like cylc validate & cylc graph don’t work on Rose Stem sources.
  • It provides basic SVN integration, but has no support for Git.
  • It’s a whole other CLI for people to learn.
  • It bakes working practices into the framework taking control away from project maintainers.

What is happening to Rose Stem?

Nothing!

Don’t panic™! It’s not going anywhere for the foreseeable, but it’s also not being actively developed.

Instead, we have been working with the maintainers of the largest Rose Stem workflows (UM and LFric) to work out what features we would need to implement in Cylc in order to allow them to move away from the rose stem wrapper. We now believe we have implemented all of the major features required, and the UM and LFric test workflows have been converted into pure Cylc workflows which no longer require use of the rose stem wrapper command for installation.

Our advice to the maintainers of Rose Stem workflows is to follow suit and move away from the rose stem wrapper when it’s convenient.

How to migrate away from rose stem?

This involves replacing each of the Rose Stem features your workflow is using with the native Cylc analogue.

We’ve encountered one Rose Stem workflow which wasn’t using any Rose Stem features at all, so this may be easier than you’d expect!

Here’s a breakdown of the native Cylc replacements for each Rose Stem functionality:

1) Workflow ID

The rose stem wrapper attempts to derive the workflow ID from SVN metadata.

But Cylc now has a feature for setting the workflow and run names via the rose-suite.conf file.

For example, this snippet will cause cylc install to default to installing the workflow as um-rose-stem/<git-commit-hash>/<run-number>:

# rose-suite.conf

[install]
workflow-name=um-rose-stem/$(git rev-parse --short --verify HEAD)

We would recommend installing workflows into a hierarchy like this where the top-level is static (i.e, hardcoded) and the remainder dynamic (e.g, derived from version control metadata). This makes it easier to manage the resulting runs (e.g, cylc clean -y um-rose-stem would remove all runs) and avoids issues where the branch name or commit hash begins with a number (which Cylc allows in run names, but not workflow names).

Note: There’s no direct replacement for retrieving SVN-style project and branch names in Git, so we’ve gone with a string template solution which allows projects to decide their own working practices rather than us guessing and hardcoding them.

For those porting their working practices from FCM, this rather complex Git command is a reasonable approximation for retrieving the branch name in Git:

git for-each-ref --points-at=HEAD --sort=refname --sort=-HEAD --exclude='refs/remotes/*/HEAD' --format='%(refname:short)' refs/heads refs/remotes 2>/dev/null` sed -n 's|\/|__|g; 1p'

Tip: You can place this in a Rose optional configuration if working practices vary from site to site.

2) Tasks / Groups

The rose stem -t/--tasks and -g/--groups arguments both did the same thing! They just set a template variable called RUN_NAMES.

# this:
rose stem --tasks=a,b,c

# is actually equivalent to this:
cylc install -s RUN_NAMES='["a", "b", "c"]'

The pure-Cylc equivalent is horrible to type, so we’ve added a -z option to make specifying lists of strings less onerous:

# shorthand for the "-s" example above
cylc install -z RUN_NAMES=a,b,c

Our recommendation would be to rename RUN_NAMES in your .cylc files to TASKS to make the CLI snappier and more obvious:

cylc install -z TASKS=a,b,c

Note: You can get Cylc to raise an error if a variable (e.g, TASKS) is not defined (example).

3) SOURCE_*

Rose Stem locates the “primary” source (i.e, the working copy your test workflow is located in) for you. It then populates the following template variables:

SOURCE
Filesystem path / SVN URL to the "source" (e.g, ~/my-source).

Cylc now has the CYLC_WORKFLOW_SRC_DIR template variable which gives the location of the Cylc source workflow (i.e, the rose-stem directory).

Add a relative path (typically ../) on to the end of this variable to derive the root directory of the working copy.

SOURCE_REV
The SVN revision number of the "source", if it is an SVN source (e.g, r00001).

For Git projects, the closest equivalent to SOURCE_REV can be obtained by running git rev-parse --verify HEAD against the source.

HOST_SOURCE_BASE
The SOURCE prefixed with the hostname (e.g, myhost:foo.x_tr).

The hostname of the machine where cylc install / cylc vip is run, is available via the ROSE_ORIG_HOST variable.

For installation direct from GitHub/GitLab/etc, something along the lines of git remote get-url upstream will reveal the Git URL.

Rose Stem also allows additional sources to be defined via the --source argument. With Cylc, these can be provided via the -s argument, e.g:

$ cylc install -s SOURCE_ADDITIONAL="/path/to/additional/source"

Note: A useful pattern might be to define default sources in the flow.cylc like so:

#!Jinja2

{% set SOURCE_FOO = SOURCE_FOO | default('git@github.com:example/foo') %}
{% set SOURCE_BAR = SOURCE_BAR | default('git@github.com:example/bar') %}

These default values can be overridden on the Cylc CLI using the -s option as needed.

4) The SITE variable.

This is a convention used in several Rose Stem workflows.

The SITE variable is typically defined in the Rose site configuration using the rose.conf[rose-stem]automatic-options configuration.

For example, at the Met Office, we set:

# rose.conf

[rose-stem]
automatic-options=SITE=meto

We have now added global template variables to Cylc. This is a more generic version of automatic-options that works for all workflows (not just Rose Stem ones).

Our recommendation is to set a variable called CYLC_SITE to whatever value you were previously setting in the Rose Config, e.g:

# global.cylc

[template variables]
    CYLC_SITE = 'meto'

And rename SITE to CYLC_SITE in your workflow’s .cylc files.

Note: The reason for the change from SITE to CYLC_SITE is because some non-Rose-Stem workflows have adopted similar SITE conventions which can clash badly.

Note: The UM/Lfric conventions for site codes are listed in the Simulation Systems documentation.

5) Source installation (if migrating from SVN → Git)

Not really a Rose Stem feature, however, some Rose Stem workflows will likely use Rose file installation to checkout the source.

Rose can install from both SVN and Git repositories, if you’re switching from SVN/FCM to Git, you may need to rejig the syntax, see the Rose docs.

6) Wrapper script

For SVN projects, the rose stem command would automatically locate your project’s rose-stem directory no matter where you ran the command within the working copy.

Cylc won’t do this, so you’ll have to cd or specify the path manually, e.g, cylc vip ../rose-stem.

If you would like tighter Git integration, this alias will invoke Cylc in project-root/rose-stem:

[alias]
  stem = ! echo $(git rev-parse --show-toplevel)/rose-stem  | xargs cylc

What next?

Rose Stem is sticking around for the forseable.

But you may find you can achieve less clunky test workflows with better Git support by converting to pure-Cylc workflows.

If you’ve got any questions, would like to talk through migration or have identified any barriers we haven’t addressed yet, open a new post in the Rose Support category.

1 Like

This is fantastic work. The workflow I manage has rose-stem-like tests and I shall be looking at implementing some of this. :slight_smile: