[asterisk-commits] jrose: testsuite/asterisk/trunk r2907 - in /asterisk/trunk/tests/queues: ./ s...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 16 08:58:32 CST 2011


Author: jrose
Date: Fri Dec 16 08:58:25 2011
New Revision: 2907

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=2907
Log:
Adds tests for 'queue set penalty' command and analogous AMI command

This test basically just has a few preset queue members in a number of queues and the
test is set up to test different uses of the command as a state machine. It then checks
QueuePenalty events sent in response to the commands and makes sure they are in line with
expectations. This test was made in response to a regression that was introduced when
adding realtime support to queue set penalty.

Review: https://reviewboard.asterisk.org/r/1611/

Added:
    asterisk/trunk/tests/queues/set_penalty/
    asterisk/trunk/tests/queues/set_penalty/configs/
    asterisk/trunk/tests/queues/set_penalty/configs/ast1/
    asterisk/trunk/tests/queues/set_penalty/configs/ast1/queues.conf   (with props)
    asterisk/trunk/tests/queues/set_penalty/configs/ast1/sip.conf   (with props)
    asterisk/trunk/tests/queues/set_penalty/run-test   (with props)
    asterisk/trunk/tests/queues/set_penalty/test-config.yaml   (with props)
Modified:
    asterisk/trunk/tests/queues/tests.yaml

Added: asterisk/trunk/tests/queues/set_penalty/configs/ast1/queues.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/queues/set_penalty/configs/ast1/queues.conf?view=auto&rev=2907
==============================================================================
--- asterisk/trunk/tests/queues/set_penalty/configs/ast1/queues.conf (added)
+++ asterisk/trunk/tests/queues/set_penalty/configs/ast1/queues.conf Fri Dec 16 08:58:25 2011
@@ -1,0 +1,14 @@
+[general]
+
+[queue1]
+member => sip/mem1
+member => sip/mem2
+member => sip/mem3
+
+[queue2]
+member => sip/mem2
+member => sip/mem3
+
+[queue3]
+member => sip/mem3
+member => sip/mem1

Propchange: asterisk/trunk/tests/queues/set_penalty/configs/ast1/queues.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/queues/set_penalty/configs/ast1/queues.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/queues/set_penalty/configs/ast1/queues.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/queues/set_penalty/configs/ast1/sip.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/queues/set_penalty/configs/ast1/sip.conf?view=auto&rev=2907
==============================================================================
--- asterisk/trunk/tests/queues/set_penalty/configs/ast1/sip.conf (added)
+++ asterisk/trunk/tests/queues/set_penalty/configs/ast1/sip.conf Fri Dec 16 08:58:25 2011
@@ -1,0 +1,15 @@
+[general]
+bindaddr=127.0.0.1
+context=default
+
+[mem1]
+type=friend
+host=dynamic
+
+[mem2]
+type=friend
+host=dynamic
+
+[mem3]
+type=friend
+host=dynamic

