def test_register_experiment():
    from lttngcluster.api import TraceExperiment
    from lttngcluster.experiments.reg import registry, AlreadyRegistered, NotRegistered

    class TestExperiment(TraceExperiment):
        def validate(self, errors):
            pass

    registry.register(TestExperiment)
    exp = registry.get_experiment('TestExperiment')
    exception1 = None
    exception2 = None
    try:
        registry.register(TestExperiment)
    except Exception as e:
        exception1 = e
    try:
        registry.get_experiment('bidon')
    except Exception as e:
        exception2 = e

    assert isinstance(exp, TraceExperiment)
    assert isinstance(exception1, AlreadyRegistered)
    assert isinstance(exception2, NotRegistered)
Exemple #2
0
from fabric.operations import local

from lttngcluster.api import TraceExperiment
from lttngcluster.experiments.reg import registry

class TraceExperimentClientServerRequest(TraceExperiment):
    def __init__(self):
        super(TraceExperimentClientServerRequest, self).__init__()

    def validate(self, errors):
        pass

    def before(self):
        opts = self.get_options()
        opts.get('params', {}).get('start_server', None)
        pass

    def action(self):
        # make request
        pass

    def after(self):
        # stop server
        pass

registry.register(TraceExperimentClientServerRequest)
                    roles = execute.get('roles', [])
                    if not hasattr(roles, '__iter__'):
                        roles = [roles]
                    for role in roles:
                        if role not in roledefs:
                            err.add('reference to undefined role: %s' % (role))
        ev = opts.get('events', {})
        for k, v in ev.items():
            if not isinstance(v, list):
                err.add('wrong type for event list %s: %s' % (k, type(v)))

    def action(self):
        opts = self.get_options()
        cmds = opts.get('execute', [])
        env.roledefs = opts['roledefs']
        for cmd in cmds:
            if not cmd.has_key('command') or \
                not isinstance(cmd.get('command'), str):
                raise ValueError('wrong command')
            method = cmd.get('method', default_method)
            if not run_methods.has_key(method):
                raise ValueError('wrong run method: %s' % (method))
            func = run_methods[method]
            roles = cmd.get('roles', [])
            if not hasattr(roles, '__iter__'):
                roles = [roles]
            command = cmd.get('command') % opts.get_context()
            execute(func, command, roles=roles)

registry.register(TraceExperimentShell)