Exemplo n.º 1
0
def test_load_include():
    from lttngcluster.api import TraceExperimentOptions
    import tempfile
    from os.path import join
    from shutil import rmtree

    content = { 'recipe_a.yaml': '''a: a\nb: b''',
                'recipe_b.yaml': '''import: recipe_a\nb: x\nz: z''',
                'recipe_c.yaml': '''import: recipe_b\nb: y\nc: c''',
    }
    exp = { 'a': 'a', 'b': 'y', 'c': 'c', 'z': 'z', 'name': 'recipe_c' }
    d = tempfile.mkdtemp()
    for k, v in content.items():
        with file(join(d, k), 'w+') as f:
            f.write(v)

    opts = TraceExperimentOptions()
    try:
        opts.load_path(join(d, 'recipe_c.yaml'))
    finally:
        rmtree(d)

    print(exp)
    print(opts)

    assert opts == exp
Exemplo n.º 2
0
def test_load_options():
    from lttngcluster.api import TraceExperimentOptions
    from lttngcluster.api import default_username

    override = 'foo'
    recipe = '''username: %s''' % (override)

    opts = TraceExperimentOptions(**TraceExperimentOptions.default_options)
    print(opts)
    assert opts['username'] == default_username
    opts.load(recipe)
    assert opts['username'] == override
Exemplo n.º 3
0
def test_trace_dir():
    from lttngcluster.api import TraceExperimentOptions
    import os
    opts = TraceExperimentOptions()

    data = { 'test1': { 'input': { }, 'exp': 'auto-ts' },
             'test2': { 'input': { 'foo': 'one', 'bar': 2 }, 'exp': 'auto-ts-foo=one-bar=2' }
    }

    opts._time = 'ts'
    for k, v in data.items():
        d = opts.get_trace_dir(**v['input'])
        print(d)
        assert d == os.path.join(default_trace_dir, v['exp'])
Exemplo n.º 4
0
def test_option_context():
    from lttngcluster.api import TraceExperimentOptions

    opts = TraceExperimentOptions()
    opts['parameters'] = {
        'delay': [1, 2, 3]
    }

    exp = [ { 'delay': 1 }, { 'delay': 2 }, { 'delay': 3 } ]
    act = []
    for ctx in opts.context_generator():
        assert ctx == opts.get_context()
        assert ctx == opts.get_context()
        act.append(ctx)
    assert exp == act
def cmd_trace_one(args, recipe):
    err = RecipeErrorCollection()
    opts = TraceExperimentOptions(**TraceExperimentOptions.default_options)
    opts.load_path(recipe)
    klass = registry.get_experiment(opts['experiment'])
    klass.set_options(opts)
    klass.validate(err)
    if len(err) > 0:
        pprint.pprint(opts)
        recipe_errors_show(recipe, err)
        raise Exception('validation error')
    if args.verbose:
        print('recipe:')
        pprint.pprint(opts)
    runner = TraceRunnerDefault()
    runner.set_dry_run(args.dry_run)
    runner.run(klass)
def recipe_verify(recipe, err):
    opts = TraceExperimentOptions(**TraceExperimentOptions.default_options)
    opts.load_path(recipe)
    klass = registry.get_experiment(opts['experiment'])
    klass.set_options(opts)
    klass.validate(err)