← Back to team overview

livepatch-charmers team mailing list archive

[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:
For channel changes, use snap.refresh() instead of removing/reinstalling.

Also add channel change tests.

Requested reviews:
  Livepatch charm developers (livepatch-charmers)

For more details, see:
https://code.launchpad.net/~barryprice/canonical-livepatch-charm/+git/canonical-livepatch-charm/+merge/354942
-- 
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 91cb96e..03c1903 100644
--- a/reactive/canonical_livepatch.py
+++ b/reactive/canonical_livepatch.py
@@ -220,13 +220,13 @@ def update_key():
 
 @when('snap.installed.canonical-livepatch', 'config.changed.snap_channel')
 def change_channel():
-    # remove the snap entirely
-    # the other handlers will automatically reinstall it from the chosen channel
-    snap.remove('canonical-livepatch')
-    # force a reconnect given the channel change
-    clear_flag('canonical-livepatch.connected')
-    # and force the proxy routine to re-run (since we just removed that config)
-    clear_flag('livepatch-proxy.configured')
+    config = hookenv.config()
+    snap_channel = config.get('snap_channel')
+    # refresh to the given channel
+    snap.refresh(
+       'canonical-livepatch',
+       **{'channel': snap_channel, }
+    )
 
 
 @when('nrpe-external-master.available')
diff --git a/tests/99-autogen b/tests/99-autogen
index f4bb24e..f4b0af9 100755
--- a/tests/99-autogen
+++ b/tests/99-autogen
@@ -97,6 +97,41 @@ class TestDeployment(unittest.TestCase):
             '.cfg'.format(test_context_name))
         self.assertEqual(exit_code, 0)
 
+
+    def test_channel_change(self):
+        livepatch = self.deployment.sentry['canonical-livepatch'][0]
+
+        # verify the current channel
+        output, exit_code = livepatch.run('snap info canonical-livepatch')
+        self.assertEqual(exit_code, 0)
+
+        # confirm we're tracking 'stable'
+        channel = ''
+        for line in output.split('\n'):
+            if line.startswith('tracking:'):
+                channel = line.strip().split(' ')[-1]
+        self.assertEqual(channel, 'stable')
+
+        # change channel to 'beta'
+        self.deployment.configure('canonical-livepatch', {
+            'snap_channel': 'beta',
+        })
+
+        # wait for that to settle
+        sleep(30)
+
+        # verify the current channel
+        output, exit_code = livepatch.run('snap info canonical-livepatch')
+        self.assertEqual(exit_code, 0)
+
+        # confirm we're tracking 'beta'
+        channel = ''
+        for line in output.split('\n'):
+            if line.startswith('tracking:'):
+                channel = line.strip().split(' ')[-1]
+        self.assertEqual(channel, 'beta')
+
+
     def test_nagios_servicegroup_change(self):
         livepatch = self.deployment.sentry['canonical-livepatch'][0]
 

References