Propchange: asterisk/trunk/tests/queues/set_penalty/configs/ast1/sip.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/queues/set_penalty/configs/ast1/sip.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/queues/set_penalty/configs/ast1/sip.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/queues/set_penalty/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/queues/set_penalty/run-test?view=auto&rev=2907
==============================================================================
--- asterisk/trunk/tests/queues/set_penalty/run-test (added)
+++ asterisk/trunk/tests/queues/set_penalty/run-test Fri Dec 16 08:58:25 2011
@@ -1,0 +1,150 @@
+#!/usr/bin/env python
+'''
+Copyright (C) 2011, Digium, Inc.
+Jonathan Rose <jrose at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+import sys
+import logging
+from twisted.internet import reactor
+
+sys.path.append("lib/python")
+from asterisk.asterisk import Asterisk
+from asterisk.TestCase import TestCase
+from twisted.internet import reactor, defer
+from starpy import manager
+
+logger = logging.getLogger(__name__)
+
+"""
+Creates an Asterisk instance with some premade queues containing some premade sip peers as members
+and changes penalties by using CLI commands and manager actions.
+
+Tests against regression such as the one discussed in https://reviewboard.asterisk.org/r/1609/
+"""
+class QueuePenaltyTest(TestCase):
+    def __init__(self):
+        TestCase.__init__(self)
+        self.create_asterisk()
+        self.state = 0 # State of the test... determines next action and next event expectations.
+        self.passed = False
+        self.state_passed_flags = 0 # Meant to be used like a bit array for storing condition successes on specific states.
+
+    #Setup loopback for QueueMemberPenalty events and set first test state
+    def ami_connect(self, ami):
+        TestCase.ami_connect(self, ami)
+        ami.registerEvent("QueueMemberPenalty", self.check_queue_penalty_result)
+        self.state_advance(ami)
+
+    #when an event is received, pass it to the state dependent evaluation function 'state_receive()'
+    def check_queue_penalty_result(self, ami, event):
+        self.state_receive(event, ami)
+        pass
+
+    #Evaluates events according to the expectations of a given state and advances the state when finished.
+    def state_receive(self, event, ami):
+        if (self.state == 1):
+            if (event['queue'] == "queue1" and event['location'] == "sip/mem1" and event['penalty'] == "1"):
+                logger.info("state 1: Successfully Completed")
+                self.state_advance(ami)
+
+            else:
+                logger.error("state 1: received unexpected QueuePenalty event: %s" % event)
+                self.stop_reactor()
+
+        elif (self.state == 2):
+            if (event['queue'] == "queue1" and event['location'] == "sip/mem2" and event['penalty'] == "2"):
+                logger.info("state 2: verified condition 1")
+                self.state_passed_flags = self.state_passed_flags | 1
+
+            elif (event['queue'] == "queue2" and event['location'] == "sip/mem2" and event['penalty'] == '2'):
+                logger.info("state 2: verified condition 2")
+                self.state_passed_flags = self.state_passed_flags | 2
+
+            else:
+                logger.error("state 2: received unexpected QueuePenalty event: %s" % event)
+                self.stop_reactor()
+
+            if (self.state_passed_flags == 3):
+                logger.info("state 2: Successfully Completed")
+                self.state_advance(ami)
+
+        elif (self.state == 3):
+            if (event['queue'] == "queue1" and event['location'] == "sip/mem3" and event['penalty'] == '3'):
+                logger.info("state 3: verified condition 1")
+                self.state_passed_flags = self.state_passed_flags | 1
+
+            elif (event['queue'] == "queue2" and event['location'] == "sip/mem3" and event['penalty'] == '3'):
+                logger.info("state 3: verified condition 2")
+                self.state_passed_flags = self.state_passed_flags | 2
+
+            elif (event['queue'] == "queue3" and event['location'] == "sip/mem3" and event['penalty'] == '3'):
+                logger.info("state 3: verified condition 3")
+                self.state_passed_flags = self.state_passed_flags | 4
+
+            else:
+                logger.error("state 3: received unexpected QueuePenalty event: %s" % event)
+                self.stop_reactor()
+
+            if (self.state_passed_flags == 7):
+                logger.info("state 3: Successfully Completed")
+                self.state_advance(ami)
+
+        elif (self.state == 4):
+            if (event['queue'] == "queue3" and event['location'] == "sip/mem1" and event['penalty'] == '4'):
+                logger.info("state 4: Successfully Completed")
+                self.state_advance(ami)
+
+            else:
+                logger.error("state 4: received unexpected QueuePenalty event: %s" % event)
+                self.stop_reactor()
+
+    #Advances test to the next state, resets state_passed_flags, and executes any actions/commands
+    def state_advance(self, ami):
+        #common:
+        self.state += 1
+        self.state_passed_flags = 0
+
+        #state specific:
+        if (self.state == 1): #state 1 - cli command with specific queue on mem1
+            ami.command('queue set penalty 1 on sip/mem1 in queue1')
+
+        elif (self.state == 2): #state 2 - cli command with unspecified queue on mem2
+            ami.command('queue set penalty 2 on sip/mem2')
+
+        elif (self.state == 3): #state 3 - manager action queuePenalty with unspecified queue on mem3
+            message = {'action': 'queuepenalty', 'penalty': '3', 'interface': 'sip/mem3'}
+            ami.sendMessage(message)
+
+        elif (self.state == 4): #state 4 - mamager action queuePenalty with specific queue on mem1
+            message = {'action': 'queuepenalty', 'penalty': '4', 'interface': 'sip/mem1', 'queue': 'queue3'}
+            ami.sendMessage(message)
+
+        #states exhausted:
+        else:
+            logger.info("Test Successful")
+            self.passed = True
+            self.stop_reactor()
+
+    #Create and commect ami.
+    def run(self):
+        TestCase.run(self)
+        self.create_ami_factory()
+
+def main():
+    test = QueuePenaltyTest()
+    test.start_asterisk()
+    reactor.run()
+    test.stop_asterisk()
+    if test.passed:
+        return 0
+    return 1
+
+
+if __name__ == "__main__":
+    sys.exit(main() or 0)
+
+
+# vim:sw=4:ts=4:expandtab:textwidth=79

Propchange: asterisk/trunk/tests/queues/set_penalty/run-test
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/queues/set_penalty/run-test
------------------------------------------------------------------------------
    svn:executable = *

Propchange: asterisk/trunk/tests/queues/set_penalty/run-test
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/queues/set_penalty/run-test
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/queues/set_penalty/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/queues/set_penalty/test-config.yaml?view=auto&rev=2907
==============================================================================
--- asterisk/trunk/tests/queues/set_penalty/test-config.yaml (added)
+++ asterisk/trunk/tests/queues/set_penalty/test-config.yaml Fri Dec 16 08:58:25 2011
@@ -1,0 +1,13 @@
+testinfo:
+    summary: 'Test functionality of queue set penalty CLI command'
+    description: |
+        This test performs a series of queue set penalty commands and QueuePenalty
+        actions in order to check whether or not they fail in some way or cause
+        Asterisk to crash.
+
+properties:
+    minversion: '1.8'
+    dependencies:
+        - python : 'twisted'
+        - python : 'starpy'
+        - asterisk : 'app_queue'

Propchange: asterisk/trunk/tests/queues/set_penalty/test-config.yaml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/queues/set_penalty/test-config.yaml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/queues/set_penalty/test-config.yaml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: asterisk/trunk/tests/queues/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/queues/tests.yaml?view=diff&rev=2907&r1=2906&r2=2907
==============================================================================
--- asterisk/trunk/tests/queues/tests.yaml (original)
+++ asterisk/trunk/tests/queues/tests.yaml Fri Dec 16 08:58:25 2011
@@ -2,6 +2,7 @@
 tests:
     - test: 'queue_baseline'
     - test: 'position_priority_maxlen'
+    - test: 'set_penalty'
     # Temporarily disabled while failures are debugged
     #- test: 'macro_gosub_test'
     # Temporarily disabled while failures are debugged




More information about the asterisk-commits mailing list