]> scripts.mit.edu Git - wizard.git/commitdiff
Add database checks, make assert_all_writable less stringent.
authorEdward Z. Yang <ezyang@mit.edu>
Mon, 8 Feb 2010 00:56:48 +0000 (19:56 -0500)
committerEdward Z. Yang <ezyang@mit.edu>
Tue, 9 Mar 2010 02:41:31 +0000 (21:41 -0500)
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
wizard/app/__init__.py
wizard/command/upgrade.py
wizard/deploy.py
wizard/util.py

index 1c8b477e997027abeabc5dd2944b32efca648d7b..f4b53a32dc2a02ce1c6926b5af31806264b8f146 100644 (file)
@@ -40,6 +40,7 @@ import shlex
 import logging
 import shutil
 import sqlalchemy
+import sqlalchemy.exc
 import random
 import string
 import urlparse
@@ -47,7 +48,7 @@ import tempfile
 import pkg_resources
 
 import wizard
-from wizard import resolve, scripts, shell, util
+from wizard import resolve, scripts, shell, sql, util
 
 # SCRIPTS SPECIFIC
 _scripts_application_list = [
@@ -412,6 +413,15 @@ class Application(object):
             not to depend on pages that are not the main page.
         """
         raise NotImplementedError
+    def checkDatabase(self, deployment):
+        """
+        Checks if the database is accessible.
+        """
+        try:
+            sql.connect(deployment.dsn)
+            return True
+        except sqlalchemy.exc.DBAPIError:
+            return False
     def checkWebPage(self, deployment, page, outputs=[], exclude=[]):
         """
         Checks if a given page of an autoinstall contains a particular string.
index 30dab29ed1a454f23bac05a694688ff08b03ee26..d7dc630ef98978fd87ffd420ba5e135f7aba44bc 100644 (file)
@@ -158,6 +158,8 @@ class Upgrade(object):
             # XXX: put this in Application
             self.version = shell.eval("git", "--git-dir="+self.repo, "describe", "--tags", "master")
             self.preflightBlacklist()
+            self.prod.verify()
+            self.prod.verifyDatabase()
             self.prod.verifyTag(options.srv_path)
             self.prod.verifyGit(options.srv_path)
             self.prod.verifyConfigured()
index 5b0e525881bca9c5148950beaacfa4415f2a4ad2..37a29f08793ebf934737c196f4e3027c084faa9e 100644 (file)
@@ -405,6 +405,12 @@ class ProductionCopy(Deployment):
         this application uses.
         """
         self.application.remove(self, options)
+    def verifyDatabase(self):
+        """
+        Checks if the autoinstall has a properly configured database.
+        """
+        if not self.application.checkDatabase(self):
+            raise DatabaseVerificationError
     def verifyWeb(self):
         """
         Checks if the autoinstall is viewable from the web.
@@ -627,6 +633,15 @@ web.  This may indicate that the website is behind
 authentication on the htaccess level.  You can find
 the contents of the page from the debug backtraces."""
 
+class DatabaseVerificationError(Error):
+    """Could not access the database"""
+    def __str__(self):
+        return """
+
+ERROR: We were not able to access the database for
+this application; this probably means that your database
+configuration is misconfigured."""
+
 class UnknownWebPath(Error):
     """Could not determine application's web path."""
     def __str__(self):
index 0335bc6ef48bb17ec66ad0102a99161c965b6e64..ce8d02ed3515809d34c9322a693618da4e8d6c0e 100644 (file)
@@ -373,13 +373,21 @@ def mixed_newlines(filename):
     return ret
 
 def assert_all_writable(dir="."):
-    """Recursively checks if all files and directories in a directory are
-    writable.  Raises :exc:`PermissionsError` if this is not true."""
+    """
+    Recursively checks if all directories are writable and all files are
+    readable.  Raises :exc:`PermissionsError` if this is not true.
+    """
     for dirpath, dirname, filenames in os.walk(dir):
-        if not os.access(dirpath, os.W_OK):
+        if not os.access(dirpath, os.R_OK):
+            logging.warning("Could not write %s", dirpath)
             raise PermissionsError
         for filename in filenames:
-            if not os.access(os.path.join(dirpath, filename), os.W_OK):
+            path = os.path.join(dirpath, filename)
+            if os.path.islink(path):
+                # assume it's ok
+                continue
+            if not os.access(path, os.R_OK):
+                logging.warning("Could not read %s", path)
                 raise PermissionsError
 
 class NoOperatorInfo(wizard.Error):