From a0fa9103721e6c165902d5db2e9b7b6cc2c30d5a Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Fri, 4 May 2012 10:56:29 -0400 Subject: better support for re-reading packages.conf (and SimpleConfigs in general) --- src/lib/Bcfg2/Server/Plugin.py | 12 ++++++++-- .../Server/Plugins/Packages/PackagesSources.py | 8 ++++--- src/lib/Bcfg2/Server/Plugins/Packages/Yum.py | 27 ++++++++++++++-------- 3 files changed, 32 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/lib/Bcfg2/Server/Plugin.py b/src/lib/Bcfg2/Server/Plugin.py index 11e6c5c20..41314bbea 100644 --- a/src/lib/Bcfg2/Server/Plugin.py +++ b/src/lib/Bcfg2/Server/Plugin.py @@ -4,7 +4,6 @@ import copy import logging import lxml.etree import os -import os.path import pickle import posixpath import re @@ -1202,6 +1201,7 @@ class SimpleConfig(FileBacked, filename = os.path.join(plugin.data, plugin.name.lower() + ".conf") self.plugin = plugin self.fam = self.plugin.core.fam + self.read_files = set() Bcfg2.Server.Plugin.FileBacked.__init__(self, filename) ConfigParser.SafeConfigParser.__init__(self) @@ -1213,7 +1213,7 @@ class SimpleConfig(FileBacked, """ Build local data structures """ for section in self.sections(): self.remove_section(section) - self.read(self.name) + self.read_files.update(self.read(self.name)) def get(self, section, option, **kwargs): """ convenience method for getting config items """ @@ -1245,3 +1245,11 @@ class SimpleConfig(FileBacked, return default else: raise + + @property + def loaded(self): + if os.path.exists(self.name): + return self.name in self.read_files + else: + return True + diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py b/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py index 8d0067b6a..a966268c0 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py @@ -35,7 +35,6 @@ class PackagesSources(Bcfg2.Server.Plugin.SingleXMLFileBacked, (self.cachepath, err)) self.pkg_obj = packages self.parsed = set() - self.loaded = False def toggle_debug(self): Bcfg2.Server.Plugin.Debuggable.toggle_debug(self) @@ -57,10 +56,13 @@ class PackagesSources(Bcfg2.Server.Plugin.SingleXMLFileBacked, self.parsed.add(fname) break - if sorted(list(self.parsed)) == sorted(self.extras): + if self.config.loaded and self.loaded: self.logger.info("Reloading Packages plugin") self.pkg_obj.Reload() - self.loaded = True + + @property + def loaded(self): + return sorted(list(self.parsed)) == sorted(self.extras) def Index(self): Bcfg2.Server.Plugin.SingleXMLFileBacked.Index(self) diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py index 85eadafb3..941203db3 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py @@ -15,6 +15,7 @@ from Bcfg2.Bcfg2Py3k import StringIO, cPickle, HTTPError, ConfigParser, file from Bcfg2.Server.Plugins.Packages.Collection import Collection from Bcfg2.Server.Plugins.Packages.Source import SourceInitError, Source, \ fetch_url +from Bcfg2.Server.Plugins.Packages.PackagesConfig import PackagesConfig logger = logging.getLogger(__name__) @@ -91,12 +92,9 @@ class YumCollection(Collection): self.keypath = os.path.join(self.basepath, "keys") if len(sources): - config = sources[0].config - self.use_yum = has_yum and config.getboolean("yum", - "use_yum_libraries", - default=False) + self.config = sources[0].config else: - self.use_yum = False + self.config = PackageConfig('Packages') if self.use_yum: self.cachefile = os.path.join(self.cachepath, @@ -110,12 +108,19 @@ class YumCollection(Collection): self.cfgfile = os.path.join(self.configdir, "%s-yum.conf" % self.cachekey) self.write_config() - - self.helper = self.config.get("yum", "helper", - default="/usr/sbin/bcfg2-yum-helper") if has_pulp and self.has_pulp_sources: _setup_pulp(self.config) + @property + def helper(self): + return self.config.get("yum", "helper", + default="/usr/sbin/bcfg2-yum-helper") + + @property + def use_yum(self): + return has_yum and self.config.getboolean("yum", "use_yum_libraries", + default=False) + @property def has_pulp_sources(self): """ see if there are any pulp sources to handle """ @@ -492,8 +497,10 @@ class YumSource(Source): self.needed_paths = set() self.file_to_arch = dict() - self.use_yum = has_yum and config.getboolean("yum", "use_yum_libraries", - default=False) + @property + def use_yum(self): + return has_yum and self.config.getboolean("yum", "use_yum_libraries", + default=False) def save_state(self): if not self.use_yum: -- cgit v1.2.3-1-g7c22