From 385281eb2375811ee6bb101ed859f2acc8103dd6 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Wed, 10 Oct 2012 08:19:26 -0400 Subject: Packages: added stats tracking --- src/lib/Bcfg2/Server/Plugins/Packages/Collection.py | 3 +++ src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py | 2 ++ src/lib/Bcfg2/Server/Plugins/Packages/Source.py | 1 + src/lib/Bcfg2/Server/Plugins/Packages/Yum.py | 15 +++++++++++---- src/lib/Bcfg2/Server/Plugins/Packages/__init__.py | 5 +++++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Collection.py b/src/lib/Bcfg2/Server/Plugins/Packages/Collection.py index bb98fe1e5..a0646d101 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/Collection.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/Collection.py @@ -218,6 +218,7 @@ class Collection(list, Bcfg2.Server.Plugin.Debuggable): cachefiles.add(source.cachefile) return list(cachefiles) + @Bcfg2.Server.Plugin.track_statistics() def get_groups(self, grouplist): """ Given a list of package group names, return a dict of ``: ``. This method is provided @@ -238,6 +239,7 @@ class Collection(list, Bcfg2.Server.Plugin.Debuggable): rv[group] = self.get_group(group, ptype) return rv + @Bcfg2.Server.Plugin.track_statistics() def get_group(self, group, ptype=None): """ Get the list of packages of the given type in a package group. @@ -486,6 +488,7 @@ class Collection(list, Bcfg2.Server.Plugin.Debuggable): """ return list(complete.difference(initial)) + @Bcfg2.Server.Plugin.track_statistics() def complete(self, packagelist): # pylint: disable=R0912,R0914 """ Build a complete list of all packages and their dependencies. diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py b/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py index 2519ddff6..94dc6d2fd 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py @@ -111,6 +111,7 @@ class PackagesSources(Bcfg2.Server.Plugin.StructFile, load its data. """ return sorted(list(self.parsed)) == sorted(self.extras) + @Bcfg2.Server.Plugin.track_statistics() def Index(self): Bcfg2.Server.Plugin.StructFile.Index(self) self.entries = [] @@ -123,6 +124,7 @@ class PackagesSources(Bcfg2.Server.Plugin.StructFile, ``Index`` is responsible for calling :func:`source_from_xml` for each ``Source`` tag in each file. """ + @Bcfg2.Server.Plugin.track_statistics() def source_from_xml(self, xsource): """ Create a :class:`Bcfg2.Server.Plugins.Packages.Source.Source` subclass diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Source.py b/src/lib/Bcfg2/Server/Plugins/Packages/Source.py index 22d488121..b98070ca9 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/Source.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/Source.py @@ -328,6 +328,7 @@ class Source(Bcfg2.Server.Plugin.Debuggable): # pylint: disable=R0902 self.essentialpkgs), cache, 2) cache.close() + @Bcfg2.Server.Plugin.track_statistics() def setup_data(self, force_update=False): """ Perform all data fetching and setup tasks. For most backends, this involves downloading all metadata from the diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py index 420c65844..c01f8359b 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py @@ -187,10 +187,7 @@ class YumCollection(Collection): def __package_groups__(self): """ YumCollections support package groups only if :attr:`use_yum` is True """ - if self.use_yum: - return True - else: - return False + return self.use_yum @property def helper(self): @@ -238,6 +235,7 @@ class YumCollection(Collection): cachefiles.add(self.cachefile) return list(cachefiles) + @Bcfg2.Server.Plugin.track_statistics() def write_config(self): """ Write the server-side config file to :attr:`cfgfile` based on the data from :func:`get_config`""" @@ -339,6 +337,7 @@ class YumCollection(Collection): return "# This config was generated automatically by the Bcfg2 " \ "Packages plugin\n\n" + buf.getvalue() + @Bcfg2.Server.Plugin.track_statistics() def build_extra_structures(self, independent): """ Add additional entries to the ```` section of the final configuration. This adds several kinds of @@ -429,6 +428,7 @@ class YumCollection(Collection): group="root", perms="0644") crt.text = consumerapi.certificate(self.metadata.hostname) + @Bcfg2.Server.Plugin.track_statistics() def _get_pulp_consumer(self, consumerapi=None): """ Get a Pulp consumer object for the client. @@ -457,6 +457,7 @@ class YumCollection(Collection): "%s" % err) return consumer + @Bcfg2.Server.Plugin.track_statistics() def _add_gpg_instances(self, keyentry, localkey, remotekey, keydata=None): """ Add GPG keys instances to a ``Package`` entry. This is called from :func:`build_extra_structures` to add GPG keys to @@ -499,6 +500,7 @@ class YumCollection(Collection): self.logger.error("Packages: Could not read GPG key %s: %s" % (localkey, err)) + @Bcfg2.Server.Plugin.track_statistics() def get_groups(self, grouplist): """ If using the yum libraries, given a list of package group names, return a dict of ``: ``. @@ -660,6 +662,7 @@ class YumCollection(Collection): new.append(pkg) return new + @Bcfg2.Server.Plugin.track_statistics() def complete(self, packagelist): """ Build a complete list of all packages and their dependencies. @@ -699,6 +702,7 @@ class YumCollection(Collection): else: return set(), set() + @Bcfg2.Server.Plugin.track_statistics() def call_helper(self, command, inputdata=None): """ Make a call to :ref:`bcfg2-yum-helper`. The yum libs have horrific memory leaks, so apparently the right way to get @@ -923,6 +927,7 @@ class YumSource(Source): self.file_to_arch[self.escape_url(fullurl)] = arch return urls + @Bcfg2.Server.Plugin.track_statistics() def read_files(self): """ When using the builtin yum parser, read and parse locally downloaded metadata files. This diverges from the stock @@ -964,6 +969,7 @@ class YumSource(Source): self.packages[key].difference(self.packages['global']) self.save_state() + @Bcfg2.Server.Plugin.track_statistics() def parse_filelist(self, data, arch): """ parse filelists.xml.gz data """ if arch not in self.filemap: @@ -977,6 +983,7 @@ class YumSource(Source): self.filemap[arch][fentry.text] = \ set([pkg.get('name')]) + @Bcfg2.Server.Plugin.track_statistics() def parse_primary(self, data, arch): """ parse primary.xml.gz data """ if arch not in self.packages: diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py b/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py index c8f643415..224866d9c 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py @@ -248,6 +248,7 @@ class Packages(Bcfg2.Server.Plugin.Plugin, return True return False + @Bcfg2.Server.Plugin.track_statistics() def validate_structures(self, metadata, structures): """ Do the real work of Packages. This does two things: @@ -282,6 +283,7 @@ class Packages(Bcfg2.Server.Plugin.Plugin, collection.build_extra_structures(indep) structures.append(indep) + @Bcfg2.Server.Plugin.track_statistics() def _build_packages(self, metadata, independent, structures, collection=None): """ Perform dependency resolution and build the complete list @@ -352,6 +354,7 @@ class Packages(Bcfg2.Server.Plugin.Plugin, newpkgs.sort() collection.packages_to_entry(newpkgs, independent) + @Bcfg2.Server.Plugin.track_statistics() def Refresh(self): """ Packages.Refresh() => True|False @@ -359,6 +362,7 @@ class Packages(Bcfg2.Server.Plugin.Plugin, self._load_config(force_update=True) return True + @Bcfg2.Server.Plugin.track_statistics() def Reload(self): """ Packages.Refresh() => True|False @@ -442,6 +446,7 @@ class Packages(Bcfg2.Server.Plugin.Plugin, if kfile not in keyfiles: os.unlink(kfile) + @Bcfg2.Server.Plugin.track_statistics() def get_collection(self, metadata): """ Get a :class:`Bcfg2.Server.Plugins.Packages.Collection.Collection` -- cgit v1.2.3-1-g7c22