Exemplo n.º 1
0
def test_invalid_templatevar():
    """It should wrap eval errors as something more informative."""
    ret = {}
    node = ConfigNode()
    node.set(['jinja2:suite.rc', 'X'], 'Y')
    with pytest.raises(ConfigProcessError):
        get_rose_vars_from_config_node(ret, node, {})
Exemplo n.º 2
0
 def _inner(comment=''):
     ret = {}
     node = ConfigNode()
     node.set(['env', 'ROSE_ORIG_HOST'], 'IMPLAUSIBLE_HOST_NAME')
     node['env']['ROSE_ORIG_HOST'].comments = [comment]
     get_rose_vars_from_config_node(ret, node, {})
     return node
Exemplo n.º 3
0
def get_rose_vars(srcdir=None, opts=None):
    """Load template variables from Rose suite configuration.

    Loads the Rose suite configuration tree from the filesystem
    using the shell environment.

    Args:
        srcdir(pathlib.Path):
            Path to the Rose suite configuration
            (the directory containing the ``rose-suite.conf`` file).
        opts:
            Options object containing specification of optional
            configuarations set by the CLI.

    Returns:
        dict - A dictionary of sections of rose-suite.conf.
        For each section either a dictionary or None is returned.
        E.g.
            {
                'env': {'MYVAR': 42},
                'empy:suite.rc': None,
                'jinja2:suite.rc': {
                    'myJinja2Var': {'yes': 'it is a dictionary!'}
                }
            }
    """
    # Set up blank page for returns.
    config = {
        'env': {},
        'template_variables': {},
        'templating_detected': None
    }

    # Return a blank config dict if srcdir does not exist
    if not rose_config_exists(srcdir, opts):
        if (
            getattr(opts, "opt_conf_keys", None)
            or getattr(opts, "defines", None)
            or getattr(opts, "rose_template_vars", None)
        ):
            raise NotARoseSuiteException()
        return config

    # Load the raw config tree
    config_tree = rose_config_tree_loader(srcdir, opts)
    deprecation_warnings(config_tree)

    # Extract templatevars from the configuration
    get_rose_vars_from_config_node(
        config,
        config_tree.node,
        os.environ
    )

    # Export environment vars
    for key, val in config['env'].items():
        os.environ[key] = val

    return config
Exemplo n.º 4
0
def test_get_rose_vars_from_config_node__unbound_env_var(caplog):
    """It should fail if variable unset in environment.
    """
    ret = {}
    node = ConfigNode()
    node.set(['env', 'X'], '${MYVAR}')
    with pytest.raises(ConfigProcessError) as exc:
        get_rose_vars_from_config_node(ret, node, {})
    assert exc.match('env=X: MYVAR: unbound variable')
Exemplo n.º 5
0
def test_blank():
    """It should provide only standard vars for a blank config."""
    ret = {}
    node = ConfigNode()
    get_rose_vars_from_config_node(ret, node, {})
    assert set(
        ret.keys()) == {'template_variables', 'templating_detected', 'env'}
    assert set(ret['env'].keys()) == {
        'ROSE_ORIG_HOST',
        'ROSE_VERSION',
    }
Exemplo n.º 6
0
def override_version_vars(caplog, scope='module'):
    """Set up config tree and pass to get_rose_vars_from_config_node

    Yields:
        node: The node after manipulation.
        message: A string representing the caplog output.
    """
    ret = {}
    node = ConfigNode()
    node.set(['template variables', 'ROSE_VERSION'], 99)
    node.set(['template variables', 'CYLC_VERSION'], 101)
    get_rose_vars_from_config_node(ret, node, {})
    message = '\n'.join([i.message for i in caplog.records])
    yield (node, message)
Exemplo n.º 7
0
def get_rose_vars(srcdir=None, opts=None):
    """Load template variables from Rose suite configuration.

    Loads the Rose suite configuration tree from the filesystem
    using the shell environment.

    Args:
        srcdir(pathlib.Path):
            Path to the Rose suite configuration
            (the directory containing the ``rose-suite.conf`` file).
        opts:
            Options object containing specification of optional
            configuarations set by the CLI.

    Returns:
        dict - A dictionary of sections of rose-suite.conf.
        For each section either a dictionary or None is returned.
        E.g.
            {
                'env': {'MYVAR': 42},
                'empy:suite.rc': None,
                'jinja2:suite.rc': {
                    'myJinja2Var': {'yes': 'it is a dictionary!'}
                }
            }
    """
    # Set up blank page for returns.
    config = {'env': {}, 'template_variables': {}, 'templating_detected': None}

    # Return a blank config dict if srcdir does not exist
    if not rose_config_exists(srcdir, opts):
        return config

    # Load the raw config tree
    config_tree = rose_config_tree_loader(srcdir, opts)

    # Warn if root-dir set in config:
    if 'root-dir' in config_tree.node:
        LOG.warning('You have set "root-dir", which at Cylc 8 does nothing. '
                    'See Cylc Install documentation.')

    # Extract templatevars from the configuration
    get_rose_vars_from_config_node(config, config_tree.node, os.environ)

    # Export environment vars
    for key, val in config['env'].items():
        os.environ[key] = val

    return config