Exemplo n.º 1
0
def test_defaults_error():
    str_content = """
machines:
defaults:
    _values:
        user: pouet
    one:pouet:
        _values:
            user: hello
"""

    configuration = load_configuration_content(str_content)
    with pytest.raises(BadKeyNameError):
        extract_machine_hierarchy(configuration)
Exemplo n.º 2
0
def test_not_empty_defaults():
    str_content = """
machines:
defaults:
    _values:
        user: pouet
    one:
        two:
            _values:
                user: pouet
                port: 5555
            five:
                _values:
                    port: 5566
        _values:
            port: 4455
    three:
        _values:
    four:
"""

    configuration = load_configuration_content(str_content)
    hierarchy = extract_machine_hierarchy(configuration)

    default_values = hierarchy["default_values"]
    assert "" in default_values
    assert "one" in default_values
    assert "three" in default_values
    assert "one:two" in default_values
    assert "one:two:five" in default_values
    assert "four" not in default_values
Exemplo n.º 3
0
def test_empty_defaults():
    str_content = """
defaults:
machines:
"""

    configuration = load_configuration_content(str_content)
    hierarchy = extract_machine_hierarchy(configuration)

    assert len(hierarchy["default_values"].keys()) == 0
Exemplo n.º 4
0
def list_machines(path_to_file):
    """
    List machines.

    :param path_to_file     Path to file (str?)
    :return Machine names (iterable)
    """
    if not path_to_file:
        path_to_file = get_user_configuration_path()

    config = load_configuration_file(path_to_file)
    hierarchy = extract_machine_hierarchy(config)

    return hierarchy["machines"].keys()
Exemplo n.º 5
0
def get_machine_configuration(path_to_file, config_name):
    """
    Get machine configuration.

    :param path_to_file     Path to file (str?)
    :param config_name      Config name (str):
    :return Machine configuration (dict)
    """
    if not path_to_file:
        path_to_file = get_user_configuration_path()

    config = load_configuration_file(path_to_file)
    hierarchy = extract_machine_hierarchy(config)

    if config_name not in hierarchy["machines"]:
        raise MissingKeyError(
            "Missing `{0}` name in machines configuration.".format(
                config_name))

    return hierarchy["machines"][config_name]