diff --git a/devstack/component.py b/devstack/component.py index 398d5b90..fc2eb746 100644 --- a/devstack/component.py +++ b/devstack/component.py @@ -19,6 +19,7 @@ import weakref from devstack import cfg_helpers from devstack import downloader as down from devstack import exceptions as excp +from devstack import importer from devstack import log as logging from devstack import pip from devstack import settings @@ -82,7 +83,6 @@ class ComponentBase(object): # Parts of the global runner context that we use self.cfg = runner.cfg self.pw_gen = runner.pw_gen - self.packager = runner.pkg_manager self.distro = runner.distro # Required component directories @@ -127,9 +127,23 @@ class ComponentBase(object): 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): ComponentBase.__init__(self, *args, **kargs) + PackageBasedComponentMixin.__init__(self) self.tracewriter = tr.TraceWriter(tr.trace_fn(self.trace_dir, tr.IN_TRACE)) self.packages = kargs.get('packages', list()) @@ -200,7 +214,8 @@ class PkgInstallComponent(ComponentBase): with utils.progress_bar(INSTALL_TITLE, len(pkgs)) as p_bar: for (i, p) in enumerate(pkgs): self.tracewriter.package_installed(p) - self.packager.install(p) + packager = self.get_packager(p) + packager.install(p) p_bar.update(i + 1) else: LOG.info('No packages to install for %s', @@ -211,13 +226,17 @@ class PkgInstallComponent(ComponentBase): pkgs = self._get_packages() if pkgs: 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): pkgs = self._get_packages() if pkgs: 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): return list() @@ -347,9 +366,10 @@ class PythonInstallComponent(PkgInstallComponent): return trace_dir -class PkgUninstallComponent(ComponentBase): +class PkgUninstallComponent(ComponentBase, PackageBasedComponentMixin): def __init__(self, *args, **kargs): ComponentBase.__init__(self, *args, **kargs) + PackageBasedComponentMixin.__init__(self) self.tracereader = tr.TraceReader(tr.trace_fn(self.trace_dir, tr.IN_TRACE)) self.keep_old = kargs.get('keep_old') @@ -409,7 +429,8 @@ class PkgUninstallComponent(ComponentBase): which_removed = set() with utils.progress_bar(UNINSTALL_TITLE, len(pkgs), reverse=True) as p_bar: 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']) p_bar.update(i + 1) LOG.info("Actually removed %s packages (%s)", diff --git a/devstack/distro.py b/devstack/distro.py index 97e0c1b0..46cdafd3 100644 --- a/devstack/distro.py +++ b/devstack/distro.py @@ -128,9 +128,9 @@ class Distro(object): """ return bool(self._distro_pattern.search(distro_name)) - def get_packager_factory(self): - """Return a factory for a package manager.""" - return importer.import_entry_point(self._packager_name) + def get_default_package_manager(self): + """Return a package manager that will work for this distro.""" + return importer.import_entry_point(self._packager_name)(self) def extract_component(self, name, action): """Return the class + component info to use for doing the action w/the component.""" diff --git a/devstack/packager.py b/devstack/packager.py index 2e2f4d7d..862c1e63 100644 --- a/devstack/packager.py +++ b/devstack/packager.py @@ -44,18 +44,16 @@ class Packager(object): return False return self._remove(pkg) - def pre_install(self, pkgs, params=None): - for info in pkgs: - cmds = info.get('pre-install') - if cmds: - LOG.info("Running pre-install commands for package %s.", - info['name']) - utils.execute_template(*cmds, params=params) + def pre_install(self, pkg, params=None): + cmds = pkg.get('pre-install') + if cmds: + LOG.info("Running pre-install commands for package %s.", + pkg['name']) + utils.execute_template(*cmds, params=params) - def post_install(self, pkgs, params=None): - for info in pkgs: - cmds = info.get('post-install') - if cmds: - LOG.info("Running post-install commands for package %s.", - info['name']) - utils.execute_template(*cmds, params=params) + def post_install(self, pkg, params=None): + cmds = pkg.get('post-install') + if cmds: + LOG.info("Running post-install commands for package %s.", + pkg['name']) + utils.execute_template(*cmds, params=params) diff --git a/devstack/progs/actions.py b/devstack/progs/actions.py index 758adf49..186acd20 100644 --- a/devstack/progs/actions.py +++ b/devstack/progs/actions.py @@ -35,12 +35,10 @@ class ActionRunner(object): distro, cfg, pw_gen, - pkg_manager, **kargs): self.distro = distro self.cfg = cfg self.pw_gen = pw_gen - self.pkg_manager = pkg_manager self.keep_old = kargs.get('keep_old', False) self.force = kargs.get('force', False) @@ -135,7 +133,6 @@ class ActionRunner(object): prereq = self.PREREQ(self.distro, self.cfg, self.pw_gen, - self.pkg_manager, keep_old=self.keep_old, force=self.force, ) diff --git a/stack b/stack index f7d6a9de..d6d8a27e 100755 --- a/stack +++ b/stack @@ -150,14 +150,11 @@ def run(args): persona_inst = load_verify_persona(persona_fn, dist) config = cfg.get_config() 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 = runner_factory(dist, config, pw_gen, - pkg_manager, **args) LOG.info("Starting action %r on %s for distro: %r" % (action, date.rcf8222date(), dist.name))