From dccd33a479c0ff14d90d2939534f91964e1a393c Mon Sep 17 00:00:00 2001 From: Michael Fenn Date: Thu, 6 Nov 2014 14:05:42 -0500 Subject: SYSV: change instances of simplename to simplefile This is to better match the schema since simplefile already exists. The previous simplename attribute would fail validation. Since pkgmgr already helpfully constructs url for you if simplefile exists, the tool no longer needs to do the concatenation itself. Given the low usage rate of SYSV.py and that the original functionality was introduced in a late 1.3 release, changing the name w/o providing backwards compatiblity seems reasonable. --- doc/client/tools.txt | 4 ++-- src/lib/Bcfg2/Client/Tools/SYSV.py | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/doc/client/tools.txt b/doc/client/tools.txt index ce8732454..26841ab11 100644 --- a/doc/client/tools.txt +++ b/doc/client/tools.txt @@ -158,14 +158,14 @@ Handles `System V Packaging - + File system format over NFS or local path: diff --git a/src/lib/Bcfg2/Client/Tools/SYSV.py b/src/lib/Bcfg2/Client/Tools/SYSV.py index a29b49efa..27c3d3785 100644 --- a/src/lib/Bcfg2/Client/Tools/SYSV.py +++ b/src/lib/Bcfg2/Client/Tools/SYSV.py @@ -52,18 +52,17 @@ class SYSV(Bcfg2.Client.Tools.PkgTool): self.origpkgtool = self.pkgtool def pkgmogrify(self, packages): - """ Take a list of pkg objects, check for a 'simplename' attribute. + """ Take a list of pkg objects, check for a 'simplefile' attribute. If present, insert a _sysv_pkg_path attribute to the package and download the datastream format SYSV package to a temporary file. """ for pkg in packages: - if pkg.get('simplename'): + if pkg.get('simplefile'): tmpfile = tempfile.NamedTemporaryFile() self.tmpfiles.append(tmpfile) - self.logger.info("Downloading %s%s to %s" % (pkg.get('url'), - pkg.get('simplename'), tmpfile.name)) - urlretrieve("%s/%s" % (pkg.get('url'), pkg.get('simplename')), - tmpfile.name) + self.logger.info("Downloading %s to %s" % (pkg.get('url'), + tmpfile.name)) + urlretrieve(pkg.get('url'), tmpfile.name) pkg.set('_sysv_pkg_path', tmpfile.name) def _get_package_command(self, packages): -- cgit v1.2.3-1-g7c22 From ddf888ec1237fb27c329f9e667c791ee7c257720 Mon Sep 17 00:00:00 2001 From: Michael Fenn Date: Thu, 6 Nov 2014 15:19:18 -0500 Subject: doc: Update SYSV datastream format docs --- doc/client/tools.txt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/doc/client/tools.txt b/doc/client/tools.txt index 26841ab11..170b30b2e 100644 --- a/doc/client/tools.txt +++ b/doc/client/tools.txt @@ -158,13 +158,21 @@ Handles `System V Packaging ` plugin will + automatically construct the url attribute by concatenating the uri and + simplefile attributes (with an intervening slash). + + Datastream format over HTTP: .. code-block:: xml - + -- cgit v1.2.3-1-g7c22 From ad438f9e17decda2efca0e8974995a6d028f7788 Mon Sep 17 00:00:00 2001 From: Michael Fenn Date: Fri, 7 Nov 2014 10:00:53 -0500 Subject: SYSV: add a migration tool to change simplename attributes to simplefile --- tools/upgrade/1.3/README | 4 +++ tools/upgrade/1.3/migrate_sysv_simplename.py | 51 ++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100755 tools/upgrade/1.3/migrate_sysv_simplename.py diff --git a/tools/upgrade/1.3/README b/tools/upgrade/1.3/README index 1a919f869..29fd9886b 100644 --- a/tools/upgrade/1.3/README +++ b/tools/upgrade/1.3/README @@ -24,3 +24,7 @@ migrate_probe_groups_to_db.py - Migrate Probe host and group data from XML to DB backend for Metadata and Probe plugins. Does not migrate individual probe return data. Assumes migration to BOTH Metadata and Probe to database backends. + +migrate_sysv_simplename.py + - Migrate any Pkgmgr entries which may have been using the simplename + attribute introduced in 1.3.5 to the simplefile attribute diff --git a/tools/upgrade/1.3/migrate_sysv_simplename.py b/tools/upgrade/1.3/migrate_sysv_simplename.py new file mode 100755 index 000000000..f6599756b --- /dev/null +++ b/tools/upgrade/1.3/migrate_sysv_simplename.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +import os +import sys +import glob +import lxml.etree +import Bcfg2.Options + +def main(): + opts = dict(repo=Bcfg2.Options.SERVER_REPOSITORY) + setup = Bcfg2.Options.OptionParser(opts) + setup.parse(sys.argv[1:]) + + files = [] + for plugin in ['Pkgmgr']: + files.extend(glob.glob(os.path.join(setup['repo'], plugin, "*"))) + + for bfile in files: + bdata = lxml.etree.parse(bfile) + changed = False + + if not bdata.xpath("//@type='sysv'"): + print("%s doesn't contain any sysv packages, skipping" % bfile) + continue + + pkglist = bdata.getroot() + if pkglist.tag != "PackageList": + print("%s doesn't look like a PackageList, skipping" % bfile) + continue + + for pkg in bdata.xpath("//Package"): + if "simplename" in pkg.attrib: + pkg.set("simplefile", pkg.get("simplename")) + del pkg.attrib["simplename"] + changed = True + + # if we switched to simplefile, we also need to switch to uri + if changed and "url" in pkglist.attrib: + pkglist.set("uri", pkglist.get("url")) + del pkglist.attrib["url"] + + if changed: + print("Writing %s" % bfile) + try: + open(bfile, "w").write(lxml.etree.tostring(bdata)) + except IOError: + err = sys.exc_info()[1] + print("Could not write %s: %s" % (bfile, err)) + +if __name__ == '__main__': + sys.exit(main()) -- cgit v1.2.3-1-g7c22