Exemplo n.º 1
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'
Exemplo n.º 2
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))))
Exemplo n.º 3
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)))
Exemplo n.º 4
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'})))
Exemplo n.º 5
0
                         max_failures = 200)],
    resources = Resources(cpu = 0.1, ram = 64 * 1048576, disk = 64 * 1048576),
  )
)
jobs = [HELLO_WORLD]
"""

REIFIED_CONFIG = Job(name='hello_world',
                     role='john_doe',
                     environment='staging42',
                     cluster='smf1-test',
                     task=Task(
                         name='main',
                         processes=[
                             Process(name='hello_world',
                                     cmdline='echo {{mesos.instance}}')
                         ],
                         resources=Resources(cpu=0.1,
                                             ram=64 * 1048576,
                                             disk=64 * 1048576),
                     ))

REIFIED_LIMITED_CONFIG = Job(name='hello_world',
                             role='john_doe',
                             environment='staging42',
                             cluster='smf1-test',
                             task=Task(
                                 name='main',
                                 processes=[
                                     Process(name='hello_world_fails_0',
                                             cmdline='echo hello world',
                                             max_failures=0),
Exemplo n.º 6
0
)
from twitter.aurora.executor.common.sandbox import DirectorySandbox
from twitter.aurora.executor.common.status_checker import ExitState
from twitter.aurora.executor.thermos_task_runner import ThermosTaskRunner
from twitter.common import log
from twitter.common.log.options import LogOptions
from twitter.common.dirutil import safe_rmtree
from twitter.common.quantity import Amount, Time
from twitter.common.contextutil import temporary_dir

TASK = MesosTaskInstance(
    instance=0,
    role=getpass.getuser(),
    task=Task(
        resources=Resources(cpu=1.0, ram=16 * MB, disk=32 * MB),
        name='hello_world',
        processes=[Process(name='hello_world', cmdline='{{command}}')],
    ))


class TestThermosTaskRunnerIntegration(object):
    PANTS_BUILT = False
    LOG_DIR = None

    @classmethod
    def setup_class(cls):
        cls.LOG_DIR = tempfile.mkdtemp()
        LogOptions.set_log_dir(cls.LOG_DIR)
        LogOptions.set_disk_log_level('DEBUG')
        log.init('executor_logger')
        if not cls.PANTS_BUILT and 'SKIP_PANTS_BUILD' not in os.environ:
Exemplo n.º 7
0
    at = AssignedTask(taskId=task_id,
                      task=TaskConfig(executorConfig=ExecutorConfig(
                          name=AURORA_EXECUTOR_NAME,
                          data=thermos_config.json_dumps()),
                                      owner=Identity(role=role, user=role)),
                      assignedPorts=assigned_ports,
                      **kw)
    td = mesos_pb.TaskInfo()
    td.task_id.value = task_id
    td.name = thermos_config.task().name().get()
    td.data = serialize(at)
    return td


BASE_MTI = MesosTaskInstance(instance=0, role=getpass.getuser())
BASE_TASK = Task(resources=Resources(cpu=1.0, ram=16 * MB, disk=32 * MB))

HELLO_WORLD_TASK_ID = 'hello_world-001'
HELLO_WORLD = BASE_TASK(name='hello_world',
                        processes=[
                            Process(name='hello_world_{{thermos.task_id}}',
                                    cmdline='echo hello world')
                        ])
HELLO_WORLD_MTI = BASE_MTI(task=HELLO_WORLD)

SLEEP60 = BASE_TASK(processes=[Process(name='sleep60', cmdline='sleep 60')])
SLEEP2 = BASE_TASK(processes=[Process(name='sleep2', cmdline='sleep 2')])
SLEEP60_MTI = BASE_MTI(task=SLEEP60)

MESOS_JOB = MesosJob(
    name='does_not_matter',