def test_get_config_announces(): for good_config in (MESOS_CONFIG_WITH_ANNOUNCE_1, MESOS_CONFIG_WITH_ANNOUNCE_2, MESOS_CONFIG_WITHOUT_ANNOUNCE): bio = BytesIO(good_config) get_aurora_config('hello_world', bio).job()
def test_get_config_announces(): for good_config in ( MESOS_CONFIG_WITH_ANNOUNCE_1, MESOS_CONFIG_WITH_ANNOUNCE_2, MESOS_CONFIG_WITHOUT_ANNOUNCE): bio = BytesIO(good_config) get_aurora_config('hello_world', bio).job()
def test_get_config_with_broken_subscopes(): bad_config = MESOS_CONFIG_BASE % { 'cmdline': 'echo {{hello[{{thermos.ports[http]}}]}}', 'announce': '', } bio = BytesIO(bad_config) with pytest.raises(AuroraConfig.InvalidConfig) as cm: get_aurora_config('hello_world', bio).job() assert 'Unexpected unbound refs' in str(cm.value.message)
def test_get_config_mapped_primary_port(capsys): config_mapped_primary_port = MESOS_CONFIG_BASE % { 'cmdline': 'echo {{thermos.ports[custom]}}', 'announce': 'announce = Announcer(primary_port = "http", portmap = {"http": "custom"}),' } get_aurora_config('hello_world', BytesIO(config_mapped_primary_port)).job() out, err = capsys.readouterr() assert err == "" # No warning about unbound primary port assert out == ""
def test_get_config_primary_port_warning(capsys): config_unbound_primary_port = MESOS_CONFIG_BASE % { 'cmdline': 'echo {{thermos.ports[http]}}', 'announce': 'announce = Announcer(primary_port = "custom", portmap = {}),' } get_aurora_config('hello_world', BytesIO(config_unbound_primary_port)).job() _, err = capsys.readouterr() msg = "Announcer specified primary port as 'custom' but no processes have bound that port" assert msg in err
def test_get_config_select(): bio = BytesIO(MESOS_CONFIG_WITHOUT_ANNOUNCE) get_aurora_config( "hello_world", bio, select_env="test", select_role="john_doe", select_cluster="test-cluster" ).job() bio.seek(0) with pytest.raises(ValueError) as cm: get_aurora_config( "hello_world", bio, select_env="staging42", select_role="moua", select_cluster="test-cluster" ).job() assert "test-cluster/john_doe/test/hello_world" in str(cm.value.message)
def test_include(): with temporary_dir() as dir: hello_mesos_fname = "hello_world.mesos" hello_mesos_path = os.path.join(dir, hello_mesos_fname) with open(os.path.join(dir, hello_mesos_path), "wb") as hello_world_mesos: hello_world_mesos.write(MESOS_CONFIG_WITHOUT_ANNOUNCE) hello_world_mesos.flush() hello_include_fname_path = os.path.join(dir, "hello_include_fname.mesos") with open(hello_include_fname_path, "wb+") as hello_include_fname_fp: hello_include_fname_fp.write(MESOS_CONFIG_WITH_INCLUDE % ("", """'%s'""" % hello_mesos_fname)) hello_include_fname_fp.flush() get_aurora_config("hello_world", hello_include_fname_path) hello_include_fname_fp.seek(0) with pytest.raises(AuroraConfigLoader.InvalidConfigError): get_aurora_config("hello_world", hello_include_fname_fp)
def test_get_config_select(): bio = BytesIO(MESOS_CONFIG_WITHOUT_ANNOUNCE) get_aurora_config('hello_world', bio, select_env='test', select_role='john_doe', select_cluster='test-cluster').job() bio.seek(0) with pytest.raises(ValueError) as cm: get_aurora_config('hello_world', bio, select_env='staging42', select_role='moua', select_cluster='test-cluster').job() assert 'test-cluster/john_doe/test/hello_world' in str(cm.value.message)
def test_get_config_select(): bio = BytesIO(MESOS_CONFIG_WITHOUT_ANNOUNCE) get_aurora_config( 'hello_world', bio, select_env='test', select_role='john_doe', select_cluster='test-cluster').job() bio.seek(0) with pytest.raises(ValueError) as cm: get_aurora_config( 'hello_world', bio, select_env='staging42', select_role='moua', select_cluster='test-cluster').job() assert 'test-cluster/john_doe/test/hello_world' in str(cm.value.message)
def test_include(): with temporary_dir() as dir: hello_mesos_fname = "hello_world.mesos" hello_mesos_path = os.path.join(dir, hello_mesos_fname) with open(os.path.join(dir, hello_mesos_path), "wb") as hello_world_mesos: hello_world_mesos.write(MESOS_CONFIG_WITHOUT_ANNOUNCE) hello_world_mesos.flush() hello_include_fname_path = os.path.join( dir, "hello_include_fname.mesos") with open(hello_include_fname_path, "wb+") as hello_include_fname_fp: hello_include_fname_fp.write( MESOS_CONFIG_WITH_INCLUDE % ("", """'%s'""" % hello_mesos_fname)) hello_include_fname_fp.flush() get_aurora_config('hello_world', hello_include_fname_path) hello_include_fname_fp.seek(0) with pytest.raises(AuroraConfigLoader.InvalidConfigError): get_aurora_config('hello_world', hello_include_fname_fp)
def test_get_config_with_broken_subscopes(): bad_config = MESOS_CONFIG_BASE % {"cmdline": "echo {{hello[{{thermos.ports[http]}}]}}", "announce": ""} bio = BytesIO(bad_config) with pytest.raises(AuroraConfig.InvalidConfig) as cm: get_aurora_config("hello_world", bio).job() assert "Unexpected unbound refs" in str(cm.value.message)