[svn-commits] mjordan: testsuite/asterisk/trunk r2696 - /asterisk/trunk/lib/python/asterisk/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Nov 8 16:41:59 CST 2011


Author: mjordan
Date: Tue Nov  8 16:41:55 2011
New Revision: 2696

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=2696
Log:
Changed the Asterisk wrapper class to not install configs on instantation

This change updates the Asterisk wrapper class such that it populates the needed
values on instantation, but does not actually create sub directories, install
config files, or take any other actions.  The individual tests are responsible
for installing the config files needed (although default test config files are
still installed automatically if not installed on start).  The TestCase class
and other libraries were updated to use this new behavior.  This eliminates the
extraneous ast directories that would be created, and allows for Asterisk
configuration information to be queried from the created objects without
copying config files.

(closes issue ASTERISK-18823)
Review: https://reviewboard.asterisk.org/r/1571/


Modified:
    asterisk/trunk/lib/python/asterisk/TestCase.py
    asterisk/trunk/lib/python/asterisk/asterisk.py
    asterisk/trunk/lib/python/asterisk/voicemail.py

Modified: asterisk/trunk/lib/python/asterisk/TestCase.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/TestCase.py?view=diff&rev=2696&r1=2695&r2=2696
==============================================================================
--- asterisk/trunk/lib/python/asterisk/TestCase.py (original)
+++ asterisk/trunk/lib/python/asterisk/TestCase.py Tue Nov  8 16:41:55 2011
@@ -117,10 +117,7 @@
             logger.info("Creating Asterisk instance %d" % (c + 1))
             host = "127.0.0.%d" % (c + 1)
             self.ast.append(Asterisk(base=self.base, host=host))
-            # Copy shared config files
-            self.ast[c].install_configs("%s/configs" %
-                    (self.test_name))
-            # Copy test specific config files
+            """ Copy test specific config files """
             self.ast[c].install_configs("%s/configs/ast%d" %
                     (self.test_name, c + 1))
 

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=2696&r1=2695&r2=2696
==============================================================================
--- asterisk/trunk/lib/python/asterisk/asterisk.py (original)
+++ asterisk/trunk/lib/python/asterisk/asterisk.py Tue Nov  8 16:41:55 2011
@@ -45,7 +45,11 @@
     asterisk.conf.
     """
 
+    """ The base location of the temporary files created by the testsuite """
     test_suite_root = "/tmp/asterisk-testsuite"
+
+    """ The default etc directory for Asterisk """
+    asterisk_etc_directory = "/etc/asterisk"
 
     def __init__(self, base=None, ast_conf_options=None, host="127.0.0.1"):
         """Construct an Asterisk instance.
@@ -60,53 +64,45 @@
         """
         self.directories = {}
         self.ast_version = AsteriskVersion()
-
         self.base = Asterisk.test_suite_root
-        self.baseDirectory = self.base
-        self.astetcdir = "/etc/asterisk"
+        if base is not None:
+            self.base = "%s/%s" % (self.base, base)
+        self.astetcdir = Asterisk.asterisk_etc_directory
         self.ast_binary = utils.which("asterisk") or "/usr/sbin/asterisk"
         self.host = host
 
-        # Find the system installed asterisk.conf
+        self.__ast_conf_options = ast_conf_options
+        self.__directory_structure_made = False
+        self.__configs_installed = False
+        self.__configs_set_up = False
+
+        """ Find the system installed asterisk.conf """
         ast_confs = [
                 "/etc/asterisk/asterisk.conf",
                 "/usr/local/etc/asterisk/asterisk.conf"
         ]
-        ast_conf = None
+        self.__ast_conf = None
         for c in ast_confs:
             if os.path.exists(c):
-                ast_conf = ConfigFile(c)
+                self.__ast_conf = ConfigFile(c)
                 break
-        if ast_conf is None:
-            logger.error("No asterisk.conf found on the system!")
-            return
-
-        if base is not None:
-            self.base = "%s/%s" % (self.base, base)
+        if self.__ast_conf is None:
+            logger.error("Unable to locate asterisk.conf file in any known location")
+            raise Exception("Unable to locate asterisk.conf file in any known location")
+
+        """ Set which astxxx this instance will be """
         i = 1
         while True:
             if not os.path.isdir("%s/ast%d" % (self.base, i)):
                 self.base = "%s/ast%d" % (self.base, i)
                 break
             i += 1
-        os.makedirs(self.base)
-        self.baseDirectory = self.base
-
-        # Mirror system install directory structure
-        dir_cat = None
-        for c in ast_conf.categories:
+
+        """ Get the Asterisk directories from the Asterisk config file """
+        for c in self.__ast_conf.categories:
             if c.name == "directories":
-                dir_cat = c
-        if dir_cat is None:
-            logger.error("Unable to discover dir layout from asterisk.conf")
-            return
-        self.__gen_ast_conf(ast_conf, dir_cat, ast_conf_options)
-        for (var, val) in dir_cat.options:
-            self.__mirror_dir(var, val)
-
-        self.install_configs(os.getcwd() + "/configs")
-
-        self.__setup_configs()
+                for (var, val) in c.options:
+                    self.directories[var] = val
 
     def start(self):
         """Start this instance of Asterisk.
