Example #1
0
                                                            self))
PLUGGABLE_EVENT_REGISTRY.register("ami-events", AMIPluggableEventModule)


def replace_ami_vars(mydict, values):
    outdict = {}
    for key, value in mydict.iteritems():
        outdict[key] = var_replace(value, values)

    return outdict


class AMIPluggableActionModule(object):
    """Pluggable AMI action module.
    """

    def __init__(self, test_object, config):
        """Setup the AMI event observer"""
        self.test_object = test_object
        if not isinstance(config, list):
            config = [config]
        self.config = config

    def run(self, triggered_by, source, extra):
        """Callback called when this action is triggered."""
        for instance in self.config:
            action = replace_ami_vars(instance["action"], extra)
            ami_id = instance.get("id", 0)
            self.test_object.ami[ami_id].sendMessage(action)
PLUGGABLE_ACTION_REGISTRY.register("ami-actions", AMIPluggableActionModule)
Example #2
0
        self.triggered_callback(self, ast)
PLUGGABLE_EVENT_REGISTRY.register("test-start", TestStartEventModule)


class LogActionModule(object):
    """An action module that logs a message when triggered."""

    def __init__(self, test_object, config):
        """Setup the test start observer"""
        self.test_object = test_object
        self.message = config["message"]

    def run(self, triggered_by, source, extra):
        """Log a message."""
        LOGGER.info(self.message)
PLUGGABLE_ACTION_REGISTRY.register("logger", LogActionModule)


class ValidateLogActionModule(object):
    """An action module that validates a log files existence."""

    def __init__(self, test_object, config):
        self.test_object = test_object
        self.logfile = config["logfile"]
        self.pass_if_present = config["pass-if-present"]

    def run(self, triggered_by, source, extra):
        """Check to see if log file is present or not."""
        files = []
        testpath = ('%s/var/log/asterisk' %
                    (self.test_object.ast[0].base))
        """Notify the event-action mapper that the test has started."""
        self.triggered_callback(self, ast)
PLUGGABLE_EVENT_REGISTRY.register("test-start", TestStartEventModule)

class LogActionModule(object):
    """An action module that logs a message when triggered."""

    def __init__(self, test_object, config):
        """Setup the test start observer"""
        self.test_object = test_object
        self.message = config["message"]

    def run(self, triggered_by, source, extra):
        """Log a message."""
        LOGGER.info(self.message)
PLUGGABLE_ACTION_REGISTRY.register("logger", LogActionModule)

class CallbackActionModule(object):
    """An action module that calls the specified callback."""

    def __init__(self, test_object, config):
        """Setup the test start observer"""
        self.test_object = test_object
        self.module = config["module"]
        self.method = config["method"]

    def run(self, triggered_by, source, extra):
        """Call the callback."""
        module = __import__(self.module)
        method = getattr(module, self.method)
        self.test_object.set_passed(method(self.test_object, triggered_by,
Example #4
0
    def __init__(self, test_object, config):
        """Setup the ARI event observer"""
        self.test_object = test_object
        if not isinstance(config, list):
            config = [config]
        self.requests = [
            ARIRequest(test_object.ari, request_config)
            for request_config in config
        ]
        self.count = 0

    def run(self, triggered_by, source, extra):
        """Callback called when this action is triggered."""
        self.count += 1
        for request in self.requests:
            if request.instance and request.instance != self.count:
                continue
            if request.delay:
                reactor.callLater(request.delay, request.send, extra)
            else:
                result = request.send(extra)
                if isinstance(result, bool) and not result:
                    self.test_object.set_passed(False)
                else:
                    self.test_object.set_passed(True)


PLUGGABLE_ACTION_REGISTRY.register("ari-requests", ARIPluggableRequestModule)

# vim:sw=4:ts=4:expandtab:textwidth=79
PLUGGABLE_EVENT_REGISTRY.register("test-start", TestStartEventModule)


class LogActionModule(object):
    """An action module that logs a message when triggered."""
    def __init__(self, test_object, config):
        """Setup the test start observer"""
        self.test_object = test_object
        self.message = config["message"]

    def run(self, triggered_by, source, extra):
        """Log a message."""
        LOGGER.info(self.message)


PLUGGABLE_ACTION_REGISTRY.register("logger", LogActionModule)


class ValidateLogActionModule(object):
    """An action module that validates a log files existence."""
    def __init__(self, test_object, config):
        self.test_object = test_object
        self.logfile = config["logfile"]
        self.pass_if_present = config["pass-if-present"]

    def run(self, triggered_by, source, extra):
        """Check to see if log file is present or not."""
        files = []
        testpath = ('%s/var/log/asterisk' % (self.test_object.ast[0].base))
        for (dirpath, dirnames, filenames) in os.walk(testpath):
            files.extend(filenames)
Example #6
0
class ARIPluggableRequestModule(object):
    """Pluggable ARI action module.
    """

    def __init__(self, test_object, config):
        """Setup the ARI event observer"""
        self.test_object = test_object
        if not isinstance(config, list):
            config = [config]
        self.requests = [ARIRequest(test_object.ari, request_config)
                         for request_config in config]
        self.count = 0

    def run(self, triggered_by, source, extra):
        """Callback called when this action is triggered."""
        self.count += 1
        for request in self.requests:
            if request.instance and request.instance != self.count:
                continue
            if request.delay:
                reactor.callLater(request.delay, request.send, extra)
            else:
                result = request.send(extra)
                if isinstance(result, bool) and not result:
                    self.test_object.set_passed(False)
                else:
                    self.test_object.set_passed(True)
PLUGGABLE_ACTION_REGISTRY.register("ari-requests", ARIPluggableRequestModule)

# vim:sw=4:ts=4:expandtab:textwidth=79
Example #7
0
PLUGGABLE_EVENT_REGISTRY.register("test-start", TestStartEventModule)


class LogActionModule(object):
    """An action module that logs a message when triggered."""
    def __init__(self, test_object, config):
        """Setup the test start observer"""
        self.test_object = test_object
        self.message = config["message"]

    def run(self, triggered_by, source, extra):
        """Log a message."""
        LOGGER.info(self.message)


PLUGGABLE_ACTION_REGISTRY.register("logger", LogActionModule)


class CallbackActionModule(object):
    """An action module that calls the specified callback."""
    def __init__(self, test_object, config):
        """Setup the test start observer"""
        self.test_object = test_object
        self.module = config["module"]
        self.method = config["method"]

    def run(self, triggered_by, source, extra):
        """Call the callback."""
        module = __import__(self.module)
        method = getattr(module, self.method)
        self.test_object.set_passed(
Example #8
0
PLUGGABLE_EVENT_REGISTRY.register("ami-events", AMIPluggableEventModule)


def replace_ami_vars(mydict, values):
    outdict = {}
    for key, value in mydict.iteritems():
        outdict[key] = var_replace(value, values)

    return outdict


class AMIPluggableActionModule(object):
    """Pluggable AMI action module.
    """
    def __init__(self, test_object, config):
        """Setup the AMI event observer"""
        self.test_object = test_object
        if not isinstance(config, list):
            config = [config]
        self.config = config

    def run(self, triggered_by, source, extra):
        """Callback called when this action is triggered."""
        for instance in self.config:
            action = replace_ami_vars(instance["action"], extra)
            ami_id = instance.get("id", 0)
            self.test_object.ami[ami_id].sendMessage(action)


PLUGGABLE_ACTION_REGISTRY.register("ami-actions", AMIPluggableActionModule)