[asterisk-commits] espiceland: testsuite/asterisk/trunk r614 - in /asterisk/trunk/tests: ./ fast...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 28 11:39:32 CDT 2010


Author: espiceland
Date: Wed Jul 28 11:39:28 2010
New Revision: 614

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=614
Log:
Test for FastAGI's database commands.  Changed all FastAGI tests to be installed
into /tmp/asterisk-testsuite/fastagi/test-name.

Added:
    asterisk/trunk/tests/fastagi/database/
    asterisk/trunk/tests/fastagi/database/run-test   (with props)
    asterisk/trunk/tests/fastagi/database/test-config.yaml   (with props)
Modified:
    asterisk/trunk/tests/fastagi/channel-status/run-test
    asterisk/trunk/tests/fastagi/connect/run-test
    asterisk/trunk/tests/fastagi/control-stream-file/run-test
    asterisk/trunk/tests/fastagi/hangup/run-test
    asterisk/trunk/tests/fastagi/stream-file/run-test
    asterisk/trunk/tests/tests.yaml

Modified: asterisk/trunk/tests/fastagi/channel-status/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/fastagi/channel-status/run-test?view=diff&rev=614&r1=613&r2=614
==============================================================================
--- asterisk/trunk/tests/fastagi/channel-status/run-test (original)
+++ asterisk/trunk/tests/fastagi/channel-status/run-test Wed Jul 28 11:39:28 2010
@@ -35,8 +35,7 @@
         reactor.callWhenRunning(self.run)
 
         print self.ast_version
-        self.asterisk = Asterisk(base=os.path.join(os.getcwd(),
-            "/tmp/asterisk-testsuite/fastagi/channel-status"))
+        self.asterisk = Asterisk(base="/tmp/asterisk-testsuite/fastagi/channel-status")
         self.asterisk.install_config("tests/fastagi/configs/extensions.conf")
         self.asterisk.install_config("tests/fastagi/configs/manager.conf")
         self.asterisk.install_config("tests/fastagi/configs/logger.conf")

Modified: asterisk/trunk/tests/fastagi/connect/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/fastagi/connect/run-test?view=diff&rev=614&r1=613&r2=614
==============================================================================
--- asterisk/trunk/tests/fastagi/connect/run-test (original)
+++ asterisk/trunk/tests/fastagi/connect/run-test Wed Jul 28 11:39:28 2010
@@ -34,8 +34,7 @@
         reactor.callWhenRunning(self.run)
 
         print self.ast_version
-        self.asterisk = Asterisk(base=os.path.join(os.getcwd(),
-            "/tmp/asterisk-testsuite/fastagi/connect"))
+        self.asterisk = Asterisk(base="/tmp/asterisk-testsuite/fastagi/connect")
         self.asterisk.install_config("tests/fastagi/configs/extensions.conf")
         self.asterisk.install_config("tests/fastagi/configs/manager.conf")
 

Modified: asterisk/trunk/tests/fastagi/control-stream-file/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/fastagi/control-stream-file/run-test?view=diff&rev=614&r1=613&r2=614
==============================================================================
--- asterisk/trunk/tests/fastagi/control-stream-file/run-test (original)
+++ asterisk/trunk/tests/fastagi/control-stream-file/run-test Wed Jul 28 11:39:28 2010
@@ -34,8 +34,7 @@
         reactor.callWhenRunning(self.run)
 
         print self.ast_version
-        self.asterisk = Asterisk(base=os.path.join(os.getcwd(),
-            "/tmp/asterisk-testsuite/fastagi/control-stream-file"))
+        self.asterisk = Asterisk(base="/tmp/asterisk-testsuite/fastagi/control-stream-file")
         self.asterisk.install_config("tests/fastagi/configs/extensions.conf")
         self.asterisk.install_config("tests/fastagi/configs/manager.conf")
         self.asterisk.install_config("tests/fastagi/configs/logger.conf")

