From f98c330f8ff3013d1e3b2d5708477b1e33cebfda Mon Sep 17 00:00:00 2001 From: Gunther Hagleitner Date: Fri, 27 Jan 2012 17:42:56 -0800 Subject: [PATCH] don't install packages if you don't want to (--keep_packages) --- devstack/opts.py | 5 +++++ devstack/packager.py | 10 ++++++++-- devstack/packaging/apt.py | 6 +++--- devstack/packaging/yum.py | 4 ++-- devstack/progs/actions.py | 6 +++--- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/devstack/opts.py b/devstack/opts.py index be9dbaad..9292d8c9 100644 --- a/devstack/opts.py +++ b/devstack/opts.py @@ -69,6 +69,10 @@ def parse(): dest="r_component", metavar="COMPONENT", help="component which will not have ACTION applied but will be referenced as if it was (ACTION dependent)") + base_group.add_option("-k", "--keep-packages", + action="store_true", + dest="keep_packages", + help="uninstall will keep any installed packages on the system") parser.add_option_group(base_group) stop_un_group = OptionGroup(parser, "Uninstall/stop options") @@ -107,5 +111,6 @@ def parse(): output['ignore_deps'] = False else: output['ignore_deps'] = True + output['keep_packages'] = options.keep_packages output['extras'] = args return output diff --git a/devstack/packager.py b/devstack/packager.py index bfb9878b..f202a817 100644 --- a/devstack/packager.py +++ b/devstack/packager.py @@ -22,14 +22,17 @@ LOG = logging.getLogger("devstack.packager") class Packager(object): - def __init__(self, distro): + def __init__(self, distro, keep_packages): self.distro = distro + self.keep_packages = keep_packages def install_batch(self, pkgs): raise NotImplementedError() def remove_batch(self, pkgs): - raise NotImplementedError() + if not self.keep_packages: + return self._remove_batch(pkgs) + return [] def pre_install(self, pkgs, installparams=None): pkgnames = sorted(pkgs.keys()) @@ -48,3 +51,6 @@ class Packager(object): if postinstallcmds and len(postinstallcmds): LOG.info("Running post-install commands for package %s." % (name)) utils.execute_template(*postinstallcmds, params=installparams) + + def _remove_batch(self, pkgs): + raise NotImplementedError() diff --git a/devstack/packaging/apt.py b/devstack/packaging/apt.py index bc4211fc..8c31a634 100644 --- a/devstack/packaging/apt.py +++ b/devstack/packaging/apt.py @@ -42,8 +42,8 @@ VERSION_TEMPL = "%s=%s" class AptPackager(pack.Packager): - def __init__(self, distro): - pack.Packager.__init__(self, distro) + def __init__(self, distro, keep_packages): + pack.Packager.__init__(self, distro, keep_packages) self.auto_remove = True def _format_pkg(self, name, version): @@ -59,7 +59,7 @@ class AptPackager(pack.Packager): env_overrides=ENV_ADDITIONS, **kargs) - def remove_batch(self, pkgs): + def _remove_batch(self, pkgs): pkgnames = sorted(pkgs.keys()) #form the needed commands cmds = [] diff --git a/devstack/packaging/yum.py b/devstack/packaging/yum.py index b572c949..9aef20d7 100644 --- a/devstack/packaging/yum.py +++ b/devstack/packaging/yum.py @@ -32,8 +32,8 @@ VERSION_TEMPL = "%s-%s" class YumPackager(pack.Packager): - def __init__(self, distro): - pack.Packager.__init__(self, distro) + def __init__(self, distro, keep_packages): + pack.Packager.__init__(self, distro, keep_packages) def _format_pkg_name(self, name, version): if version is not None and len(version): diff --git a/devstack/progs/actions.py b/devstack/progs/actions.py index 501c2292..50a4abef 100644 --- a/devstack/progs/actions.py +++ b/devstack/progs/actions.py @@ -135,9 +135,9 @@ def _clean_action(action): return action -def _get_pkg_manager(distro): +def _get_pkg_manager(distro, keep_packages): cls = _PKGR_MAP.get(distro) - return cls(distro) + return cls(distro, keep_packages) def _get_action_cls(action_name, component_name): @@ -286,7 +286,7 @@ def _run_components(action_name, component_order, components, distro, root_dir, non_components = set(components.keys()).difference(set(component_order)) if non_components: LOG.info("Using reference components [%s]" % (", ".join(sorted(non_components)))) - pkg_manager = _get_pkg_manager(distro) + pkg_manager = _get_pkg_manager(distro, program_args.pop('keep_packages', True)) config = _get_config() #form the active instances (this includes ones we won't use) all_instances = dict()