diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-07-15 15:32:21 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-07-15 15:43:07 -0400 |
commit | 2217fa6295070f137988006c4bb00d25dfc0cb5e (patch) | |
tree | fa79bcf1be203d5719871c3ea9d01b42c5c689b2 /src/sbin | |
parent | 156212c6fc294382198840e143f0867e0536601e (diff) | |
download | bcfg2-2217fa6295070f137988006c4bb00d25dfc0cb5e.tar.gz bcfg2-2217fa6295070f137988006c4bb00d25dfc0cb5e.tar.bz2 bcfg2-2217fa6295070f137988006c4bb00d25dfc0cb5e.zip |
Read-only yum cache
This makes the yum cache read-only so that bcfg2-yum-helper cannot
update the cache on the fly, which should help avoid locking issues
with the yum caches that can cause client runs to fail. It also makes
the Packages plugin behave more consistently, since use of yum
libraries won't cause the cache to be refreshed at random times on the
fly, but rather more predictably as with the Apt cache or the yum
cache without using yum libraries. Unlike those two cases, though,
the caches will not all be downloaded initially, but rather
opportunistically as needed.
In order for this to work, the Bcfg2 server must not run as root.
Root ignores the 'w' permissions bit, so the cache cannot be made
read-only.
Diffstat (limited to 'src/sbin')
-rwxr-xr-x | src/sbin/bcfg2-yum-helper | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/sbin/bcfg2-yum-helper b/src/sbin/bcfg2-yum-helper index 4ef531d39..473214d89 100755 --- a/src/sbin/bcfg2-yum-helper +++ b/src/sbin/bcfg2-yum-helper @@ -193,6 +193,20 @@ class DepSolver(object): if not msg.startswith("0 "): self.logger.info(msg) + def populate_cache(self): + """ populate the yum cache """ + for repo in self.yumbase.repos.findRepos('*'): + repo.metadata_expire = 0 + repo.mdpolicy = "group:all" + self.yumbase.doRepoSetup() + self.yumbase.repos.doSetup() + for repo in self.yumbase.repos.listEnabled(): + # this populates the cache as a side effect + repo.repoXML # pylint: disable=W0104 + self.yumbase.repos.populateSack(mdtype='metadata', cacheonly=1) + self.yumbase.repos.populateSack(mdtype='filelists', cacheonly=1) + self.yumbase.repos.populateSack(mdtype='otherdata', cacheonly=1) + def main(): parser = OptionParser() @@ -233,6 +247,15 @@ def main(): sys.exc_info()[1], exc_info=1) print(json.dumps(False)) rv = 2 + elif cmd == "makecache": + try: + # this code copied from yumcommands.py + depsolver.populate_cache() + print json.dumps(True) + except yum.Errors.YumBaseError: + logger.error("Unexpected error creating cache: %s" % + sys.exc_info()[1], exc_info=1) + print json.dumps(False) elif cmd == "complete": try: data = json.loads(sys.stdin.read()) |