@@ -115,7 +111,15 @@
 
         Example Usage:
         asterisk.start()
-        """
+
+        Note that calling this will install the default testsuite
+        config files, if they have not already been installed
+        """
+        if self.__configs_installed == False:
+            self.install_configs(os.getcwd() + "/configs")
+        if self.__configs_set_up == False:
+            self.__setup_configs()
+
         cmd = [
             self.ast_binary,
             "-f", "-g", "-q", "-m", "-n",
@@ -206,7 +210,20 @@
 
         Example Usage:
         asterisk.install_configs("tests/my-cool-test/configs")
-        """
+
+        Note that this will install the default testsuite config files,
+        if they have not already been installed.
+        """
+
+        if not self.__directory_structure_made:
+            self.__make_directory_structure()
+
+        if not self.__configs_installed:
+            if cfg_path != ("%s/configs" % os.getcwd()):
+                """ Do a one-time installation of the base configs """
+                self.install_configs("%s/configs" % os.getcwd())
+            self.__configs_installed = True
+
         for f in os.listdir(cfg_path):
             target = "%s/%s" % (cfg_path, f)
             if os.path.isfile(target):
@@ -241,6 +258,9 @@
         Example Usage:
         asterisk.install_config("tests/my-cool-test/configs/manager.conf")
         """
+
+        self.__make_directory_structure()
+
         if not os.path.exists(cfg_path):
             logger.error("Config file '%s' does not exist" % cfg_path)
             return
@@ -362,7 +382,36 @@
             pass
         return output
 
+    def __make_directory_structure(self):
+        """ Mirror system directory structure """
+
+        if self.__directory_structure_made:
+            return
+
+        """ Make the directory structure if not available """
+        if not os.path.exists(self.base):
+            os.makedirs(self.base)
+
+        dir_cat = None
+        for c in self.__ast_conf.categories:
+            if c.name == "directories":
+                dir_cat = c
+        if dir_cat is None:
+            logger.error("Unable to discover dir layout from asterisk.conf")
+            raise Exception("Unable to discover dir layout from asterisk.conf")
+
+        self.__gen_ast_conf(self.__ast_conf, dir_cat, self.__ast_conf_options)
+        for (var, val) in dir_cat.options:
+            self.__mirror_dir(var, val)
+
+        self.__directory_structure_made = True
+
+
     def __setup_configs(self):
+        """
+        Perform any post-installation manipulation of the config
+        files
+        """
         self.__setup_manager_conf()
 
     def __setup_manager_conf(self):
@@ -393,11 +442,10 @@
             logger.error("Unexpected error: %s" % sys.exc_info()[0])
             return
 
-        for c in ast_conf.categories:
+        for c in self.__ast_conf.categories:
             f.write("[%s]\n" % c.name)
             if c.name == "directories":
                 for (var, val) in c.options:
-                    self.directories[var] = val
                     f.write("%s = %s%s\n" % (var, self.base, val))
             elif c.name == "options":
                 f.write("#include \"%s/asterisk.options.conf.inc\"\n" %

Modified: asterisk/trunk/lib/python/asterisk/voicemail.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/voicemail.py?view=diff&rev=2696&r1=2695&r2=2696
==============================================================================
--- asterisk/trunk/lib/python/asterisk/voicemail.py (original)
+++ asterisk/trunk/lib/python/asterisk/voicemail.py Tue Nov  8 16:41:55 2011
@@ -338,7 +338,7 @@
     true on success, false on error
     """
     def createMailbox(self, context, mailbox, createAllFolders=False):
-        mailboxPath = self.__ast.baseDirectory + "%(vd)s/%(c)s/%(m)s" %{'vd': self.voicemailDirectory, 'c': context, 'm': mailbox}
+        mailboxPath = self.__ast.base + "%(vd)s/%(c)s/%(m)s" %{'vd': self.voicemailDirectory, 'c': context, 'm': mailbox}
 
         try:
             if not os.path.isdir(mailboxPath):
@@ -392,7 +392,7 @@
 
         msgName = 'msg%04d' % (msgnum)
         msgEnvName = msgName + ".txt"
-        msgEnvPath = self.__ast.baseDirectory + "%(vd)s/%(c)s/%(m)s/%(f)s/%(n)s" % {'vd':self.voicemailDirectory, 'c':context, 'm':mailbox, 'f':folder, 'n':msgEnvName}
+        msgEnvPath = self.__ast.base + "%(vd)s/%(c)s/%(m)s/%(f)s/%(n)s" % {'vd':self.voicemailDirectory, 'c':context, 'm':mailbox, 'f':folder, 'n':msgEnvName}
 
         f = open(msgEnvPath, 'w')
         f.write(';\n')
@@ -419,7 +419,7 @@
 
         for format in formats:
             msgFormatName = msgName + '.' + format
-            msgFormatPath = self.__ast.baseDirectory + "%(vd)s/%(c)s/%(m)s/%(f)s/%(n)s" % {'vd':self.voicemailDirectory, 'c':context, 'm':mailbox, 'f':folder, 'n':msgFormatName}
+            msgFormatPath = self.__ast.base + "%(vd)s/%(c)s/%(m)s/%(f)s/%(n)s" % {'vd':self.voicemailDirectory, 'c':context, 'm':mailbox, 'f':folder, 'n':msgFormatName}
             audioFile = os.path.join(os.getcwd(), "%s/sounds/talking.ulaw" % (self.testParentDir))
             shutil.copy(audioFile, msgFormatPath)
 
@@ -434,7 +434,7 @@
     true if the folder exists, false otherwise
     """
     def checkFolderExists(self, context, mailbox, folder=inboxFolderName):
-        mailboxPath = self.__ast.baseDirectory + "%(vd)s/%(c)s/%(m)s" %{'vd': self.voicemailDirectory, 'c': context, 'm': mailbox}
+        mailboxPath = self.__ast.base + "%(vd)s/%(c)s/%(m)s" %{'vd': self.voicemailDirectory, 'c': context, 'm': mailbox}
 
         if not (os.path.exists(mailboxPath)):
             return False
@@ -507,7 +507,7 @@
 
         msgName = 'msg%(msgnum)04d' %{"msgnum":msgnum}
         msgName = msgName + ".txt"
-        msgPath = self.__ast.baseDirectory + "%(vd)s/%(c)s/%(m)s/%(f)s/%(n)s" % {'vd':self.voicemailDirectory, 'c':context, 'm':mailbox, 'f':folder, 'n':msgName}
+        msgPath = self.__ast.base + "%(vd)s/%(c)s/%(m)s/%(f)s/%(n)s" % {'vd':self.voicemailDirectory, 'c':context, 'm':mailbox, 'f':folder, 'n':msgName}
 
         configFile = ConfigFile(msgPath)
         for cat in configFile.categories:
@@ -541,7 +541,7 @@
     """
     def getUserObject(self, context, mailbox, sourceFile="voicemail.conf"):
 
-        filePath = self.__ast.baseDirectory + self.__ast.directories['astetcdir'] + "/" + sourceFile
+        filePath = self.__ast.base + self.__ast.directories['astetcdir'] + "/" + sourceFile
 
         configFile = ConfigFile(filePath)
         userObject = VoiceMailMailboxManagement.UserObject()
@@ -578,7 +578,7 @@
         if not (self.checkFolderExists(context, mailbox, folder)):
             return False
 
-        msgPath = self.__ast.baseDirectory + "%(vd)s/%(c)s/%(m)s/%(f)s/%(n)s" % {'vd':self.voicemailDirectory, 'c':context, 'm':mailbox, 'f':folder, 'n':name}
+        msgPath = self.__ast.base + "%(vd)s/%(c)s/%(m)s/%(f)s/%(n)s" % {'vd':self.voicemailDirectory, 'c':context, 'm':mailbox, 'f':folder, 'n':name}
 
         if (os.path.exists(msgPath)):
             return True
@@ -586,7 +586,7 @@
             return False
 
     def __removeItemsFromFolder__(self, mailboxPath, folder):
-        folderPath = os.path.join(self.__ast.baseDirectory, "%(mp)s/%(f)s" % {'mp':mailboxPath, 'f':folder})
+        folderPath = os.path.join(self.__ast.base, "%(mp)s/%(f)s" % {'mp':mailboxPath, 'f':folder})
 
         if not (os.path.exists(folderPath)):
             return
@@ -609,7 +609,7 @@
     False if the mailbox does not exist, otherwise True
     """
     def removeMailbox(self, context, mailbox, removeFolders=False):
-        mailboxPath = self.__ast.baseDirectory + "/%(vd)s/%(c)s/%(m)s" %{'vd': self.voicemailDirectory, 'c': context, 'm': mailbox}
+        mailboxPath = self.__ast.base + "/%(vd)s/%(c)s/%(m)s" %{'vd': self.voicemailDirectory, 'c': context, 'm': mailbox}
 
         if not (os.path.exists(mailboxPath)):
             return False
@@ -621,11 +621,11 @@
         self.__removeItemsFromFolder__(mailboxPath, self.greetingsFolderName)
 
         if (removeFolders):
-            rmdir(os.path.join(self.__ast.baseDirectory, "%(mp)s/%(f)s" %{'mp':mailboxPath, 'f':self.inboxFolderName}))
-            rmdir(os.path.join(self.__ast.baseDirectory, "%(mp)s/%(f)s" %{'mp':mailboxPath, 'f':self.tempFolderName}))
-            rmdir(os.path.join(self.__ast.baseDirectory, "%(mp)s/%(f)s" %{'mp':mailboxPath, 'f':self.oldFolderName}))
-            rmdir(os.path.join(self.__ast.baseDirectory, "%(mp)s/%(f)s" %{'mp':mailboxPath, 'f':self.urgentFolderName}))
-            rmdir(os.path.join(self.__ast.baseDirectory, "%(mp)s/%(f)s" %{'mp':mailboxPath, 'f':self.greetingsFolderName}))
+            rmdir(os.path.join(self.__ast.base, "%(mp)s/%(f)s" %{'mp':mailboxPath, 'f':self.inboxFolderName}))
+            rmdir(os.path.join(self.__ast.base, "%(mp)s/%(f)s" %{'mp':mailboxPath, 'f':self.tempFolderName}))
+            rmdir(os.path.join(self.__ast.base, "%(mp)s/%(f)s" %{'mp':mailboxPath, 'f':self.oldFolderName}))
+            rmdir(os.path.join(self.__ast.base, "%(mp)s/%(f)s" %{'mp':mailboxPath, 'f':self.urgentFolderName}))
+            rmdir(os.path.join(self.__ast.base, "%(mp)s/%(f)s" %{'mp':mailboxPath, 'f':self.greetingsFolderName}))
 
             rmdir(mailboxPath)
 




More information about the svn-commits mailing list