Example #1
0
def test_config_with_ports():
    hwc = HELLO_WORLD(task=HELLO_WORLD.task()(processes=[
        Process(
            name='hello_world',
            cmdline='echo {{thermos.ports[http]}} {{thermos.ports[admin]}}')
    ]))
    config = AuroraConfig(hwc)
    job = config.job()
    assert job.taskConfig.requestedPorts == set(['http', 'admin'])
Example #2
0
def test_pick():
    with temporary_file() as fp:
        fp.write(MESOS_CONFIG)
        fp.flush()
        env = AuroraConfigLoader.load(fp.name)

    hello_world = env["jobs"][0]
    assert AuroraConfig.pick(env, "hello_world", None) == hello_world

    env["jobs"][0] = env["jobs"][0](name="something_{{else}}")
    assert str(AuroraConfig.pick(env, "something_else", [{"else": "else"}]).name()) == ("something_else")
Example #3
0
def test_config_with_ports():
  hwc = HELLO_WORLD(
    task = HELLO_WORLD.task()(
      processes = [
        Process(name = 'hello_world',
                cmdline = 'echo {{thermos.ports[http]}} {{thermos.ports[admin]}}')
      ]
    )
  )
  config = AuroraConfig(hwc)
  job = config.job()
  assert job.taskConfig.requestedPorts == set(['http', 'admin'])
Example #4
0
def test_simple_config():
    with temporary_file() as fp:
        fp.write(MESOS_CONFIG)
        fp.flush()
        proxy_config1 = AuroraConfig.load(fp.name)
        proxy_config2 = AuroraConfig.load(fp.name, name="hello_world")
        assert proxy_config1.job()
        assert proxy_config1._job == proxy_config2._job
        assert proxy_config1._job == REIFIED_CONFIG
        assert proxy_config1.name() == 'hello_world'
        assert proxy_config1.role() == 'john_doe'
        assert proxy_config1.cluster() == 'smf1-test'
        assert proxy_config1.ports() == set()
Example #5
0
def test_simple_config():
  with temporary_file() as fp:
    fp.write(MESOS_CONFIG)
    fp.flush()
    proxy_config1 = AuroraConfig.load(fp.name)
    proxy_config2 = AuroraConfig.load(fp.name, name="hello_world")
    assert proxy_config1.job()
    assert proxy_config1._job == proxy_config2._job
    assert proxy_config1._job == REIFIED_CONFIG
    assert proxy_config1.name() == 'hello_world'
    assert proxy_config1.role() == 'john_doe'
    assert proxy_config1.cluster() == 'smf1-test'
    assert proxy_config1.ports() == set()
Example #6
0
def test_pick():
    with temporary_file() as fp:
        fp.write(MESOS_CONFIG)
        fp.flush()
        env = AuroraConfigLoader.load(fp.name)

    hello_world = env['jobs'][0]
    assert AuroraConfig.pick(env, 'hello_world', None) == hello_world

    env['jobs'][0] = env['jobs'][0](name='something_{{else}}')
    assert str(
        AuroraConfig.pick(env, 'something_else', [{
            'else': 'else'
        }]).name()) == ('something_else')
Example #7
0
def test_environment_names():
  BAD = ('Prod', ' prod', 'prod ', 'tEst', 'production', 'staging 2', 'stagingA')
  GOOD = ('prod', 'devel', 'test', 'staging', 'staging001', 'staging1', 'staging1234')
  base_job = Job(
      name='hello_world', role='john_doe', cluster='smf1-test',
      task=Task(name='main', processes=[],
                resources=Resources(cpu=0.1, ram=64 * MB, disk=64 * MB)))

  with pytest.raises(ValueError):
    config._validate_environment_name(AuroraConfig(base_job))
  for env_name in GOOD:
    config._validate_environment_name(AuroraConfig(base_job(environment=env_name)))
  for env_name in BAD:
    with pytest.raises(ValueError):
      config._validate_environment_name(AuroraConfig(base_job(environment=env_name)))
Example #8
0
def test_config_with_task_links():
    tl = Map(String, String)
    unresolved_tl = {
        'foo': 'http://%host%:{{thermos.ports[foo]}}',
        'bar': 'http://%host%:{{thermos.ports[bar]}}/{{mesos.instance}}',
    }
    resolved_tl = {
        'foo': 'http://%host%:%port:foo%',
        'bar': 'http://%host%:%port:bar%/%shard_id%'
    }
    aurora_config = AuroraConfig(HELLO_WORLD(task_links=tl(unresolved_tl)))
    assert aurora_config.task_links() == tl(resolved_tl)
    assert aurora_config.job().taskConfig.taskLinks == frozendict(resolved_tl)

    bad_tl = {'foo': '{{thermos.ports.bad}}'}
    with pytest.raises(AuroraConfig.InvalidConfig):
        AuroraConfig(HELLO_WORLD(task_links=tl(bad_tl))).job()
