import logging
import shutil
import sqlalchemy
+import sqlalchemy.exc
import random
import string
import urlparse
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 = [
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.
# 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()
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.
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):
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):