Merge ~yoshikadokawa/charm-prometheus-openstack-exporter:lp1936375 into charm-prometheus-openstack-exporter:master

Proposed by Yoshi Kadokawa
Status: Merged
Approved by: Xav Paice
Approved revision: 274236ff64e5d01a2a347d2c08cc2fe0ced8d7d4
Merged at revision: 2495a1833a10aadb0eb91128140d8d2216c9bc73
Proposed branch: ~yoshikadokawa/charm-prometheus-openstack-exporter:lp1936375
Merge into: charm-prometheus-openstack-exporter:master
Diff against target: 45 lines (+4/-5)
2 files modified
src/reactive/openstack_exporter.py (+1/-2)
src/tests/unit/test_reactive_openstack_exporter.py (+3/-3)
Reviewer Review Type Date Requested Status
Xav Paice (community) Approve
Paul Goins Approve
James Troup (community) Needs Information
Review via email: mp+407684@code.launchpad.net

Commit message

use snap layer's library to refresh channel

snap layer's install function also consider's if snap resources are attached, which is necessary in an offline environment.

LP: #1936375

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
James Troup (elmo) wrote :

I'm not going to lie, this feels like a bug in the snap layer? I'm OK with this as a workaround if it unblocks you, but is there a bug for the snap layer?

review: Needs Information
Revision history for this message
Yoshi Kadokawa (yoshikadokawa) wrote :

> I'm not going to lie, this feels like a bug in the snap layer? I'm OK with
> this as a workaround if it unblocks you, but is there a bug for the snap
> layer?

I believe you are saying that this is a charmhelpers bug since snap_refresh() function comes from charmhelpers library. Therefore, my MR is replacing the charmhelpers function with the one from snap-layer.
And indeed, I agree that this is a charmhelpers bug, I have just raised a bug for this one.
https://bugs.launchpad.net/charm-helpers/+bug/1941711

However, since most of the recent charms are created with reactive framework, and this prometheus-openstack-exporter is a reactive charm as well, so using snap-layer would be better I believe.

Revision history for this message
Paul Goins (vultaire) wrote :

This is a +1 from me.

Indeed, the charmhelpers.fetch.snap module appears to really be a somewhat thin shim around the snap CLI; I can't find any references to resources in that module.

The snap layer's install function is more appropriate here.

review: Approve
Revision history for this message
Xav Paice (xavpaice) wrote :

LGTM

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 2495a1833a10aadb0eb91128140d8d2216c9bc73

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/reactive/openstack_exporter.py b/src/reactive/openstack_exporter.py
2index 9d8cdb3..6f330ec 100644
3--- a/src/reactive/openstack_exporter.py
4+++ b/src/reactive/openstack_exporter.py
5@@ -22,7 +22,6 @@ import os
6 from charmhelpers.contrib.charmsupport import nrpe
7 from charmhelpers.core import hookenv, host, unitdata
8 from charmhelpers.core.templating import render
9-from charmhelpers.fetch.snap import snap_refresh
10
11 from charms.layer import snap
12 from charms.reactive import (
13@@ -89,7 +88,7 @@ def snap_channel_changed():
14 hookenv.status_set("maintenance", "Snap channel changed")
15 config = hookenv.config()
16 channel = config.get("snap_channel", "stable")
17- snap_refresh(SNAP_NAME, "--channel", channel)
18+ snap.install(SNAP_NAME, channel=channel, force_dangerous=False)
19 hookenv.status_set("active", "Snap refreshed")
20
21
22diff --git a/src/tests/unit/test_reactive_openstack_exporter.py b/src/tests/unit/test_reactive_openstack_exporter.py
23index 9f406e7..520a32d 100644
24--- a/src/tests/unit/test_reactive_openstack_exporter.py
25+++ b/src/tests/unit/test_reactive_openstack_exporter.py
26@@ -93,8 +93,8 @@ class TestOpenstackExporterContext(unittest.TestCase):
27 return openstack_exporter.config_paths(key)["target"]
28
29 def test_basic_config(self, _mock_hookenv_config, *args):
30- exp_cert = "fortytwo"
31- exp_cert64 = base64.encodestring(exp_cert.encode("utf-8")).decode()
32+ exp_cert = b"fortytwo"
33+ exp_cert64 = base64.encodebytes(exp_cert).decode()
34 config = self.def_config
35 config.update(
36 {
37@@ -140,7 +140,7 @@ class TestOpenstackExporterContext(unittest.TestCase):
38 act_keys = act_creds.keys()
39 self.assertSetEqual(set(exp_keys), set(act_keys))
40 cacert_file = self._config_file(openstack_exporter.CACERT)
41- self.assertEqual(exp_cert, open(cacert_file).read())
42+ self.assertEqual(exp_cert.decode(), open(cacert_file).read())
43
44 @mock.patch("reactive.openstack_exporter.host.service_running", return_value=True)
45 @mock.patch("reactive.openstack_exporter.host.service_restart")

Subscribers

People subscribed via source and target branches

to all changes: