diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2009-03-13 02:35:35 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2009-03-13 02:35:35 +0000 |
commit | c15d5b167a65d860803465d57937e6c3e225cd8c (patch) | |
tree | 1e41c054e27933f6e8deb1dfcad61be7e1ae2d20 /src/lib/Client | |
parent | 9c9bcdd78d37d89b1da9e99dbcb477fce2afb78c (diff) | |
download | bcfg2-c15d5b167a65d860803465d57937e6c3e225cd8c.tar.gz bcfg2-c15d5b167a65d860803465d57937e6c3e225cd8c.tar.bz2 bcfg2-c15d5b167a65d860803465d57937e6c3e225cd8c.zip |
YUMng: implement version=auto/any support
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5118 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Client')
-rw-r--r-- | src/lib/Client/Tools/RPMng.py | 9 | ||||
-rw-r--r-- | src/lib/Client/Tools/YUMng.py | 82 |
2 files changed, 74 insertions, 17 deletions
diff --git a/src/lib/Client/Tools/RPMng.py b/src/lib/Client/Tools/RPMng.py index 3d0522950..e99b467b3 100644 --- a/src/lib/Client/Tools/RPMng.py +++ b/src/lib/Client/Tools/RPMng.py @@ -183,12 +183,13 @@ class RPMng(Bcfg2.Client.Tools.PkgTool): for attrib in entry.attrib.keys(): instance.attrib[attrib] = entry.attrib[attrib] if self.pkg_checks == 'true' and entry.get('pkg_checks', 'true') == 'true': - if entry.get('version') == 'any': - # FIXME not sure if this is synthesized properly + if 'any' in [entry.get('version'), pinned_version]: version, release = 'any', 'any' elif entry.get('version') == 'auto': - # FIXME ditto - version, release = pinned_version.split('-') + if pinned_version != None: + version, release = pinned_version.split('-') + else: + return False else: version, release = entry.get('version').split('-') instance.set('version', version) diff --git a/src/lib/Client/Tools/YUMng.py b/src/lib/Client/Tools/YUMng.py index ec95e09ec..3baacb32a 100644 --- a/src/lib/Client/Tools/YUMng.py +++ b/src/lib/Client/Tools/YUMng.py @@ -1,7 +1,9 @@ '''This provides bcfg2 support for yum''' __revision__ = '$Revision: $' -import Bcfg2.Client.Tools.RPMng, ConfigParser, sys, os.path +import Bcfg2.Client.XML +import Bcfg2.Client.Tools.RPMng +import ConfigParser, sys, os.path, copy try: set @@ -49,6 +51,53 @@ class YUMng(Bcfg2.Client.Tools.RPMng.RPMng): conflicts = ['RPMng'] + def __init__(self, logger, setup, config): + Bcfg2.Client.Tools.RPMng.RPMng.__init__(self, logger, setup, config) + self.yum_avail = dict() + self.yum_installed = dict() + for line in self.cmd.run('yum list updates --noplugins')[1][1:]: + try: + pinfo, vers, _ = line.split() + pkg, arch = pinfo.split('.') + if pkg in self.yum_avail: + self.yum_avail[pkg].update([(arch, vers)]) + else: + self.yum_avail[pkg] = dict([(arch, vers)]) + except: + continue + for line in self.cmd.run('yum list installed --noplugins')[1][1:]: + try: + pinfo, vers, _ = line.split() + pkg, arch = pinfo.split('.') + if pkg in self.yum_installed: + self.yum_installed[pkg].update([(arch, vers)]) + else: + self.yum_installed[pkg] = dict([(arch, vers)]) + except: + continue + + def VerifyPackage(self, entry, modlist): + pinned_version = None + if entry.get('version', False) == 'auto': + # old style entry; synthesize Instances from current installed + if entry.get('name') not in self.yum_installed and \ + entry.get('name') not in self.yum_avail: + # new entry; fall back to default + entry.set('version', 'any') + else: + data = copy.copy(self.yum_installed[entry.get('name')]) + if entry.get('name') in self.yum_avail: + # installed but out of date + data.update(self.yum_avail[entry.get('name')]) + for (arch, vdata) in data.iteritems(): + vers, rel = vdata.split('-') + Bcfg2.Client.XML.SubElement(entry, "Instance", + name=entry.get('name'), + version=vers, arch=arch, + release=rel) + return Bcfg2.Client.Tools.RPMng.RPMng.VerifyPackage(self, entry, + modlist) + def Install(self, packages, states): ''' Try and fix everything that RPMng.VerifyPackages() found wrong for @@ -92,16 +141,22 @@ class YUMng(Bcfg2.Client.Tools.RPMng.RPMng): # Figure out which instances of the packages actually need something # doing to them and place in the appropriate work 'queue'. for pkg in packages: - for inst in [pinst for pinst in pkg \ - if pinst.tag in ['Instance', 'Package']]: - if self.FixInstance(inst, self.instance_status[inst]): - if self.instance_status[inst].get('installed', False) == False: - if pkg.get('name') == 'gpg-pubkey': - gpg_keys.append(inst) - else: - install_pkgs.append(inst) - elif self.instance_status[inst].get('version_fail', False) == True: - upgrade_pkgs.append(inst) + insts = [pinst for pinst in pkg \ + if pinst.tag in ['Instance', 'Package']] + if insts: + for inst in insts: + if self.FixInstance(inst, self.instance_status[inst]): + if self.instance_status[inst].get('installed', False) \ + == False: + if pkg.get('name') == 'gpg-pubkey': + gpg_keys.append(inst) + else: + install_pkgs.append(inst) + elif self.instance_status[inst].get('version_fail', \ + False) == True: + upgrade_pkgs.append(inst) + else: + install_pkgs.append(pkg) # Install GPG keys. # Alternatively specify the required keys using 'gpgkey' in the @@ -142,11 +197,12 @@ class YUMng(Bcfg2.Client.Tools.RPMng.RPMng): pkg_arg = pkg_arg + '-' + inst.get('epoch') + ':' + inst.get('version') + \ '-' + inst.get('release') + '.' + inst.get('arch') else: - if inst.get('version', False): + if inst.get('version', False) and \ + inst.get('version') != 'any': pkg_arg = pkg_arg + '-' + inst.get('version') if inst.get('release', False): pkg_arg = pkg_arg + '-' + inst.get('release') - if inst.get('arch', False): + if inst.get('arch', False) and inst.get('arch') != 'any': pkg_arg = pkg_arg + '.' + inst.get('arch') install_args.append(pkg_arg) |