def parse_module_config(self, plug_set, plug_name, plug_config):
     """Parse module config and update the pluggable module set"""
     if self.local_event_registry.check(plug_name):
         plug_class = self.local_event_registry.get_class(plug_name)
         plug_set["events"].append(
             plug_class(self.test_object, self.event_triggered, plug_config))
     elif self.local_action_registry.check(plug_name):
         plug_class = self.local_action_registry.get_class(plug_name)
         plug_set["actions"].append(
             plug_class(self.test_object, plug_config))
     elif PLUGGABLE_EVENT_REGISTRY.check(plug_name):
         plug_class = PLUGGABLE_EVENT_REGISTRY.get_class(plug_name)
         plug_set["events"].append(
             plug_class(self.test_object, self.event_triggered, plug_config))
     elif PLUGGABLE_ACTION_REGISTRY.check(plug_name):
         plug_class = PLUGGABLE_ACTION_REGISTRY.get_class(plug_name)
         plug_set["actions"].append(
             plug_class(self.test_object, plug_config))
     else:
         raise Exception("Pluggable component '%s' not recognized"
                         % plug_name)
Beispiel #2
0
 def parse_module_config(self, plug_set, plug_name, plug_config):
     """Parse module config and update the pluggable module set"""
     if self.local_event_registry.check(plug_name):
         plug_class = self.local_event_registry.get_class(plug_name)
         plug_set["events"].append(
             plug_class(self.test_object, self.event_triggered, plug_config))
     elif self.local_action_registry.check(plug_name):
         plug_class = self.local_action_registry.get_class(plug_name)
         plug_set["actions"].append(
             plug_class(self.test_object, plug_config))
     elif PLUGGABLE_EVENT_REGISTRY.check(plug_name):
         plug_class = PLUGGABLE_EVENT_REGISTRY.get_class(plug_name)
         plug_set["events"].append(
             plug_class(self.test_object, self.event_triggered, plug_config))
     elif PLUGGABLE_ACTION_REGISTRY.check(plug_name):
         plug_class = PLUGGABLE_ACTION_REGISTRY.get_class(plug_name)
         plug_set["actions"].append(
             plug_class(self.test_object, plug_config))
     else:
         raise Exception("Pluggable component '%s' not recognized"
                         % plug_name)
Beispiel #3
0

class AMIStartEventModule(object):
    """An event module that triggers when the test starts."""

    def __init__(self, test_object, triggered_callback, config):
        """Setup the test start observer"""
        self.test_object = test_object
        self.triggered_callback = triggered_callback
        self.config = config
        test_object.register_ami_observer(self.start_observer)

    def start_observer(self, ami):
        """Notify the event-action mapper that ami has started."""
        self.triggered_callback(self, ami)
PLUGGABLE_EVENT_REGISTRY.register("ami-start", AMIStartEventModule)


class AMIPluggableEventInstance(AMIHeaderMatchInstance):
    """Subclass of AMIEventInstance that works with the pluggable event action
    module.

    Events can be set to 'trigger-on-count' meaning (when set to True) the
    trigger callback will not be called until the min count is reached. For
    event/actions this means actions won't be executed until an event reaches
    its specified count. If the configured count allows for an infinite max
    (ie. '>1'), the actions will only be executed upon the minimum count being
    reached. Additional occurrences of the event will not trigger the actions
    again.
    """
            action_mod.run(triggered_by, source, extra)

class TestStartEventModule(object):
    """An event module that triggers when the test starts."""

    def __init__(self, test_object, triggered_callback, config):
        """Setup the test start observer"""
        self.test_object = test_object
        self.triggered_callback = triggered_callback
        self.config = config
        test_object.register_start_observer(self.start_observer)

    def start_observer(self, ast):
        """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):
Beispiel #5
0
        :param args: Ignored arguments.
        """
        for event_desc in self.config:
            if not event_desc["expected_count_range"].contains(
                    event_desc["event_count"]):
                # max could be int or float('inf'); format with %r
                LOGGER.error("Expected %d <= count <= %r; was %d (%r, !%r)",
                             event_desc["expected_count_range"].min_value,
                             event_desc["expected_count_range"].max_value,
                             event_desc["event_count"], event_desc["match"],
                             event_desc.get("nomatch", None))
                self.test_object.set_passed(False)
            self.test_object.set_passed(True)