Added: asterisk/trunk/tests/fastagi/database/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/fastagi/database/run-test?view=auto&rev=614
==============================================================================
--- asterisk/trunk/tests/fastagi/database/run-test (added)
+++ asterisk/trunk/tests/fastagi/database/run-test Wed Jul 28 11:39:28 2010
@@ -1,0 +1,231 @@
+#!/usr/bin/python
+'''
+Copyright (C) 2010, Digium, Inc.
+Erin Spiceland <espiceland at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+
+import sys
+import os
+from optparse import OptionParser
+from twisted.internet import reactor
+from starpy import fastagi
+
+sys.path.append("lib/python")
+from asterisk.asterisk import Asterisk
+from asterisk.version import AsteriskVersion
+
+class FastAGIDatabaseTest:
+    def __init__(self, argv):
+        self.passed = {}
+        self.timeout = 45
+        self.key = "fastagitest"
+        self.overall_result = True
+        self.agi = ""
+
+        parser = OptionParser()
+        parser.add_option("-v", "--version", dest="ast_version",
+                          help="Asterisk version string")
+        (options, args) = parser.parse_args(argv)
+        self.ast_version = AsteriskVersion(options.ast_version)
+
+        # Listen for results from dialplan
+        self.agi_factory = fastagi.FastAGIFactory(self.do_test)
+        reactor.listenTCP(4573, self.agi_factory, self.timeout, '127.0.0.1')
+        reactor.callWhenRunning(self.run)
+
+        print self.ast_version
+        self.asterisk = Asterisk(base="/tmp/asterisk-testsuite/fastagi/database")
+        self.asterisk.install_config("tests/fastagi/configs/extensions.conf")
+        self.asterisk.install_config("tests/fastagi/configs/manager.conf")
+        self.asterisk.install_config("tests/fastagi/configs/logger.conf")
+
+    def on_del_failure(self, reason):
+        print 'Could not delete the data from the database.'
+        print reason.getTraceback()
+        self.passed["Del"] = False
+        self.result_changed()
+
+    def on_set_failure(self, reason):
+        print 'Could not set a new value.'
+        print reason.getTraceback()
+        self.passed["Set"] = False
+
+    def on_get_failure(self, reason):
+        print 'Could not get the data from the database.'
+        print reason.getTraceback()
+        self.passed["Get"] = False
+
+    # We expect this to get called when we try to select
+    # the key we've just deleted from the database.
+    def on_get3_failure(self, reason):
+        print "Success. %s is no longer a valid key." % self.key
+        self.passed["Del"] = True
+        self.result_changed()
+
+    def on_put_failure(self, reason):
+        print 'Could not put the data into the database.'
+        print reason.getTraceback()
+        self.passed["Put"] = False
+        self.result_changed()
+
+    def get_result_from_put(self, result):
+        self.passed["Put"] = True
+
+        # 2. Retrieve that key from the database
+        print "Retrieving key from the database."
+        self.agi.databaseGet("secret",self.key).addCallback(
+            self.get_result_from_get
+        ).addErrback(self.on_get_failure)
+
+    # 2. Retrieve that key from the database
+    def get_result_from_get(self, result):
+        print 'Value of %s is "%s"' % (self.key, result)
+        if result == "juststarted":
+            self.passed["Get"] = True
+        else:
+            # If the call to databaseGet() succeeds but the value is wrong,
+            # the previous call to databasePut() failed.
+            self.passed["Put"] = False
+            print "Call to databaseGet() succeeded, but value is wrong."
+            print 'Expected value of "juststarted" but got "%s"' % result
+
+        # 3. Update the value of the key in the database
+        print "Updating value of key."
+        self.agi.databaseSet("secret",self.key,"halfwaydone").addCallback(
+            self.get_result_from_set
+        ).addErrback(self.on_set_failure)
+
+    # 3. Update the value of the key in the database
+    def get_result_from_set(self, result):
+        if result >= 0:
+            self.passed["Set"] = True
+        # This should never happen.
+        else:
+            self.passed["Set"] = False
+            print "Something went horribly wrong."
+
+        # 4. Test for new value
+        print "Checking new value of key."
+        self.agi.databaseGet("secret",self.key).addCallback(
+            self.get_result_from_get2
+        ).addErrback(self.on_get_failure)
+
+    # 4. Test for new value
+    def get_result_from_get2(self, result):
+        print 'Value of %s is "%s"' % (self.key, result)
+        if result != "halfwaydone":
+            self.passed["Set"] = False
+            print "Call to databaseSet() succeeded,\
+                but value did not get updated."
+            print 'Expected value of "halfwaydone" but got "%s"' % result
+
+        # 5. Delete that key from the database
+        print "Deleting key from database."
+        self.agi.databaseDel("secret",self.key).addCallback(
+            self.get_result_from_del
+        ).addErrback(self.on_del_failure)
+
+    # 5. Delete that key from the database
+    def get_result_from_del(self, result):
+        if result >= 0:
+            self.passed["Del"] = True
+        # This should never happen.
+        else:
+            self.passed["Del"] = False
+            print "Something went horribly wrong."
+
+        # 6. Test that key was deleted.
+        print "Checking that key was deleted."
+        self.agi.databaseGet("secret",self.key).addCallback(
+            self.get_result_from_get3
+        ).addErrback(self.on_get3_failure)
+
+    # 6. Test that key was deleted.
+    # This should never be called if databaseDel() succeeded.
+    def get_result_from_get3(self, result):
+        print "Value of %s is %s" % (self.key, result)
+        if result is not None:
+            self.passed["Del"] = False
+        # This should never happen.
+        else:
+            self.passed["Del"] = True
+
+        result_changed()
+
+    # This gets invoked by the dialplan when the call is answered
+    # 1. Put a new key into the database
+    # 2. Retrieve that key from the database
+    # 3. Update the value of the key in the database
+    # 4. Test for new value
+    # 5. Delete that key from the database
+    # 6. Test that key was deleted.
+    def do_test(self, agi):
+        self.agi = agi
+        print "Inserting key into database."
+        return agi.databaseSet("secret",self.key,"juststarted").addCallback(
+            self.get_result_from_put
+        ).addErrback(self.on_put_failure)
+
+	# Read test results and dialplan globals
+    def read_result(self):
+        self.agi.finish()
+
+        for test in self.passed:
+            if self.passed[test] is True:
+                print "database%s worked as expected." % test
+            else:
+                print "database%s FAILED." % test
+                self.overall_result = False
+
+        self.stop_asterisk()
+
+        if reactor.running:
+            print "Stopping Reactor ..."
+            reactor.stop()
+
+    def launch_test(self):
+        self.asterisk.cli_exec("core set verbose 10")
+        self.asterisk.cli_exec("agi set debug on")
+
+        print "Originating call to begin test."
+        self.asterisk.cli_originate(
+            "Local/b_exten at agitest extension echo at agitest"
+        )
+
+    def start_asterisk(self):
+        print "Starting Asterisk"
+        self.asterisk.start()
+
+    def stop_asterisk(self):
+        print "Stopping Asterisk"
+        self.asterisk.stop()
+
+    # Read result before timeout
+    def result_changed(self):
+        # if self.passed["Put"] is None, not one test has completed yet
+        # and we should wait for the timeout.
+        if self.passed["Put"] is not None:
+            reactor.callLater(2, self.read_result)
+
+    def run(self):
+        self.start_asterisk()
+        reactor.callLater(2, self.launch_test)
+        reactor.callLater(self.timeout, self.read_result)
+
+def main(argv=None):
+    if argv is None:
+        argv = sys.argv
+
+    agi_test = FastAGIDatabaseTest(argv)
+    reactor.run()
+
+    if agi_test.overall_result is not True:
+        return 1
+
+    return 0
+
+if __name__ == "__main__":
+    sys.exit(main() or 0)

Propchange: asterisk/trunk/tests/fastagi/database/run-test
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/fastagi/database/run-test
------------------------------------------------------------------------------
    svn:executable = *

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

Propchange: asterisk/trunk/tests/fastagi/database/run-test
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/fastagi/database/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/fastagi/database/test-config.yaml?view=auto&rev=614
==============================================================================
--- asterisk/trunk/tests/fastagi/database/test-config.yaml (added)
+++ asterisk/trunk/tests/fastagi/database/test-config.yaml Wed Jul 28 11:39:28 2010
@@ -1,0 +1,13 @@
+testinfo:
+    summary:     'Test FastAGI database manipulation functions.'
+    description: |
+        'Test FastAGI database manipulation functions. databasePut, databaseGet,
+        databaseSet, databaseDel.'
+
+
+properties:
+    minversion: '1.4'
+    dependencies:
+        - app : 'python'
+        - python : 'twisted'
+        - python : 'starpy'

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

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

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

Modified: asterisk/trunk/tests/fastagi/hangup/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/fastagi/hangup/run-test?view=diff&rev=614&r1=613&r2=614
==============================================================================
--- asterisk/trunk/tests/fastagi/hangup/run-test (original)
+++ asterisk/trunk/tests/fastagi/hangup/run-test Wed Jul 28 11:39:28 2010
@@ -35,8 +35,7 @@
         reactor.callWhenRunning(self.run)
 
         print self.ast_version
-        self.asterisk = Asterisk(base=os.path.join(os.getcwd(),
-            "/tmp/asterisk-testsuite/fastagi/channel-status"))
+        self.asterisk = Asterisk(base="/tmp/asterisk-testsuite/fastagi/channel-status")
         self.asterisk.install_config("tests/fastagi/configs/extensions.conf")
         self.asterisk.install_config("tests/fastagi/configs/manager.conf")
         self.asterisk.install_config("tests/fastagi/configs/logger.conf")

Modified: asterisk/trunk/tests/fastagi/stream-file/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/fastagi/stream-file/run-test?view=diff&rev=614&r1=613&r2=614
==============================================================================
--- asterisk/trunk/tests/fastagi/stream-file/run-test (original)
+++ asterisk/trunk/tests/fastagi/stream-file/run-test Wed Jul 28 11:39:28 2010
@@ -34,8 +34,7 @@
         reactor.callWhenRunning(self.run)
 
         print self.ast_version
-        self.asterisk = Asterisk(base=os.path.join(os.getcwd(),
-            "/tmp/asterisk-testsuite/fastagi/stream-file"))
+        self.asterisk = Asterisk(base="/tmp/asterisk-testsuite/fastagi/stream-file")
         self.asterisk.install_config("tests/fastagi/configs/extensions.conf")
         self.asterisk.install_config("tests/fastagi/configs/manager.conf")
         self.asterisk.install_config("tests/fastagi/configs/logger.conf")

Modified: asterisk/trunk/tests/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/tests.yaml?view=diff&rev=614&r1=613&r2=614
==============================================================================
--- asterisk/trunk/tests/tests.yaml (original)
+++ asterisk/trunk/tests/tests.yaml Wed Jul 28 11:39:28 2010
@@ -42,3 +42,5 @@
     - test: 'fastagi/channel-status'
     - test: 'fastagi/hangup'
     - test: 'fastagi/stream-file'
+#    - test: 'fastagi/control-stream-file'
+    - test: 'fastagi/database'




More information about the asterisk-commits mailing list