livepatch-charmers team mailing list archive
-
livepatch-charmers team
-
Mailing list archive
-
Message #00096
[Merge] ~barryprice/canonical-livepatch-charm/+git/canonical-livepatch-charm:master into canonical-livepatch-charm:master
Barry Price has proposed merging ~barryprice/canonical-livepatch-charm/+git/canonical-livepatch-charm:master into canonical-livepatch-charm:master.
Commit message:
Use reactive triggers to handle proxy setting, avoid handling the reconfig/restart logic twice
Requested reviews:
Livepatch charm developers (livepatch-charmers)
For more details, see:
https://code.launchpad.net/~barryprice/canonical-livepatch-charm/+git/canonical-livepatch-charm/+merge/347668
--
Your team Livepatch charm developers is requested to review the proposed merge of ~barryprice/canonical-livepatch-charm/+git/canonical-livepatch-charm:master into canonical-livepatch-charm:master.
diff --git a/reactive/canonical_livepatch.py b/reactive/canonical_livepatch.py
index f71923d..46f96e0 100644
--- a/reactive/canonical_livepatch.py
+++ b/reactive/canonical_livepatch.py
@@ -1,5 +1,6 @@
from charms import layer
-from charms.reactive import when, when_not, set_state, remove_state
+from charms.reactive import when, when_not, set_state, remove_state, set_flag, clear_flag
+from charms.reactive.flags import register_trigger
from charmhelpers.core.host import write_file, is_container
from charmhelpers.core import hookenv
from charmhelpers.contrib.charmsupport import nrpe
@@ -171,6 +172,7 @@ def activate_livepatch():
unit_update('blocked', 'Activation failed')
else:
set_state('canonical-livepatch.active')
+ clear_flag('canonical-livepatch.restart-needed')
unit_update()
else:
hookenv.log('Unable to activate canonical-livepatch as no key has been set', hookenv.ERROR)
@@ -178,6 +180,9 @@ def activate_livepatch():
unit_update('blocked', 'Service disabled, please set livepatch_key to activate')
+register_trigger(when='config.changed.livepatch_proxy', clear_flag='livepatch-proxy.configured')
+
+
@when_not('snap.installed.canonical-livepatch')
def livepatch_supported():
arch = uname()[4]
@@ -191,7 +196,19 @@ def livepatch_supported():
unit_update('blocked', 'Livepatch is not needed in OS containers')
+@when_not('livepatch-proxy.configured')
+def proxy_configure():
+ # Configure proxies early, if required - LP#1761661
+ config = hookenv.config()
+ proxy_url = config.get('livepatch_proxy')
+ if proxy_url:
+ configure_proxies(http_proxy=proxy_url, https_proxy=proxy_url)
+ set_flag('livepatch-proxy.configured')
+ set_flag('canonical-livepatch.restart-needed')
+
+
@when('snap.installed.canonical-livepatch')
+@when('livepatch-proxy.configured')
@when_not('canonical-livepatch.connected')
def canonical_livepatch_connect():
# So if we've just installed snapd on a trusty system, we will not be on
@@ -207,11 +224,6 @@ def canonical_livepatch_connect():
unit_update('blocked', 'A reboot is required')
else:
unit_update('maintenance', 'Connecting to the livepatch service')
- # Configure proxies early, if required - LP#1761661
- config = hookenv.config()
- proxy_url = config.get('livepatch_proxy')
- if proxy_url:
- configure_proxies(http_proxy=proxy_url, https_proxy=proxy_url)
# Make sure the service is ready for us
wait_for_livepatch()
set_state('canonical-livepatch.connected')
@@ -233,12 +245,9 @@ def update_key():
activate_livepatch()
-@when('canonical-livepatch.connected', 'config.changed.livepatch_proxy')
-def update_livepatch_proxy():
- unit_update('maintenance', 'Configuring proxy servers')
- config = hookenv.config()
- proxy_url = config.get('livepatch_proxy')
- configure_proxies(http_proxy=proxy_url, https_proxy=proxy_url)
+@when('canonical-livepatch.connected', 'canonical-livepatch.restart-needed')
+def handle_restart():
+ unit_update('maintenance', 'Restarting client')
# restart the system service to pick up the new config
restart_livepatch()
References