[asterisk-commits] jrose: testsuite/asterisk/trunk r3473 - in /asterisk/trunk: lib/python/asteri...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Sep 21 10:43:42 CDT 2012


Author: jrose
Date: Fri Sep 21 10:43:37 2012
New Revision: 3473

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3473
Log:
Add a test for 'queue reload members'

(issue AST-956)
Reported by: John Bigelow

Added:
    asterisk/trunk/tests/apps/queues/reload_queue_members/
    asterisk/trunk/tests/apps/queues/reload_queue_members/configs/
    asterisk/trunk/tests/apps/queues/reload_queue_members/configs/ast1/
    asterisk/trunk/tests/apps/queues/reload_queue_members/configs/ast1/queues.conf   (with props)
    asterisk/trunk/tests/apps/queues/reload_queue_members/queues.conf.replacement   (with props)
    asterisk/trunk/tests/apps/queues/reload_queue_members/run-test   (with props)
    asterisk/trunk/tests/apps/queues/reload_queue_members/test-config.yaml   (with props)
Modified:
    asterisk/trunk/lib/python/asterisk/asterisk.py
    asterisk/trunk/tests/apps/queues/tests.yaml

Modified: asterisk/trunk/lib/python/asterisk/asterisk.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/asterisk.py?view=diff&rev=3473&r1=3472&r2=3473
==============================================================================
--- asterisk/trunk/lib/python/asterisk/asterisk.py (original)
+++ asterisk/trunk/lib/python/asterisk/asterisk.py Fri Sep 21 10:43:37 2012
@@ -445,7 +445,7 @@
             if os.path.isfile(target):
                 self.install_config(target)
 
-    def install_config(self, cfg_path):
+    def install_config(self, cfg_path, target_filename = None):
         """Install a custom configuration file for this instance of Asterisk.
 
         By default, the configuration used will be whatever is found in the
@@ -470,9 +470,14 @@
         Keyword Arguments:
         cfg_path -- This argument must be the path to the configuration file
         to be installed into the directory tree for this instance of Asterisk.
+        target_filename -- If this argument is specified, the config file
+        provided will be installed with this filename in the Asterisk etc
+        directory. Use this if the file for cfg_path doesn't match the name of
+        the configuration needed by Asterisk.
 
         Example Usage:
         asterisk.install_config("tests/my-cool-test/configs/manager.conf")
+        asterisk.install_config("tests/my-cool-test/replacement_manager_config.conf", target_filename = "manager.conf")
         """
 
         self.__make_directory_structure()
@@ -484,7 +489,12 @@
         tmp = "%s/%s/%s" % (os.path.dirname(cfg_path), self.ast_version.branch, os.path.basename(cfg_path))
         if os.path.exists(tmp):
             cfg_path = tmp
-        target_path = os.path.join(self.astetcdir, os.path.basename(cfg_path))
+
+        if (target_filename):
+            target_path = os.path.join(self.astetcdir, target_filename)
+        else:
+            target_path = os.path.join(self.astetcdir, os.path.basename(cfg_path))
+
         if os.path.exists(target_path):
             os.remove(target_path)
         try:

Added: asterisk/trunk/tests/apps/queues/reload_queue_members/configs/ast1/queues.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/queues/reload_queue_members/configs/ast1/queues.conf?view=auto&rev=3473
==============================================================================
--- asterisk/trunk/tests/apps/queues/reload_queue_members/configs/ast1/queues.conf (added)
+++ asterisk/trunk/tests/apps/queues/reload_queue_members/configs/ast1/queues.conf Fri Sep 21 10:43:37 2012
@@ -1,0 +1,7 @@
+[queue1] ; One stays the same, two fall off, two new ones are added
+member=>local/1 at default
+member=>local/2 at default
+member=>local/3 at default
+
+[queue2] ; Empty Queue receiving new members
+

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

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

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

Added: asterisk/trunk/tests/apps/queues/reload_queue_members/queues.conf.replacement
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/queues/reload_queue_members/queues.conf.replacement?view=auto&rev=3473
==============================================================================
--- asterisk/trunk/tests/apps/queues/reload_queue_members/queues.conf.replacement (added)
+++ asterisk/trunk/tests/apps/queues/reload_queue_members/queues.conf.replacement Fri Sep 21 10:43:37 2012
@@ -1,0 +1,9 @@
+[queue1]
+member=>local/1 at default
+member=>local/4 at default
+member=>local/5 at default
+member=>local/6 at default
+
+[queue2]
+member=>local/7 at default
+member=>local/8 at default

