Beispiel #1
0
def test_get_task_from_options():
  options_mock = get_options_mock()

  with three_configs() as (config_path, multi_path, _):
    # from single file w/o .task
    task = get_task_from_options([config_path], options_mock)
    assert str(task.task.name()) == 'task'

    # from .json
    json_path = config_path + '.json'
    task.to_file(json_path)
    options_mock.task = None
    options_mock.json = True
    task = get_task_from_options([json_path], options_mock)
    assert str(task.task.name()) == 'task'
    options_mock.json = False

    # from multi file
    options_mock.task = 'task1'
    task = get_task_from_options([multi_path], options_mock)
    assert str(task.task.name()) == 'task1'

    options_mock.task = 'task2'
    task = get_task_from_options([multi_path], options_mock)
    assert str(task.task.name()) == 'task2'
Beispiel #2
0
def test_get_task_from_options_invalid(error_mock):
  error_mock.side_effect = raise_exception
  options_mock = get_options_mock()

  with three_configs() as (config_path, multi_path, empty_path):
    exc = catch_exception(lambda: get_task_from_options([], options_mock))
    assert exc is not None
    assert exc.startswith('Should specify precisely one config')

    exc = catch_exception(lambda: get_task_from_options([config_path, config_path], options_mock))
    assert exc is not None
    assert exc.startswith('Should specify precisely one config')

    # unknown task name
    options_mock.task = 'unknown'
    exc = catch_exception(lambda: get_task_from_options([config_path], options_mock))
    assert exc is not None
    assert exc.startswith('Could not find task')

    # multiple tasks but not disambiguated
    options_mock.task = None
    exc = catch_exception(lambda: get_task_from_options([multi_path], options_mock))
    assert exc is not None
    assert exc.startswith('Multiple tasks in config but no task name specified')

    # no tasks defined
    exc = catch_exception(lambda: get_task_from_options([empty_path], options_mock))
    assert exc is not None
    assert exc.startswith('No tasks specified')
Beispiel #3
0
def inspect(args, options):
    """Inspect a thermos config and display the evaluated task

    Usage: thermos inspect [options] config
  """
    thermos_task = get_task_from_options(args, options)
    ti, _ = thermos_task.task().interpolate()
    pprint.pprint(inspect_unwrap(ti.get()), indent=4)
Beispiel #4
0
def inspect(args, options):
  """Inspect a thermos config and display the evaluated task

    Usage: thermos inspect [options] config
  """
  thermos_task = get_task_from_options(args, options)
  ti, _ = thermos_task.task().interpolate()
  pprint.pprint(inspect_unwrap(ti.get()), indent=4)
Beispiel #5
0
def run(args, options):

  """Run a thermos task.

    Usage: thermos run [options] config
  """
  thermos_task = get_task_from_options(args, options)
  really_run(thermos_task,
             options.root,
             options.sandbox,
             task_id=options.task_id,
             user=options.user,
             prebound_ports=options.prebound_ports,
             chroot=options.chroot,
             daemon=options.daemon)