summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-08-09 11:51:06 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-08-09 12:02:45 -0400
commit35bb03c45a057d1f0f313d129125cc0d1f7c1042 (patch)
tree4956dc23eacdef5bc699a68fe53c02768052220b /src/lib/Bcfg2
parent53d5423f3e5e09812c751360ba53f0a2639d2f29 (diff)
downloadbcfg2-35bb03c45a057d1f0f313d129125cc0d1f7c1042.tar.gz
bcfg2-35bb03c45a057d1f0f313d129125cc0d1f7c1042.tar.bz2
bcfg2-35bb03c45a057d1f0f313d129125cc0d1f7c1042.zip
move MetadataConsistency/RuntimeError exceptions into Plugin.py so we don't depend on a particular Metadata plugin
Diffstat (limited to 'src/lib/Bcfg2')
-rw-r--r--src/lib/Bcfg2/Server/Core.py25
-rw-r--r--src/lib/Bcfg2/Server/Plugin.py16
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Metadata.py59
3 files changed, 50 insertions, 50 deletions
diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py
index 7e0e33024..5b84a334d 100644
--- a/src/lib/Bcfg2/Server/Core.py
+++ b/src/lib/Bcfg2/Server/Core.py
@@ -10,15 +10,10 @@ import time
import inspect
import lxml.etree
from traceback import format_exc
-
-# this must be set before we import the Metadata plugin
-os.environ['DJANGO_SETTINGS_MODULE'] = 'Bcfg2.settings'
-
import Bcfg2.settings
import Bcfg2.Server
import Bcfg2.Logger
import Bcfg2.Server.FileMonitor
-import Bcfg2.Server.Plugins.Metadata
from Bcfg2.Bcfg2Py3k import xmlrpclib
from Bcfg2.Server.Plugin import PluginInitError, PluginExecutionError
@@ -31,6 +26,8 @@ try:
except:
pass
+os.environ['DJANGO_SETTINGS_MODULE'] = 'Bcfg2.settings'
+
def exposed(func):
func.exposed = True
return func
@@ -356,7 +353,7 @@ class BaseCore(object):
revision=self.revision)
try:
meta = self.build_metadata(client)
- except Bcfg2.Server.Plugins.Metadata.MetadataConsistencyError:
+ except Bcfg2.Server.Plugin.MetadataConsistencyError:
self.logger.error("Metadata consistency error for client %s" %
client)
return lxml.etree.Element("error", type='metadata error')
@@ -447,7 +444,7 @@ class BaseCore(object):
"""Build the metadata structure."""
if not hasattr(self, 'metadata'):
# some threads start before metadata is even loaded
- raise Bcfg2.Server.Plugins.Metadata.MetadataRuntimeError
+ raise Bcfg2.Server.Plugin.MetadataRuntimeError
imd = self.metadata.get_initial_metadata(client_name)
for conn in self.connectors:
grps = conn.get_additional_groups(imd)
@@ -483,11 +480,11 @@ class BaseCore(object):
meta = self.build_metadata(client)
else:
meta = None
- except Bcfg2.Server.Plugins.Metadata.MetadataConsistencyError:
+ except Bcfg2.Server.Plugin.MetadataConsistencyError:
err = sys.exc_info()[1]
self.critical_error("Client metadata resolution error for %s: %s" %
(address[0], err))
- except Bcfg2.Server.Plugins.Metadata.MetadataRuntimeError:
+ except Bcfg2.Server.Plugin.MetadataRuntimeError:
err = sys.exc_info()[1]
self.critical_error('Metadata system runtime failure for %s: %s' %
(address[0], err))
@@ -526,8 +523,8 @@ class BaseCore(object):
client, metadata = self.resolve_client(address)
try:
self.metadata.set_version(client, version)
- except (Bcfg2.Server.Plugins.Metadata.MetadataConsistencyError,
- Bcfg2.Server.Plugins.Metadata.MetadataRuntimeError):
+ except (Bcfg2.Server.Plugin.MetadataConsistencyError,
+ Bcfg2.Server.Plugin.MetadataRuntimeError):
err = sys.exc_info()[1]
self.critical_error("Unable to set version for %s: %s" %
(client, err))
@@ -584,8 +581,8 @@ class BaseCore(object):
client = self.resolve_client(address, metadata=False)[0]
try:
self.metadata.set_profile(client, profile, address)
- except (Bcfg2.Server.Plugins.Metadata.MetadataConsistencyError,
- Bcfg2.Server.Plugins.Metadata.MetadataRuntimeError):
+ except (Bcfg2.Server.Plugin.MetadataConsistencyError,
+ Bcfg2.Server.Plugin.MetadataRuntimeError):
err = sys.exc_info()[1]
self.critical_error("Unable to assert profile for %s: %s" %
(client, err))
@@ -599,7 +596,7 @@ class BaseCore(object):
config = self.BuildConfiguration(client)
return lxml.etree.tostring(config, encoding='UTF-8',
xml_declaration=True)
- except Bcfg2.Server.Plugins.Metadata.MetadataConsistencyError:
+ except Bcfg2.Server.Plugin.MetadataConsistencyError:
self.critical_error("Metadata consistency failure for %s" % client)
@exposed
diff --git a/src/lib/Bcfg2/Server/Plugin.py b/src/lib/Bcfg2/Server/Plugin.py
index 31c62018a..e030ff1bd 100644
--- a/src/lib/Bcfg2/Server/Plugin.py
+++ b/src/lib/Bcfg2/Server/Plugin.py
@@ -72,6 +72,18 @@ class PluginExecutionError(Exception):
pass
+class MetadataConsistencyError(Exception):
+ """This error gets raised when metadata is internally inconsistent."""
+ pass
+
+
+class MetadataRuntimeError(Exception):
+ """This error is raised when the metadata engine
+ is called prior to reading enough data.
+ """
+ pass
+
+
class Debuggable(object):
__rmi__ = ['toggle_debug']
@@ -294,7 +306,7 @@ class ThreadedStatistics(Statistics, threading.Thread):
try:
metadata = self.core.build_metadata(pmetadata)
break
- except Bcfg2.Server.Plugins.Metadata.MetadataRuntimeError:
+ except MetadataRuntimeError:
pass
self.terminate.wait(5)
@@ -311,7 +323,7 @@ class ThreadedStatistics(Statistics, threading.Thread):
lxml_error = sys.exc_info()[1]
self.logger.error("Unable to load saved interaction: %s" %
lxml_error)
- except Bcfg2.Server.Plugins.Metadata.MetadataConsistencyError:
+ except MetadataConsistencyError:
self.logger.error("Unable to load metadata for save "
"interaction: %s" % pmetadata)
try:
diff --git a/src/lib/Bcfg2/Server/Plugins/Metadata.py b/src/lib/Bcfg2/Server/Plugins/Metadata.py
index 79aaddbf6..fcef6ebb7 100644
--- a/src/lib/Bcfg2/Server/Plugins/Metadata.py
+++ b/src/lib/Bcfg2/Server/Plugins/Metadata.py
@@ -81,18 +81,6 @@ if has_django:
return False
-class MetadataConsistencyError(Exception):
- """This error gets raised when metadata is internally inconsistent."""
- pass
-
-
-class MetadataRuntimeError(Exception):
- """This error is raised when the metadata engine
- is called prior to reading enough data.
- """
- pass
-
-
class XMLMetadataConfig(Bcfg2.Server.Plugin.XMLFileBacked):
"""Handles xml config files and all XInclude statements"""
def __init__(self, metadata, watch_clients, basefile):
@@ -117,13 +105,15 @@ class XMLMetadataConfig(Bcfg2.Server.Plugin.XMLFileBacked):
@property
def xdata(self):
if not self.data:
- raise MetadataRuntimeError("%s has no data" % self.basefile)
+ raise Bcfg2.Server.Plugin.MetadataRuntimeError("%s has no data" %
+ self.basefile)
return self.data
@property
def base_xdata(self):
if not self.basedata:
- raise MetadataRuntimeError("%s has no data" % self.basefile)
+ raise Bcfg2.Server.Plugin.MetadataRuntimeError("%s has no data" %
+ self.basefile)
return self.basedata
def load_xml(self):
@@ -158,7 +148,7 @@ class XMLMetadataConfig(Bcfg2.Server.Plugin.XMLFileBacked):
except IOError:
msg = "Failed to write %s: %s" % (tmpfile, sys.exc_info()[1])
self.logger.error(msg)
- raise MetadataRuntimeError(msg)
+ raise Bcfg2.Server.Plugin.MetadataRuntimeError(msg)
# prep data
dataroot = xmltree.getroot()
newcontents = lxml.etree.tostring(dataroot, pretty_print=True)
@@ -174,7 +164,7 @@ class XMLMetadataConfig(Bcfg2.Server.Plugin.XMLFileBacked):
(tmpfile, sys.exc_info()[1])
self.logger.error(msg, exc_info=1)
os.unlink(tmpfile)
- raise MetadataRuntimeError(msg)
+ raise Bcfg2.Server.Plugin.MetadataRuntimeError(msg)
datafile.close()
# check if clients.xml is a symlink
if os.path.islink(fname):
@@ -187,7 +177,7 @@ class XMLMetadataConfig(Bcfg2.Server.Plugin.XMLFileBacked):
msg = "Metadata: Failed to rename %s: %s" % (tmpfile,
sys.exc_info()[1])
self.logger.error(msg)
- raise MetadataRuntimeError(msg)
+ raise Bcfg2.Server.Plugin.MetadataRuntimeError(msg)
def find_xml_for_xpath(self, xpath):
"""Find and load xml file containing the xpath query"""
@@ -434,7 +424,7 @@ class Metadata(Bcfg2.Server.Plugin.Metadata,
node = self._search_xdata(tag, name, config.xdata, alias=alias)
if node != None:
self.logger.error("%s \"%s\" already exists" % (tag, name))
- raise MetadataConsistencyError
+ raise Bcfg2.Server.Plugin.MetadataConsistencyError
element = lxml.etree.SubElement(config.base_xdata.getroot(),
tag, name=name)
if attribs:
@@ -478,13 +468,13 @@ class Metadata(Bcfg2.Server.Plugin.Metadata,
node = self._search_xdata(tag, name, config.xdata, alias=alias)
if node == None:
self.logger.error("%s \"%s\" does not exist" % (tag, name))
- raise MetadataConsistencyError
+ raise Bcfg2.Server.Plugin.MetadataConsistencyError
xdict = config.find_xml_for_xpath('.//%s[@name="%s"]' %
(tag, node.get('name')))
if not xdict:
self.logger.error("Unexpected error finding %s \"%s\"" %
(tag, name))
- raise MetadataConsistencyError
+ raise Bcfg2.Server.Plugin.MetadataConsistencyError
for key, val in list(attribs.items()):
xdict['xquery'][0].set(key, val)
config.write_xml(xdict['filename'], xdict['xmltree'])
@@ -520,13 +510,13 @@ class Metadata(Bcfg2.Server.Plugin.Metadata,
node = self._search_xdata(tag, name, config.xdata)
if node == None:
self.logger.error("%s \"%s\" does not exist" % (tag, name))
- raise MetadataConsistencyError
+ raise Bcfg2.Server.Plugin.MetadataConsistencyError
xdict = config.find_xml_for_xpath('.//%s[@name="%s"]' %
(tag, node.get('name')))
if not xdict:
self.logger.error("Unexpected error finding %s \"%s\"" %
(tag, name))
- raise MetadataConsistencyError
+ raise Bcfg2.Server.Plugin.MetadataConsistencyError
xdict['xquery'][0].getparent().remove(xdict['xquery'][0])
config.write_xml(xdict['filename'], xdict['xmltree'])
@@ -556,7 +546,7 @@ class Metadata(Bcfg2.Server.Plugin.Metadata,
except MetadataClientModel.DoesNotExist:
msg = "Client %s does not exist" % client_name
self.logger.warning(msg)
- raise MetadataConsistencyError(msg)
+ raise Bcfg2.Server.Plugin.MetadataConsistencyError(msg)
client.delete()
self.clients = self.list_clients()
else:
@@ -739,16 +729,16 @@ class Metadata(Bcfg2.Server.Plugin.Metadata,
self.logger.info("Asserting client %s profile to %s" %
(client, profile))
if False in list(self.states.values()):
- raise MetadataRuntimeError
+ raise Bcfg2.Server.Plugin.MetadataRuntimeError("Metadata has not been read yet")
if not force and profile not in self.groups:
msg = "Profile group %s does not exist" % profile
self.logger.error(msg)
- raise MetadataConsistencyError(msg)
+ raise Bcfg2.Server.Plugin.MetadataConsistencyError(msg)
group = self.groups[profile]
if not force and not group.is_public:
msg = "Cannot set client %s to private group %s" % (client, profile)
self.logger.error(msg)
- raise MetadataConsistencyError(msg)
+ raise Bcfg2.Server.Plugin.MetadataConsistencyError(msg)
if client in self.clients:
if self._use_db:
@@ -795,7 +785,7 @@ class Metadata(Bcfg2.Server.Plugin.Metadata,
else:
msg = "Cannot set version on non-existent client %s" % client
self.logger.error(msg)
- raise MetadataConsistencyError(msg)
+ raise Bcfg2.Server.Plugin.MetadataConsistencyError(msg)
self.versions[client] = version
self.clients_xml.write()
@@ -829,7 +819,7 @@ class Metadata(Bcfg2.Server.Plugin.Metadata,
if len(self.addresses[address]) != 1:
err = "Address %s has multiple reverse assignments; a uuid must be used" % address
self.logger.error(err)
- raise MetadataConsistencyError(err)
+ raise Bcfg2.Server.Plugin.MetadataConsistencyError(err)
return self.addresses[address][0]
try:
cname = socket.gethostbyaddr(address)[0].lower()
@@ -839,7 +829,7 @@ class Metadata(Bcfg2.Server.Plugin.Metadata,
except socket.herror:
warning = "address resolution error for %s" % address
self.logger.warning(warning)
- raise MetadataConsistencyError(warning)
+ raise Bcfg2.Server.Plugin.MetadataConsistencyError(warning)
def _merge_groups(self, client, groups, categories=None):
""" set group membership based on the contents of groups.xml
@@ -869,7 +859,7 @@ class Metadata(Bcfg2.Server.Plugin.Metadata,
def get_initial_metadata(self, client):
"""Return the metadata for a given client."""
if False in list(self.states.values()):
- raise MetadataRuntimeError("Metadata has not been read yet")
+ raise Bcfg2.Server.Plugin.MetadataRuntimeError("Metadata has not been read yet")
client = client.lower()
if client in self.aliases:
client = self.aliases[client]
@@ -896,7 +886,7 @@ class Metadata(Bcfg2.Server.Plugin.Metadata,
else:
msg = "Cannot add new client %s; no default group set" % client
self.logger.error(msg)
- raise MetadataConsistencyError(msg)
+ raise Bcfg2.Server.Plugin.MetadataConsistencyError(msg)
if client in self.clientgroups:
for cgroup in self.clientgroups[client]:
@@ -1050,9 +1040,10 @@ class Metadata(Bcfg2.Server.Plugin.Metadata,
id_method = 'address'
try:
client = self.resolve_client(address)
- except MetadataConsistencyError:
- self.logger.error("Client %s failed to resolve; metadata problem"
- % address[0])
+ except Bcfg2.Server.Plugin.MetadataConsistencyError:
+ err = sys.exc_info()[1]
+ self.logger.error("Client %s failed to resolve: %s" %
+ (address[0], err))
return False
else:
id_method = 'uuid'