nagios-charmers team mailing list archive
-
nagios-charmers team
-
Mailing list archive
-
Message #00695
[Merge] ~freyes/thruk-agent-charm:lp1829681 into thruk-agent-charm:master
Felipe Reyes has proposed merging ~freyes/thruk-agent-charm:lp1829681 into thruk-agent-charm:master.
Commit message:
Use add-apt-repository only when needed
Requested reviews:
Canonical IS Reviewers (canonical-is-reviewers)
Nagios Charm developers (nagios-charmers)
For more details, see:
https://code.launchpad.net/~freyes/thruk-agent-charm/+git/thruk-agent-charm/+merge/376486
--
Your team Nagios Charm developers is requested to review the proposed merge of ~freyes/thruk-agent-charm:lp1829681 into thruk-agent-charm:master.
diff --git a/hooks/actions.py b/hooks/actions.py
index 1593b51..0323ae3 100644
--- a/hooks/actions.py
+++ b/hooks/actions.py
@@ -9,10 +9,13 @@ import hashlib
# import thruk_helpers
from charmhelpers.fetch import (
- apt_install, apt_update, add_source
+ apt_install, apt_update, add_source,
+ filter_installed_packages
)
+PACKAGE_LIST = ["thruk", "pwgen", "apache2-utils"]
+
def log_start(service_name):
hookenv.log('thruk-agent starting')
@@ -91,15 +94,22 @@ def update_ppa(service_name):
config = hookenv.config()
new_source = config.get('source')
prev_source = config.previous('source')
+
+ new_key = config.get('key')
+ prev_key = config.previous('key')
+
if prev_source is not None and prev_source != new_source:
subprocess.check_call(['add-apt-repository',
'--yes', '--remove', prev_source],
env=hookenv.env_proxy_settings(['https']))
- add_source(config.get('source'), config.get('key', None))
- apt_update(fatal=True)
- package_list = ["thruk", "pwgen", "apache2-utils"]
- apt_install(packages=package_list, fatal=True)
+ if prev_source != new_source or prev_key != new_key:
+ add_source(config.get('source'), config.get('key', None))
+ apt_update(fatal=True)
+
+ pkgs_to_install = filter_installed_packages(PACKAGE_LIST)
+ if pkgs_to_install:
+ apt_install(packages=pkgs_to_install, fatal=True)
def update_status(service_name):
- hookenv.status_set('active', 'ready')
+ hookenv.status_set('active', 'ready')
References