summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Laszlo <tim.laszlo@gmail.com>2010-07-26 15:30:42 +0000
committerSol Jerome <sol.jerome@gmail.com>2010-07-30 11:53:15 -0500
commitd74aa12c9d3d92c405aaacb5a3bfd265b017879f (patch)
tree24aae1bc8b811662e4a56b3981abee1591fb9768
parent804c8f5f237b8c445a16750fa50df2344387ae07 (diff)
downloadbcfg2-d74aa12c9d3d92c405aaacb5a3bfd265b017879f.tar.gz
bcfg2-d74aa12c9d3d92c405aaacb5a3bfd265b017879f.tar.bz2
bcfg2-d74aa12c9d3d92c405aaacb5a3bfd265b017879f.zip
Packages: Allow xinclude and add XML error handling
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5990 ce84e21b-d406-0410-9b95-82705330c041
-rw-r--r--schemas/packages.xsd17
-rw-r--r--src/lib/Server/Plugins/Packages.py24
2 files changed, 27 insertions, 14 deletions
diff --git a/schemas/packages.xsd b/schemas/packages.xsd
index 342920c2b..e15fb7f99 100644
--- a/schemas/packages.xsd
+++ b/schemas/packages.xsd
@@ -32,12 +32,13 @@
</xsd:sequence>
</xsd:complexType>
- <xsd:element name='Sources'>
- <xsd:complexType>
- <xsd:choice minOccurs='1' maxOccurs='unbounded'>
- <xsd:element name='APTSource' type='SourceType'/>
- <xsd:element name='YUMSource' type='SourceType'/>
- </xsd:choice>
- </xsd:complexType>
- </xsd:element>
+ <xsd:complexType name='SourcesType'>
+ <xsd:choice minOccurs='1' maxOccurs='unbounded'>
+ <xsd:element name='APTSource' type='SourceType'/>
+ <xsd:element name='YUMSource' type='SourceType'/>
+ <xsd:element name='Sources' type='SourcesType'/>
+ </xsd:choice>
+ </xsd:complexType>
+
+ <xsd:element name='Sources' type='SourcesType'/>
</xsd:schema>
diff --git a/src/lib/Server/Plugins/Packages.py b/src/lib/Server/Plugins/Packages.py
index 40b01e64e..7978ddd62 100644
--- a/src/lib/Server/Plugins/Packages.py
+++ b/src/lib/Server/Plugins/Packages.py
@@ -543,16 +543,22 @@ class Packages(Bcfg2.Server.Plugin.Plugin,
# create cache directory if needed
os.makedirs(self.cachepath)
try:
- xdata = lxml.etree.parse(self.data + '/config.xml').getroot()
+ xdata = lxml.etree.parse(self.data + '/config.xml')
+ xdata.xinclude()
+ xdata = xdata.getroot()
+ except (lxml.etree.XIncludeError, \
+ lxml.etree.XMLSyntaxError), xmlerr:
+ self.logger.error("Package: Error processing xml: %s" % xmlerr)
+ raise Bcfg2.Server.Plugin.PluginInitError
except IOError:
self.logger.error("Failed to read Packages configuration. Have"
" you created your config.xml file?")
raise Bcfg2.Server.Plugin.PluginInitError
self.sentinels = set()
self.sources = []
- for s in xdata.findall('APTSource'):
+ for s in xdata.findall('.//APTSource'):
self.sources.append(APTSource(self.cachepath, **source_from_xml(s)))
- for s in xdata.findall('YUMSource'):
+ for s in xdata.findall('.//YUMSource'):
self.sources.append(YUMSource(self.cachepath, **source_from_xml(s)))
for source in self.sources:
source.setup_data()
@@ -682,16 +688,22 @@ class Packages(Bcfg2.Server.Plugin.Plugin,
def Refresh(self):
'''Packages.Refresh() => True|False\nReload configuration specification and sources\n'''
try:
- xdata = lxml.etree.parse(self.data + '/config.xml').getroot()
+ xdata = lxml.etree.parse(self.data + '/config.xml')
+ xdata.xinclude()
+ xdata = xdata.getroot()
+ except (lxml.etree.XIncludeError, \
+ lxml.etree.XMLSyntaxError), xmlerr:
+ self.logger.error("Package: Error processing xml: %s" % xmlerr)
+ raise Bcfg2.Server.Plugin.PluginInitError
except IOError:
self.logger.error("Failed to read Packages configuration. Have" +
" you created your config.xml file?")
raise Bcfg2.Server.Plugin.PluginInitError
self.sentinels = set()
self.sources = []
- for s in xdata.findall('APTSource'):
+ for s in xdata.findall('.//APTSource'):
self.sources.append(APTSource(self.cachepath, **source_from_xml(s)))
- for s in xdata.findall('YUMSource'):
+ for s in xdata.findall('.//YUMSource'):
self.sources.append(YUMSource(self.cachepath, **source_from_xml(s)))
for source in self.sources:
source.setup_data()