Example #9
0
def test_config_with_task_links():
  tl = Map(String, String)
  unresolved_tl = {
    'foo': 'http://%host%:{{thermos.ports[foo]}}',
    'bar': 'http://%host%:{{thermos.ports[bar]}}/{{mesos.instance}}',
  }
  resolved_tl = {
    'foo': 'http://%host%:%port:foo%',
    'bar': 'http://%host%:%port:bar%/%shard_id%'
  }
  aurora_config = AuroraConfig(HELLO_WORLD(task_links = tl(unresolved_tl)))
  assert aurora_config.task_links() == tl(resolved_tl)
  assert aurora_config.job().taskConfig.taskLinks == frozendict(resolved_tl)

  bad_tl = {
    'foo': '{{thermos.ports.bad}}'
  }
  with pytest.raises(AuroraConfig.InvalidConfig):
    AuroraConfig(HELLO_WORLD(task_links=tl(bad_tl))).job()
Example #10
0
def test_dedicated_portmap():
  base_job = Job(
      name='hello_world', role='john_doe', cluster='smf1-test',
      task=Task(name='main', processes=[],
                resources=Resources(cpu=0.1, ram=64 * MB, disk=64 * MB)))

  config._validate_announce_configuration(AuroraConfig(base_job))
  config._validate_announce_configuration(
      AuroraConfig(base_job(constraints={'dedicated': 'mesos-team'})))
  config._validate_announce_configuration(
      AuroraConfig(base_job(constraints={'dedicated': 'mesos-team'},
                            announce=Announcer(portmap={'http': 80}))))

  with pytest.raises(ValueError):
    config._validate_announce_configuration(
        AuroraConfig(base_job(announce=Announcer(portmap={'http': 80}))))

  with pytest.raises(ValueError):
    config._validate_announce_configuration(
        AuroraConfig(base_job(announce=Announcer(portmap={'http': 80}),
                              constraints={'foo': 'bar'})))
Example #11
0
def make_config(announce, *ports):
    process = Process(name='hello',
                      cmdline=' '.join('{{thermos.ports[%s]}}' % port
                                       for port in ports))
    return AuroraConfig(
        Job(name='hello_world',
            environment='staging42',
            role='john_doe',
            cluster='smf1-test',
            announce=announce,
            task=Task(name='main',
                      processes=[process],
                      resources=Resources(cpu=0.1,
                                          ram=64 * 1048576,
                                          disk=64 * 1048576))))
Example #12
0
def test_inject_default_environment():
  base_job = Job(
      name='hello_world', role='john_doe', cluster='smf1-test',
      task=Task(name='main', processes=[],
                resources=Resources(cpu=0.1, ram=64 * MB, disk=64 * MB)))

  no_env_config = AuroraConfig(base_job)
  config._inject_default_environment(no_env_config)
  assert no_env_config.environment() == DEFAULT_ENVIRONMENT

  test_env_config = AuroraConfig(base_job(environment='test'))
  config._inject_default_environment(test_env_config)
  assert test_env_config.environment() == 'test'
Example #13
0
def test_empty_config():
    with pytest.raises(AuroraConfig.InvalidConfig):
        with temporary_file() as fp:
            fp.write(UNDERSPECIFIED_MESOS_CONFIG)
            fp.flush()
            AuroraConfig.load(fp.name)
def write_and_load_config(role):
  with temporary_file() as fp:
    fp.write(GENERIC_CONFIG)
    fp.flush()
    return AuroraConfig.load(fp.name, name='hello_world', select_role=role)
Example #15
0
def write_and_load_config(role):
    with temporary_file() as fp:
        fp.write(GENERIC_CONFIG)
        fp.flush()
        return AuroraConfig.load(fp.name, name='hello_world', select_role=role)
Example #16
0
 def job_command(cmdline):
     return AuroraConfig(
         HELLO_WORLD(task=SimpleTask('hello_world', cmdline))).raw()
Example #17
0
def test_empty_config():
  with pytest.raises(AuroraConfig.InvalidConfig):
    with temporary_file() as fp:
      fp.write(UNDERSPECIFIED_MESOS_CONFIG)
      fp.flush()
      AuroraConfig.load(fp.name)