Make all of the packager method signatures consistent by moving the loops for pre_install and post_install into the component method where the packager is invoked.

Have the component get a packager for each package and use that, falling back to a default provided by the distro. This will allow us to override the packaging rules for specific packages by providing a class reference in the distro file.
This commit is contained in:
Doug Hellmann 2012-03-22 16:49:40 -04:00
parent eb68327cbb
commit 679f33b242
5 changed files with 43 additions and 30 deletions

View File

@ -19,6 +19,7 @@ import weakref
from devstack import cfg_helpers from devstack import cfg_helpers
from devstack import downloader as down from devstack import downloader as down
from devstack import exceptions as excp from devstack import exceptions as excp
from devstack import importer
from devstack import log as logging from devstack import log as logging
from devstack import pip from devstack import pip
from devstack import settings from devstack import settings
@ -82,7 +83,6 @@ class ComponentBase(object):
# Parts of the global runner context that we use # Parts of the global runner context that we use
self.cfg = runner.cfg self.cfg = runner.cfg
self.pw_gen = runner.pw_gen self.pw_gen = runner.pw_gen
self.packager = runner.pkg_manager
self.distro = runner.distro self.distro = runner.distro
# Required component directories # Required component directories
@ -127,9 +127,23 @@ class ComponentBase(object):
return tr.TraceReader(tr.trace_fn(self.trace_dir, tr.IN_TRACE)).exists() return tr.TraceReader(tr.trace_fn(self.trace_dir, tr.IN_TRACE)).exists()
class PkgInstallComponent(ComponentBase): class PackageBasedComponentMixin(object):
def __init__(self):
self.default_packager = self.distro.get_default_package_manager()
def get_packager(self, pkg_info):
if 'packager' in pkg_info:
packager_name = pkg_info['packager']
packager = importer.import_entry_point(packager_name)(self.distro)
else:
packager = self.default_packager
return packager
class PkgInstallComponent(ComponentBase, PackageBasedComponentMixin):
def __init__(self, *args, **kargs): def __init__(self, *args, **kargs):
ComponentBase.__init__(self, *args, **kargs) ComponentBase.__init__(self, *args, **kargs)
PackageBasedComponentMixin.__init__(self)
self.tracewriter = tr.TraceWriter(tr.trace_fn(self.trace_dir, self.tracewriter = tr.TraceWriter(tr.trace_fn(self.trace_dir,
tr.IN_TRACE)) tr.IN_TRACE))
self.packages = kargs.get('packages', list()) self.packages = kargs.get('packages', list())
@ -200,7 +214,8 @@ class PkgInstallComponent(ComponentBase):
with utils.progress_bar(INSTALL_TITLE, len(pkgs)) as p_bar: with utils.progress_bar(INSTALL_TITLE, len(pkgs)) as p_bar:
for (i, p) in enumerate(pkgs): for (i, p) in enumerate(pkgs):
self.tracewriter.package_installed(p) self.tracewriter.package_installed(p)
self.packager.install(p) packager = self.get_packager(p)
packager.install(p)
p_bar.update(i + 1) p_bar.update(i + 1)
else: else:
LOG.info('No packages to install for %s', LOG.info('No packages to install for %s',
@ -211,13 +226,17 @@ class PkgInstallComponent(ComponentBase):
pkgs = self._get_packages() pkgs = self._get_packages()
if pkgs: if pkgs:
mp = self._get_param_map(None) mp = self._get_param_map(None)
self.packager.pre_install(pkgs, mp) for p in pkgs:
packager = self.get_packager(p)
packager.pre_install(p, mp)
def post_install(self): def post_install(self):
pkgs = self._get_packages() pkgs = self._get_packages()
if pkgs: if pkgs:
mp = self._get_param_map(None) mp = self._get_param_map(None)
self.packager.post_install(pkgs, mp) for p in pkgs:
packager = self.get_packager(p)
packager.post_install(p, mp)
def _get_config_files(self): def _get_config_files(self):
return list() return list()
@ -347,9 +366,10 @@ class PythonInstallComponent(PkgInstallComponent):
return trace_dir return trace_dir
class PkgUninstallComponent(ComponentBase): class PkgUninstallComponent(ComponentBase, PackageBasedComponentMixin):
def __init__(self, *args, **kargs): def __init__(self, *args, **kargs):
ComponentBase.__init__(self, *args, **kargs) ComponentBase.__init__(self, *args, **kargs)
PackageBasedComponentMixin.__init__(self)
self.tracereader = tr.TraceReader(tr.trace_fn(self.trace_dir, self.tracereader = tr.TraceReader(tr.trace_fn(self.trace_dir,
tr.IN_TRACE)) tr.IN_TRACE))
self.keep_old = kargs.get('keep_old') self.keep_old = kargs.get('keep_old')
@ -409,7 +429,8 @@ class PkgUninstallComponent(ComponentBase):
which_removed = set() which_removed = set()
with utils.progress_bar(UNINSTALL_TITLE, len(pkgs), reverse=True) as p_bar: with utils.progress_bar(UNINSTALL_TITLE, len(pkgs), reverse=True) as p_bar:
for (i, p) in enumerate(pkgs): for (i, p) in enumerate(pkgs):
if self.packager.remove(p): packager = self.get_packager(p)
if packager.remove(p):
which_removed.add(p['name']) which_removed.add(p['name'])
p_bar.update(i + 1) p_bar.update(i + 1)
LOG.info("Actually removed %s packages (%s)", LOG.info("Actually removed %s packages (%s)",

View File

@ -128,9 +128,9 @@ class Distro(object):
""" """
return bool(self._distro_pattern.search(distro_name)) return bool(self._distro_pattern.search(distro_name))
def get_packager_factory(self): def get_default_package_manager(self):
"""Return a factory for a package manager.""" """Return a package manager that will work for this distro."""
return importer.import_entry_point(self._packager_name) return importer.import_entry_point(self._packager_name)(self)
def extract_component(self, name, action): def extract_component(self, name, action):
"""Return the class + component info to use for doing the action w/the component.""" """Return the class + component info to use for doing the action w/the component."""

View File

@ -44,18 +44,16 @@ class Packager(object):
return False return False
return self._remove(pkg) return self._remove(pkg)
def pre_install(self, pkgs, params=None): def pre_install(self, pkg, params=None):
for info in pkgs: cmds = pkg.get('pre-install')
cmds = info.get('pre-install') if cmds:
if cmds: LOG.info("Running pre-install commands for package %s.",
LOG.info("Running pre-install commands for package %s.", pkg['name'])
info['name']) utils.execute_template(*cmds, params=params)
utils.execute_template(*cmds, params=params)
def post_install(self, pkgs, params=None): def post_install(self, pkg, params=None):
for info in pkgs: cmds = pkg.get('post-install')
cmds = info.get('post-install') if cmds:
if cmds: LOG.info("Running post-install commands for package %s.",
LOG.info("Running post-install commands for package %s.", pkg['name'])
info['name']) utils.execute_template(*cmds, params=params)
utils.execute_template(*cmds, params=params)

View File

@ -35,12 +35,10 @@ class ActionRunner(object):
distro, distro,
cfg, cfg,
pw_gen, pw_gen,
pkg_manager,
**kargs): **kargs):
self.distro = distro self.distro = distro
self.cfg = cfg self.cfg = cfg
self.pw_gen = pw_gen self.pw_gen = pw_gen
self.pkg_manager = pkg_manager
self.keep_old = kargs.get('keep_old', False) self.keep_old = kargs.get('keep_old', False)
self.force = kargs.get('force', False) self.force = kargs.get('force', False)
@ -135,7 +133,6 @@ class ActionRunner(object):
prereq = self.PREREQ(self.distro, prereq = self.PREREQ(self.distro,
self.cfg, self.cfg,
self.pw_gen, self.pw_gen,
self.pkg_manager,
keep_old=self.keep_old, keep_old=self.keep_old,
force=self.force, force=self.force,
) )

3
stack
View File

@ -150,14 +150,11 @@ def run(args):
persona_inst = load_verify_persona(persona_fn, dist) persona_inst = load_verify_persona(persona_fn, dist)
config = cfg.get_config() config = cfg.get_config()
pw_gen = passwords.PasswordGenerator(config, args.get('prompt_for_passwords', True)) pw_gen = passwords.PasswordGenerator(config, args.get('prompt_for_passwords', True))
pkg_cls = dist.get_packager_factory()
pkg_manager = pkg_cls(dist)
runner_factory = actions.get_runner_factory(action) runner_factory = actions.get_runner_factory(action)
runner = runner_factory(dist, runner = runner_factory(dist,
config, config,
pw_gen, pw_gen,
pkg_manager,
**args) **args)
LOG.info("Starting action %r on %s for distro: %r" % (action, date.rcf8222date(), dist.name)) LOG.info("Starting action %r on %s for distro: %r" % (action, date.rcf8222date(), dist.name))