summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2015-01-14 23:35:22 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2015-01-16 04:55:00 +0100
commit7d6032e82ea26baf82c64435925d6991d812e768 (patch)
treea05dff1ea4422759445783569b7fd6f4e0d3b54c /src
parent4609569ec9a7b9ea083c5546fa38ef401bba5fa8 (diff)
downloadbcfg2-7d6032e82ea26baf82c64435925d6991d812e768.tar.gz
bcfg2-7d6032e82ea26baf82c64435925d6991d812e768.tar.bz2
bcfg2-7d6032e82ea26baf82c64435925d6991d812e768.zip
Plugins/Packages: fix initialization of YumSource
During __init__ of the parent class get_repo_name is called. That needs fields (pump_id) that are defined later in the __init__ of YumSource. We introduce the new function _init_attributes to parse all attributes out of the <Source> tag before calling any other functions.
Diffstat (limited to 'src')
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Packages/Source.py134
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Packages/Yum.py7
2 files changed, 81 insertions, 60 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Source.py b/src/lib/Bcfg2/Server/Plugins/Packages/Source.py
index 30cdd543f..c09a9988b 100644
--- a/src/lib/Bcfg2/Server/Plugins/Packages/Source.py
+++ b/src/lib/Bcfg2/Server/Plugins/Packages/Source.py
@@ -143,6 +143,83 @@ class Source(Bcfg2.Server.Plugin.Debuggable): # pylint: disable=R0902
#: source
self.essentialpkgs = set()
+ self._init_attributes(basepath, xsource, setup)
+
+ #: A set of all package names in this source. This will not
+ #: necessarily be populated, particularly by backends that
+ #: reimplement large portions of
+ #: :class:`Bcfg2.Server.Plugins.Packages.Collection.Collection`
+ self.pkgnames = set()
+
+ #: A dict of ``<package name>`` -> ``<list of dependencies>``.
+ #: This will not necessarily be populated, particularly by
+ #: backends that reimplement large portions of
+ #: :class:`Bcfg2.Server.Plugins.Packages.Collection.Collection`
+ self.deps = dict()
+
+ #: A dict of ``<package name>`` -> ``<list of provided
+ #: symbols>``. This will not necessarily be populated,
+ #: particularly by backends that reimplement large portions of
+ #: :class:`Bcfg2.Server.Plugins.Packages.Collection.Collection`
+ self.provides = dict()
+
+ #: The file (or directory) used for this source's cache data
+ self.cachefile = os.path.join(self.basepath,
+ "cache-%s" % self.cachekey)
+ if not self.rawurl:
+ baseurl = self.url + "%(version)s/%(component)s/%(arch)s/"
+ else:
+ baseurl = self.rawurl
+
+ #: A list of dicts, each of which describes the URL to one
+ #: repository contained in this source. Each dict contains
+ #: the following keys:
+ #:
+ #: * ``version``: The version of the repo (``None`` for
+ #: ``rawurl`` repos)
+ #: * ``component``: The component use to form this URL
+ #: (``None`` for ``rawurl`` repos)
+ #: * ``arch``: The architecture of this repo
+ #: * ``baseurl``: Either the ``rawurl`` attribute, or the
+ #: format string built from the ``url`` attribute
+ #: * ``url``: The actual URL to the repository
+ self.url_map = []
+ for arch in self.arches:
+ if self.url:
+ usettings = [dict(version=self.version, component=comp,
+ arch=arch, debsrc=self.debsrc)
+ for comp in self.components]
+ else: # rawurl given
+ usettings = [dict(version=self.version, component=None,
+ arch=arch, debsrc=self.debsrc)]
+
+ for setting in usettings:
+ if not self.rawurl:
+ setting['baseurl'] = self.url
+ else:
+ setting['baseurl'] = self.rawurl
+ setting['url'] = baseurl % setting
+ setting['name'] = self.get_repo_name(setting)
+ self.url_map.extend(usettings)
+
+ def _init_attributes(self, basepath, xsource, setup):
+ """
+ This functions evaluates the Source tag and parses all
+ attributes. Override this function in a sub class to
+ parse specific attributes. Do not use ``__init__`` because
+ ``Source.__init__`` may call other functions that already
+ need this specific fields. This functions is called before
+ any other function.
+
+ :param basepath: The base filesystem path under which cache
+ data for this source should be stored
+ :type basepath: string
+ :param xsource: The XML tag that describes this source
+ :type source: lxml.etree._Element
+ :param setup: A Bcfg2 options dict
+ :type setup: dict
+ """
+
#: A list of the text of all 'Component' attributes of this
#: source from XML
self.components = [item.text for item in xsource.findall('Component')]
@@ -241,63 +318,6 @@ class Source(Bcfg2.Server.Plugin.Debuggable): # pylint: disable=R0902
self.conditions.append(lambda m, el=el:
el.get("name") == m.hostname)
- #: A set of all package names in this source. This will not
- #: necessarily be populated, particularly by backends that
- #: reimplement large portions of
- #: :class:`Bcfg2.Server.Plugins.Packages.Collection.Collection`
- self.pkgnames = set()
-
- #: A dict of ``<package name>`` -> ``<list of dependencies>``.
- #: This will not necessarily be populated, particularly by
- #: backends that reimplement large portions of
- #: :class:`Bcfg2.Server.Plugins.Packages.Collection.Collection`
- self.deps = dict()
-
- #: A dict of ``<package name>`` -> ``<list of provided
- #: symbols>``. This will not necessarily be populated,
- #: particularly by backends that reimplement large portions of
- #: :class:`Bcfg2.Server.Plugins.Packages.Collection.Collection`
- self.provides = dict()
-
- #: The file (or directory) used for this source's cache data
- self.cachefile = os.path.join(self.basepath,
- "cache-%s" % self.cachekey)
- if not self.rawurl:
- baseurl = self.url + "%(version)s/%(component)s/%(arch)s/"
- else:
- baseurl = self.rawurl
-
- #: A list of dicts, each of which describes the URL to one
- #: repository contained in this source. Each dict contains
- #: the following keys:
- #:
- #: * ``version``: The version of the repo (``None`` for
- #: ``rawurl`` repos)
- #: * ``component``: The component use to form this URL
- #: (``None`` for ``rawurl`` repos)
- #: * ``arch``: The architecture of this repo
- #: * ``baseurl``: Either the ``rawurl`` attribute, or the
- #: format string built from the ``url`` attribute
- #: * ``url``: The actual URL to the repository
- self.url_map = []
- for arch in self.arches:
- if self.url:
- usettings = [dict(version=self.version, component=comp,
- arch=arch, debsrc=self.debsrc)
- for comp in self.components]
- else: # rawurl given
- usettings = [dict(version=self.version, component=None,
- arch=arch, debsrc=self.debsrc)]
-
- for setting in usettings:
- if not self.rawurl:
- setting['baseurl'] = self.url
- else:
- setting['baseurl'] = self.rawurl
- setting['url'] = baseurl % setting
- setting['name'] = self.get_repo_name(setting)
- self.url_map.extend(usettings)
-
@property
def cachekey(self):
""" A unique key for this source that will be used to generate
diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py
index 6139a28b5..ae8ac5d6f 100644
--- a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py
+++ b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py
@@ -1028,8 +1028,9 @@ class YumSource(Source):
#: YumSource sets the ``type`` on Package entries to "yum"
ptype = 'yum'
- def __init__(self, basepath, xsource, setup):
- Source.__init__(self, basepath, xsource, setup)
+ def _init_attributes(self, basepath, xsource, setup):
+ Source._init_attributes(self, basepath, xsource, setup)
+
self.pulp_id = None
if HAS_PULP and xsource.get("pulp_id"):
self.pulp_id = xsource.get("pulp_id")
@@ -1071,7 +1072,7 @@ class YumSource(Source):
self.needed_paths = set()
self.file_to_arch = dict()
self.yumgroups = dict()
- __init__.__doc__ = Source.__init__.__doc__
+ _init_attributes.__doc__ = Source._init_attributes.__doc__
@property
def use_yum(self):