Propchange: asterisk/trunk/tests/apps/queues/reload_queue_members/queues.conf.replacement
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/apps/queues/reload_queue_members/queues.conf.replacement
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/apps/queues/reload_queue_members/queues.conf.replacement
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/apps/queues/reload_queue_members/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/queues/reload_queue_members/run-test?view=auto&rev=3473
==============================================================================
--- asterisk/trunk/tests/apps/queues/reload_queue_members/run-test (added)
+++ asterisk/trunk/tests/apps/queues/reload_queue_members/run-test Fri Sep 21 10:43:37 2012
@@ -1,0 +1,109 @@
+#!/usr/bin/env python
+# vim: sw=3 et:
+'''
+Copyright (C) 2012, 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 os
+import logging
+
+from twisted.internet import reactor
+sys.path.append("lib/python")
+from asterisk.TestCase import TestCase
+LOGGER = logging.getLogger(__name__)
+
+class QueueReloadMembersTest(TestCase):
+    """
+    Creates an Asterisk instance with a couple premade queues. It then replaces
+    the queues.conf file with a new one and performs a reload. After the
+    reload, The AMI is issued a QueueStatus command and the test checks if all
+    of the expected members of the queues are named by the status.
+    """
+    def __init__(self):
+        super(QueueReloadMembersTest, self).__init__()
+
+        self.members_expected = [("queue1", "local/1 at default"), ("queue1", "local/4 at default"), ("queue1", "local/5 at default"), ("queue1", "local/6 at default"),\
+                                 ("queue2", "local/7 at default"), ("queue2", "local/8 at default")]
+
+        self.create_asterisk()
+
+    def run(self):
+        super(QueueReloadMembersTest, self).run()
+        self.create_ami_factory()
+
+    def ami_connect(self, ami):
+        src = "%s/tests/%s/queues.conf.replacement" % (os.getcwd(), self.base)
+        message = {'action': 'queuereload', 'members': 'yes'}
+
+        LOGGER.info( "Installing replacement configuration %s" % src)
+        self.ast[0].install_config(src, target_filename = "queues.conf")
+
+        ami.sendMessage(message, responseCallback = self.reload_finished)
+
+    def reload_finished(self, received):
+        message = {'action': 'QueueStatus'}
+
+        if (received['response'] != "Success"):
+            LOGGER.error("Failed to reload queue members. Test Failed.")
+            self.passed = False
+            self.stop_reactor()
+            return
+
+        LOGGER.info("Completed Reload, moving onto checking the results.")
+
+        self.ami[0].registerEvent("QueueMember", self.queue_member_event)
+        self.ami[0].registerEvent("QueueStatusComplete", self.queue_status_complete_event)
+        self.ami[0].sendMessage(message)
+
+        return 0
+
+    def queue_member_event(self, ami, event):
+        member = event.get("name")
+        queue = event.get("queue")
+        if member is None:
+            LOGGER.error("Received a QueueMember event with no name field.")
+            self.passed = False
+            self.stop_reactor()
+            return
+
+        if queue is None:
+            LOGGER.error("Received a QueueMember event with no queue field.")
+            self.passed = False
+            self.stop_reactor()
+            return
+
+        if (queue, member) not in self.members_expected:
+            LOGGER.error("Test Failed: Received Unexepcted member: %s" % member)
+            self.passed = False
+            self.stop_reactor()
+            return
+
+        LOGGER.info("Received Expected member: %s in %s" % (member, queue))
+        self.members_expected.remove((queue, member))
+
+        if len(self.members_expected) == 0:
+            LOGGER.info("All members that were expected are accounted for. Test will pass if no errors occur between now and when the QueueStatusComplete event is received.")
+            self.passed = True
+
+    def queue_status_complete_event(self, ami, event):
+        if len(self.members_expected) > 0:
+            LOGGER.error("Received QueueStatusComplete without receiving all expected new members of queues.")
+            self.passed = False
+        self.stop_reactor()
+
+def main():
+    test = QueueReloadMembersTest()
+    reactor.run()
+
+    if test.passed:
+        return 0
+    else:
+        return 1
+
+if __name__ == "__main__":
+   sys.exit(main() or 0)

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

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

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

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

Added: asterisk/trunk/tests/apps/queues/reload_queue_members/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/queues/reload_queue_members/test-config.yaml?view=auto&rev=3473
==============================================================================
--- asterisk/trunk/tests/apps/queues/reload_queue_members/test-config.yaml (added)
+++ asterisk/trunk/tests/apps/queues/reload_queue_members/test-config.yaml Fri Sep 21 10:43:37 2012
@@ -1,0 +1,14 @@
+testinfo:
+    summary:     'Test Queue Reload Members functionality'
+    description: |
+        'This replaces the configuration for queues with a new one which should contain different members
+         and then performs a QueueReload command from AMI. After reloading the queue, it then checks the
+         members in the queue to be sure they changed as expected.'
+
+properties:
+    minversion: '1.8.0.0'
+    dependencies:
+        - python : 'twisted'
+        - python : 'starpy'
+    tags:
+        - queues

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

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

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

Modified: asterisk/trunk/tests/apps/queues/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/queues/tests.yaml?view=diff&rev=3473&r1=3472&r2=3473
==============================================================================
--- asterisk/trunk/tests/apps/queues/tests.yaml (original)
+++ asterisk/trunk/tests/apps/queues/tests.yaml Fri Sep 21 10:43:37 2012
@@ -4,6 +4,7 @@
     - test: 'queue_transfer_callee'
     - test: 'position_priority_maxlen'
     - test: 'set_penalty'
+    - test: 'reload_queue_members'
     # Temporarily disabled while failures are debugged
     #- test: 'macro_gosub_test'
     # Temporarily disabled while failures are debugged




More information about the asterisk-commits mailing list