예제 #1
0
def test_cron_policy_alias():
    cron_schedule = '*/10 * * * *'
    CRON_HELLO_WORLD = HELLO_WORLD(cron_schedule=cron_schedule)

    tti = convert_pystachio_to_thrift(CRON_HELLO_WORLD)
    assert tti.cronSchedule == cron_schedule
    assert tti.cronCollisionPolicy == CronCollisionPolicy.KILL_EXISTING

    tti = convert_pystachio_to_thrift(
        CRON_HELLO_WORLD(cron_policy='RUN_OVERLAP'))
    assert tti.cronSchedule == cron_schedule
    assert tti.cronCollisionPolicy == CronCollisionPolicy.RUN_OVERLAP

    tti = convert_pystachio_to_thrift(
        CRON_HELLO_WORLD(cron_collision_policy='RUN_OVERLAP'))
    assert tti.cronSchedule == cron_schedule
    assert tti.cronCollisionPolicy == CronCollisionPolicy.RUN_OVERLAP

    with pytest.raises(ValueError):
        tti = convert_pystachio_to_thrift(
            CRON_HELLO_WORLD(cron_policy='RUN_OVERLAP',
                             cron_collision_policy='RUN_OVERLAP'))

    with pytest.raises(ValueError):
        tti = convert_pystachio_to_thrift(
            CRON_HELLO_WORLD(cron_collision_policy='GARBAGE'))
예제 #2
0
def test_packages_in_config():
  job = convert_pystachio_to_thrift(HELLO_WORLD, packages = [('alpha', 'beta', 1)])
  assert job.instanceCount == 1
  tti = job.taskConfig

  assert len(tti.packages) == 1
  pi = iter(tti.packages).next()
  assert pi.role == 'alpha'
  assert pi.name == 'beta'
  assert pi.version == 1
예제 #3
0
def test_packages_in_config():
    job = convert_pystachio_to_thrift(HELLO_WORLD,
                                      packages=[('alpha', 'beta', 1)])
    assert job.instanceCount == 1
    tti = job.taskConfig

    assert len(tti.packages) == 1
    pi = iter(tti.packages).next()
    assert pi.role == 'alpha'
    assert pi.name == 'beta'
    assert pi.version == 1
예제 #4
0
def test_cron_policy_alias():
  cron_schedule = '*/10 * * * *'
  CRON_HELLO_WORLD = HELLO_WORLD(cron_schedule=cron_schedule)

  tti = convert_pystachio_to_thrift(CRON_HELLO_WORLD)
  assert tti.cronSchedule == cron_schedule
  assert tti.cronCollisionPolicy == CronCollisionPolicy.KILL_EXISTING

  tti = convert_pystachio_to_thrift(CRON_HELLO_WORLD(cron_policy='RUN_OVERLAP'))
  assert tti.cronSchedule == cron_schedule
  assert tti.cronCollisionPolicy == CronCollisionPolicy.RUN_OVERLAP

  tti = convert_pystachio_to_thrift(CRON_HELLO_WORLD(cron_collision_policy='RUN_OVERLAP'))
  assert tti.cronSchedule == cron_schedule
  assert tti.cronCollisionPolicy == CronCollisionPolicy.RUN_OVERLAP

  with pytest.raises(ValueError):
    tti = convert_pystachio_to_thrift(CRON_HELLO_WORLD(cron_policy='RUN_OVERLAP',
                                                       cron_collision_policy='RUN_OVERLAP'))

  with pytest.raises(ValueError):
    tti = convert_pystachio_to_thrift(CRON_HELLO_WORLD(cron_collision_policy='GARBAGE'))
예제 #5
0
def test_unbound_references():
  def job_command(cmdline):
    return AuroraConfig(HELLO_WORLD(task = SimpleTask('hello_world', cmdline))).raw()

  # bindingless and bad => good bindings should work
  convert_pystachio_to_thrift(job_command('echo hello world'))
  convert_pystachio_to_thrift(job_command('echo {{mesos.user}}')
      .bind(mesos = {'user': '******'}))

  # unbound
  with pytest.raises(InvalidConfig):
    convert_pystachio_to_thrift(job_command('echo {{mesos.user}}'))
예제 #6
0
def test_unbound_references():
    def job_command(cmdline):
        return AuroraConfig(
            HELLO_WORLD(task=SimpleTask('hello_world', cmdline))).raw()

    # bindingless and bad => good bindings should work
    convert_pystachio_to_thrift(job_command('echo hello world'))
    convert_pystachio_to_thrift(
        job_command('echo {{mesos.user}}').bind(
            mesos={'user': '******'}))

    # unbound
    with pytest.raises(InvalidConfig):
        convert_pystachio_to_thrift(job_command('echo {{mesos.user}}'))
