Exemplo n.º 1
0
def test_cli_defines_ignored_are_ignored(state, caplog):
    opts = SimpleNamespace(opt_confs='',
                           defines=[f'[]{state}opts=ignore me'],
                           define_suites=[])
    get_cli_opts_node(opts)
    assert caplog.records[0].message == \
        'CLI opts set to ignored or trigger-ignored will be ignored.'
Exemplo n.º 2
0
def test_get_cli_opts_node(opt_confs, defines, rose_template_vars, expect):
    opts = SimpleNamespace(opt_conf_keys=opt_confs,
                           defines=defines,
                           rose_template_vars=rose_template_vars)
    loader = ConfigLoader()
    expect = loader.load(StringIO(expect))
    result = get_cli_opts_node(opts)
    for item in ['env', 'template variables', 'opts']:
        assert result[item] == expect[item]
Exemplo n.º 3
0
def test_get_cli_opts_node(opt_confs, defines, define_suites, expect):
    opts = SimpleNamespace(opt_conf_keys=opt_confs,
                           defines=defines,
                           define_suites=define_suites)
    loader = ConfigLoader()
    expect = loader.load(StringIO(expect))
    result = get_cli_opts_node(opts)
    for item in ['env', 'jinja2:suite.rc', 'opts']:
        assert result[item] == expect[item]
Exemplo n.º 4
0
def record_cylc_install_options(
    rundir=None,
    opts=None,
    srcdir=None,
):
    """Create/modify files recording Cylc install config options.

    Creates a new config based on CLI options and writes it to the workflow
    install location as ``rose-suite-cylc-install.conf``.

    If ``rose-suite-cylc-install.conf`` already exists over-writes changed
    items, except for ``!opts=`` which is merged and simplified.

    If ``!opts=`` have been changed these are appended to those that have
    been written in the installed ``rose-suite.conf``.

    Args:
        srcdir (pathlib.Path):
            Used to check whether the source directory contains a rose config.
        opts:
            Cylc option parser object - we want to extract the following
            values:
            - opt_conf_keys (list or str):
                Equivelent of ``rose suite-run --option KEY``
            - defines (list of str):
                Equivelent of ``rose suite-run --define KEY=VAL``
            - suite_defines (list of str):
                Equivelent of ``rose suite-run --define-suite KEY=VAL``
        rundir (pathlib.Path):
            Path to dump the rose-suite-cylc-conf

    Returns:
        cli_config - Config Node which has been dumped to
        ``rose-suite-cylc-install.conf``.
        rose_suite_conf['opts'] - Opts section of the config node dumped to
        installed ``rose-suite.conf``.
    """
    # Create a config based on command line options:
    cli_config = get_cli_opts_node(opts)

    # Leave now if there is nothing to do:
    if not cli_config:
        return False

    # Construct path objects representing our target files.
    (Path(rundir) / 'opt').mkdir(exist_ok=True)
    conf_filepath = Path(rundir) / 'opt/rose-suite-cylc-install.conf'
    rose_conf_filepath = Path(rundir) / 'rose-suite.conf'
    dumper = ConfigDumper()
    loader = ConfigLoader()

    # If file exists we need to merge with our new config, over-writing with
    # new items where there are duplicates.
    if conf_filepath.is_file():
        if opts.clear_rose_install_opts:
            conf_filepath.unlink()
        else:
            oldconfig = loader.load(str(conf_filepath))
            cli_config = merge_rose_cylc_suite_install_conf(
                oldconfig, cli_config)

    cli_config.comments = [' This file records CLI Options.']
    dumper.dump(cli_config, str(conf_filepath))

    # Merge the opts section of the rose-suite.conf with those set by CLI:
    if not rose_conf_filepath.is_file():
        rose_conf_filepath.touch()
    rose_suite_conf = loader.load(str(rose_conf_filepath))
    rose_suite_conf = add_cylc_install_to_rose_conf_node_opts(
        rose_suite_conf, cli_config)
    dumper(rose_suite_conf, rose_conf_filepath)

    return cli_config, rose_suite_conf