summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Laszlo <tim.laszlo@gmail.com>2012-08-15 12:35:26 -0500
committerTim Laszlo <tim.laszlo@gmail.com>2012-08-15 12:35:26 -0500
commitf5d3b73b36712944558f5529785b29621cb5cc11 (patch)
tree7b8efd457a1327f4b11e05cc5138b1af6b265bb6
parentaf44641c5511d35889fa4c25ffda0d2aa8eb4be6 (diff)
downloadbcfg2-f5d3b73b36712944558f5529785b29621cb5cc11.tar.gz
bcfg2-f5d3b73b36712944558f5529785b29621cb5cc11.tar.bz2
bcfg2-f5d3b73b36712944558f5529785b29621cb5cc11.zip
Core: add database_available flag to allow plugins to see availability
-rw-r--r--src/lib/Bcfg2/Server/Core.py9
-rw-r--r--src/lib/Bcfg2/Server/Plugin.py2
-rw-r--r--src/lib/Bcfg2/Server/Plugins/DBStats.py4
-rw-r--r--src/lib/Bcfg2/Server/SchemaUpdater/__init__.py4
4 files changed, 15 insertions, 4 deletions
diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py
index f25542eae..4465abb9a 100644
--- a/src/lib/Bcfg2/Server/Core.py
+++ b/src/lib/Bcfg2/Server/Core.py
@@ -102,14 +102,15 @@ class BaseCore(object):
# load plugins
Bcfg2.settings.read_config(cfile=self.cfile, repo=self.datastore)
+ self._database_available = False
# verify our database schema
try:
from Bcfg2.Server.SchemaUpdater import update_database, UpdaterError
try:
update_database()
+ self._database_available = True
except UpdaterError:
self.logger.error("Failed to update database schema")
- raise CoreInitError
except ImportError:
# assume django is not installed
pass
@@ -623,3 +624,9 @@ class BaseCore(object):
"""Get the data of the decision list."""
client, metadata = self.resolve_client(address)
return self.GetDecisions(metadata, mode)
+
+ @property
+ def database_available(self):
+ """Is the database configured and available"""
+ return self._database_available
+
diff --git a/src/lib/Bcfg2/Server/Plugin.py b/src/lib/Bcfg2/Server/Plugin.py
index 58e5dafeb..a9d8a2996 100644
--- a/src/lib/Bcfg2/Server/Plugin.py
+++ b/src/lib/Bcfg2/Server/Plugin.py
@@ -156,7 +156,7 @@ class DatabaseBacked(Plugin):
use_db = self.core.setup.cfp.getboolean(self.name.lower(),
"use_database",
default=False)
- if use_db and has_django:
+ if use_db and has_django and self.core.database_available:
return True
elif not use_db:
return False
diff --git a/src/lib/Bcfg2/Server/Plugins/DBStats.py b/src/lib/Bcfg2/Server/Plugins/DBStats.py
index fa1f45a39..b8750f850 100644
--- a/src/lib/Bcfg2/Server/Plugins/DBStats.py
+++ b/src/lib/Bcfg2/Server/Plugins/DBStats.py
@@ -27,8 +27,8 @@ class DBStats(Bcfg2.Server.Plugin.ThreadedStatistics,
Bcfg2.Server.Plugin.PullSource.__init__(self)
self.cpath = "%s/Metadata/clients.xml" % datastore
self.core = core
- logger.debug("Searching for new models to "
- "add to the statistics database")
+ if not self.core.database_available:
+ raise Bcfg2.Server.Plugin.PluginInitError
def handle_statistic(self, metadata, data):
newstats = data.find("Statistics")
diff --git a/src/lib/Bcfg2/Server/SchemaUpdater/__init__.py b/src/lib/Bcfg2/Server/SchemaUpdater/__init__.py
index ac33724a0..d57175cd7 100644
--- a/src/lib/Bcfg2/Server/SchemaUpdater/__init__.py
+++ b/src/lib/Bcfg2/Server/SchemaUpdater/__init__.py
@@ -1,4 +1,5 @@
from django.db import connection, DatabaseError
+from django.core.exceptions import ImproperlyConfigured
import django.core.management
import logging
import pkgutil
@@ -232,6 +233,9 @@ def update_database():
except UpdaterError:
raise
+ except ImproperlyConfigured:
+ logger.error("Django is not properly configured: %s" % traceback.format_exc().splitlines()[-1])
+ raise UpdaterError
except:
logger.error("Error while updating the database")
for x in traceback.format_exc().splitlines():