예제 #7
0
def test_config_with_options():
    hwc = HELLO_WORLD(production=True,
                      priority=200,
                      service=True,
                      cron_policy='RUN_OVERLAP',
                      constraints={
                          'dedicated': 'your_mom',
                          'cpu': 'x86_64'
                      },
                      environment='prod')
    job = convert_pystachio_to_thrift(hwc)
    assert job.instanceCount == 1
    tti = job.taskConfig

    assert tti.production == True
    assert tti.priority == 200
    assert tti.isService == True
    assert job.cronCollisionPolicy == CronCollisionPolicy.RUN_OVERLAP
    assert len(tti.constraints) == 2
    assert tti.environment == 'prod'
    assert job.key.environment == 'prod'
예제 #8
0
def test_simple_config():
    job = convert_pystachio_to_thrift(HELLO_WORLD)
    assert job.instanceCount == 1
    tti = job.taskConfig
    assert job.key == JobKey(role=HELLO_WORLD.role().get(),
                             environment=HELLO_WORLD.environment().get(),
                             name=HELLO_WORLD.name().get())
    assert job.owner == Identity(role=HELLO_WORLD.role().get(),
                                 user=getpass.getuser())
    assert job.cronSchedule == ''
    assert tti.jobName == 'hello_world'
    assert tti.isService == False
    assert tti.numCpus == 0.1
    assert tti.ramMb == 64
    assert tti.diskMb == 64
    assert tti.requestedPorts == set()
    assert tti.production == False
    assert tti.priority == 0
    assert tti.maxTaskFailures == 1
    assert tti.constraints == set()
    assert tti.packages == set()
    assert tti.environment == HELLO_WORLD.environment().get()
예제 #9
0
def test_simple_config():
  job = convert_pystachio_to_thrift(HELLO_WORLD)
  assert job.instanceCount == 1
  tti = job.taskConfig
  assert job.key == JobKey(
    role=HELLO_WORLD.role().get(),
    environment=HELLO_WORLD.environment().get(),
    name=HELLO_WORLD.name().get())
  assert job.owner == Identity(role=HELLO_WORLD.role().get(), user=getpass.getuser())
  assert job.cronSchedule == ''
  assert tti.jobName == 'hello_world'
  assert tti.isService == False
  assert tti.numCpus == 0.1
  assert tti.ramMb == 64
  assert tti.diskMb == 64
  assert tti.requestedPorts == set()
  assert tti.production == False
  assert tti.priority == 0
  assert tti.maxTaskFailures == 1
  assert tti.constraints == set()
  assert tti.packages == set()
  assert tti.environment == HELLO_WORLD.environment().get()
예제 #10
0
def test_config_with_options():
  hwc = HELLO_WORLD(
    production = True,
    priority = 200,
    service = True,
    cron_policy = 'RUN_OVERLAP',
    constraints = {
      'dedicated': 'your_mom',
      'cpu': 'x86_64'
    },
    environment = 'prod'
  )
  job = convert_pystachio_to_thrift(hwc)
  assert job.instanceCount == 1
  tti = job.taskConfig

  assert tti.production == True
  assert tti.priority == 200
  assert tti.isService == True
  assert job.cronCollisionPolicy == CronCollisionPolicy.RUN_OVERLAP
  assert len(tti.constraints) == 2
  assert tti.environment == 'prod'
  assert job.key.environment == 'prod'
예제 #11
0
def test_config_with_bad_resources():
    MB = 1048576
    hwtask = HELLO_WORLD.task()

    convert_pystachio_to_thrift(HELLO_WORLD)

    good_resources = [Resources(cpu=1.0, ram=1 * MB, disk=1 * MB)]

    bad_resources = [
        Resources(cpu=0, ram=1 * MB, disk=1 * MB),
        Resources(cpu=1, ram=0 * MB, disk=1 * MB),
        Resources(cpu=1, ram=1 * MB, disk=0 * MB),
        Resources(cpu=1, ram=1 * MB - 1, disk=1 * MB),
        Resources(cpu=1, ram=1 * MB, disk=1 * MB - 1)
    ]

    for resource in good_resources:
        convert_pystachio_to_thrift(
            HELLO_WORLD(task=hwtask(resources=resource)))

    for resource in bad_resources:
        with pytest.raises(ValueError):
            convert_pystachio_to_thrift(
                HELLO_WORLD(task=hwtask(resources=resource)))
예제 #12
0
def test_config_with_bad_resources():
  MB = 1048576
  hwtask = HELLO_WORLD.task()

  convert_pystachio_to_thrift(HELLO_WORLD)

  good_resources = [
    Resources(cpu = 1.0, ram = 1 * MB, disk = 1 * MB)
  ]

  bad_resources = [
    Resources(cpu = 0, ram = 1 * MB, disk = 1 * MB),
    Resources(cpu = 1, ram = 0 * MB, disk = 1 * MB),
    Resources(cpu = 1, ram = 1 * MB, disk = 0 * MB),
    Resources(cpu = 1, ram = 1 * MB - 1, disk = 1 * MB),
    Resources(cpu = 1, ram = 1 * MB, disk = 1 * MB - 1)
  ]

  for resource in good_resources:
    convert_pystachio_to_thrift(HELLO_WORLD(task = hwtask(resources = resource)))

  for resource in bad_resources:
    with pytest.raises(ValueError):
      convert_pystachio_to_thrift(HELLO_WORLD(task = hwtask(resources = resource)))