PLUGGABLE_EVENT_REGISTRY.register("ari-events", ARIPluggableEventModule)


class ARIPluggableStartModule(object):
    """Pluggable ARI module that kicks off when Asterisk starts
    """
    def __init__(self, test_object, triggered_callback, config):
        """Constructor"""

        self.triggered_callback = triggered_callback
        self.test_object = test_object

        # AMI connects after ARI, so this should call back once we're
        # good and ready
        test_object.register_ami_observer(self.on_ami_connect)
class TestStartEventModule(object):
    """An event module that triggers when the test starts."""
    def __init__(self, test_object, triggered_callback, config):
        """Setup the test start observer"""
        self.test_object = test_object
        self.triggered_callback = triggered_callback
        self.config = config
        test_object.register_start_observer(self.start_observer)

    def start_observer(self, ast):
        """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)
Beispiel #7
0
        """Callback for the end of the test.

        :param args: Ignored arguments.
        """
        for event_desc in self.config:
            if not event_desc["expected_count_range"].contains(event_desc["event_count"]):
                # max could be int or float('inf'); format with %r
                LOGGER.error("Expected %d <= count <= %r; was %d (%r, !%r)",
                             event_desc["expected_count_range"].min_value,
                             event_desc["expected_count_range"].max_value,
                             event_desc["event_count"],
                             event_desc["match"],
                             event_desc.get("nomatch", None))
                self.test_object.set_passed(False)
            self.test_object.set_passed(True)
PLUGGABLE_EVENT_REGISTRY.register("ari-events", ARIPluggableEventModule)


class ARIPluggableStartModule(object):
    """Pluggable ARI module that kicks off when Asterisk starts
    """

    def __init__(self, test_object, triggered_callback, config):
        """Constructor"""

        self.triggered_callback = triggered_callback
        self.test_object = test_object

        # AMI connects after ARI, so this should call back once we're
        # good and ready
        test_object.register_ami_observer(self.on_ami_connect)
Beispiel #8
0
        Keyword Arguments:
        test_object - The TestCase driver
        triggered_callback - Conditionally called when matched
        config - Configuration for this module

        Configuration options:
        type - The <module.class> of the object type to create that is
            listens for events and passes event data to the conditional
            matcher.
        """

        self.triggered_callback = triggered_callback

        module_name, _, obj_type = config['type'].partition('.')

        module = __import__(module_name, fromlist=[obj_type])
        if not module:
            raise Exception(
                "Unable to import module '{0}'.".format(module_name))

        obj = getattr(module, obj_type)

        self.conditions = obj(config, test_object, self.__handle_match)

    def __handle_match(self, matched, event):
        self.triggered_callback(self, matched, event)


PLUGGABLE_EVENT_REGISTRY.register('event', PluggableConditionsEventModule)
Beispiel #9
0
class AMIStartEventModule(object):
    """An event module that triggers when the test starts."""
    def __init__(self, test_object, triggered_callback, config):
        """Setup the test start observer"""
        self.test_object = test_object
        self.triggered_callback = triggered_callback
        self.config = config
        test_object.register_ami_observer(self.start_observer)

    def start_observer(self, ami):
        """Notify the event-action mapper that ami has started."""
        self.triggered_callback(self, ami)


PLUGGABLE_EVENT_REGISTRY.register("ami-start", AMIStartEventModule)


class AMIPluggableEventInstance(AMIHeaderMatchInstance):
    """Subclass of AMIEventInstance that works with the pluggable event action
    module.
    """
    def __init__(self, test_object, triggered_callback, config, data):
        """Setup the AMI event observer"""
        self.triggered_callback = triggered_callback
        self.data = data
        super(AMIPluggableEventInstance, self).__init__(config, test_object)

    def event_callback(self, ami, event):
        """Callback called when an event is received from AMI"""
        super(AMIPluggableEventInstance, self).event_callback(ami, event)