示例#1
0
文件: environ.py 项目: lowks/bosun
def load_configuration(yaml_string, kw=None, missing_fmt=None):
    environ = rec_env.load_configuration(yaml_string, kw, missing_fmt)
    environ = update_model_type(environ)

    #if environ.get('API', 0) != API_VERSION:
    #    print fc.red('Error: Configuration outdated')
    #    ref = yaml.safe_load(
    #      os.path.join(os.path.dirname(__file__), 'api.yaml'))
    #    report_differences(environ, ref)
    #    raise APIVersionException

    if 'ensemble' in environ:
        environs = []
        ensemble = environ['ensemble']
        environ.pop('ensemble')
        for member in ensemble.keys():
            new_env = update_environ(environ, ensemble, member)
            new_env = update_model_type(environ)
            environs.append(new_env)

        # TODO: ignoring for now, but need to think on how to run
        # multiple environs (one for each ensemble member).
        # Maybe use the Fabric JobQueue, which abstracts
        # multiprocessing?

    return environ
示例#2
0
def load_configuration(yaml_string, kw=None, missing_fmt=None):
    environ = rec_env.load_configuration(yaml_string, kw, missing_fmt)
    environ = update_model_type(environ)

    #if environ.get('API', 0) != API_VERSION:
    #    print fc.red('Error: Configuration outdated')
    #    ref = yaml.safe_load(
    #      os.path.join(os.path.dirname(__file__), 'api.yaml'))
    #    report_differences(environ, ref)
    #    raise APIVersionException

    if 'ensemble' in environ:
        environs = []
        ensemble = environ['ensemble']
        environ.pop('ensemble')
        for member in ensemble.keys():
            new_env = update_environ(environ, ensemble, member)
            new_env = update_model_type(environ)
            environs.append(new_env)

        # TODO: ignoring for now, but need to think on how to run
        # multiple environs (one for each ensemble member).
        # Maybe use the Fabric JobQueue, which abstracts
        # multiprocessing?

    return environ
示例#3
0
def test_recursive_circular_variables():
    # Notice: if this fails we probably made an AI or a parallel universe.
    with pytest.raises(RuntimeError):
        env = load_configuration(CIRCULAR_YAML)
示例#4
0
def test_int_values():
    env = load_configuration(TEST_YAML)
    assert env['api_version'] == 1
示例#5
0
def test_recursive_replace_nested_complex():
    env = load_configuration(TEST_YAML)
    assert env['clients']['ios']['auth'] == "uat.urltest.net/auth"
示例#6
0
def test_recursive_replace_nested_simple():
    env = load_configuration(TEST_YAML)
    assert env['clients']['ios']['provision'] == "mycarrier.uat.urltest.net"
示例#7
0
def test_recursive_replace_boolean_values():
    env = load_configuration(TEST_YAML)
    assert env['features']['contacts'] is True
    assert env['features']['backup'] is False
示例#8
0
def test_recursive_replace_with_keywords():
    env = load_configuration(TEST_YAML, {'environment': 'dev'})
    assert env['url'] == "mycarrier.localhost"
示例#9
0
def test_recursive_replace():
    env = load_configuration(TEST_YAML)
    assert env['url'] == "mycarrier.uat.urltest.net"
示例#10
0
def test_recursive_circular_variables():
    # Notice: if this fails we probably made an AI or a parallel universe.
    with pytest.raises(RuntimeError):
        env = load_configuration(CIRCULAR_YAML)
示例#11
0
def test_int_values():
    env = load_configuration(TEST_YAML)
    assert env['api_version'] == 1
示例#12
0
def test_recursive_replace_nested_complex():
    env = load_configuration(TEST_YAML)
    assert env['clients']['ios']['auth'] == "uat.urltest.net/auth"
示例#13
0
def test_recursive_replace_nested_simple():
    env = load_configuration(TEST_YAML)
    assert env['clients']['ios']['provision'] == "mycarrier.uat.urltest.net"
示例#14
0
def test_recursive_replace_boolean_values():
    env = load_configuration(TEST_YAML)
    assert env['features']['contacts'] is True
    assert env['features']['backup'] is False
示例#15
0
def test_recursive_replace_with_keywords():
    env = load_configuration(TEST_YAML, {'environment': 'dev'})
    assert env['url'] == "mycarrier.localhost"
示例#16
0
def test_recursive_replace():
    env = load_configuration(TEST_YAML)
    assert env['url'] == "mycarrier.uat.urltest.net"