diff options
| author | Stuart Bishop <stuart.bishop@canonical.com> | 2016-07-14 10:44:48 (GMT) |
|---|---|---|
| committer | Stuart Bishop <stuart.bishop@canonical.com> | 2016-07-14 10:44:48 (GMT) |
| commit | 625d18edfbba37210adf9e0f198b7be4bbd7e1d8 (patch) | |
| tree | 6273afa448ad3187d0488b9faa9628b7c112870b | |
| parent | 9ce740a1e535540cd2a75b5f68963e5394d06855 (diff) | |
Unset installed state for manually removed packages
| -rw-r--r-- | reactive/apt.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/reactive/apt.py b/reactive/apt.py index 5cf7305..57097b7 100644 --- a/reactive/apt.py +++ b/reactive/apt.py @@ -23,6 +23,7 @@ once the apt.installed.{packagename} state is set. ''' from charmhelpers import fetch from charmhelpers.core import hookenv +from charmhelpers.core.hookenv import WARNING from charms import layer from charms import reactive from charms.reactive import when, when_not @@ -52,6 +53,17 @@ def ensure_package_status(): charms.apt.ensure_package_status() +def clear_removed_package_states(): + """On hook startup, clear install states for removed packages.""" + removed = fetch.filter_installed_packages(charms.apt.installed()) + if removed: + hookenv.log('{} missing packages ({})'.format(len(removed), + ','.join(removed)), + WARNING) + for package in removed: + reactive.remove_state('apt.installed.{}'.format(package)) + + def configure_sources(): """Add user specified package sources from the service configuration. @@ -81,7 +93,7 @@ def configure_sources(): extra_packages = sorted(config.get('extra_packages', '').split()) if extra_packages: - queue_install(extra_packages) + charms.apt.queue_install(extra_packages) def queue_layer_packages(): @@ -93,7 +105,7 @@ def queue_layer_packages(): opts = layer.options() for section in ['basic', 'apt']: if section in opts and 'packages' in opts[section]: - queue_install(opts[section]['packages']) + charms.apt.queue_install(opts[section]['packages']) # Per https://github.com/juju-solutions/charms.reactive/issues/33, @@ -107,6 +119,7 @@ if not hasattr(reactive, '_apt_registered'): # do this, then the config in the hook environment may show updates # to running hooks well before the config-changed hook has been invoked # and the intialization provided an opertunity to be run. + hookenv.atstart(clear_removed_package_states) hookenv.atstart(configure_sources) hookenv.atstart(queue_layer_packages) reactive._apt_registered = True |
