Merge ~jacekn/prometheus-snmp-exporter-charm/+git/prometheus-snmp-exporter-charm:master into prometheus-snmp-exporter-charm:master

Proposed by Jacek Nykis
Status: Merged
Merged at revision: 3df8ec0daaab908adc9c9a99d3d5b9a3f389a37b
Proposed branch: ~jacekn/prometheus-snmp-exporter-charm/+git/prometheus-snmp-exporter-charm:master
Merge into: prometheus-snmp-exporter-charm:master
Diff against target: 147 lines (+11/-63)
3 files modified
config.yaml (+0/-29)
layer.yaml (+1/-1)
reactive/prometheus-snmp-exporter.py (+10/-33)
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+307035@code.launchpad.net

Description of the change

Switch snap support to snap layer. Remove deb package support

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Looks fine.

Do you want to declare the Juju resource in metadata.yaml, so people can upload the snap as a resource for deployments without network connectivity?

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/config.yaml b/config.yaml
2index c47092e..ed96956 100644
3--- a/config.yaml
4+++ b/config.yaml
5@@ -1,39 +1,10 @@
6 options:
7- install_method:
8- default: "snap"
9- type: string
10- description: >
11- How to install prometheus-snmp-exporter package. If set to "apt"
12- the package will be installed using apt-get.
13- If set to "snap", empty string or unset snap package will be installed
14 snap_channel:
15 default: "stable"
16 type: string
17 description: |
18 If install_method is set to "snap" this option controlls channel name.
19 Supported values are: "stable", "candidate", "beta" and "edge"
20- install_sources:
21- default: '[ "ppa:canonical-bootstack/prometheus" ]'
22- type: string
23- description: |
24- YAML list of additional installation sources, as a string. The number of
25- install_sources must match the number of install_keys. For example:
26- install_sources: |
27- - ppa:project1/ppa
28- - ppa:project2/ppa
29- install_keys:
30- default: '[ "" ]'
31- type: string
32- description: |
33- YAML list of GPG keys for installation sources, as a string. For apt repository
34- URLs, use the public key ID used to verify package signatures. For
35- other sources such as PPA, use empty string. This list must have the
36- same number of elements as install_sources, even if the key items are
37- all empty string. An example to go with the above for install_sources:
38- install_keys: |
39- - "ABC"
40- - ""
41-
42 snmp_community:
43 default: "public"
44 type: string
45diff --git a/layer.yaml b/layer.yaml
46index 16a7bcf..c0bb288 100644
47--- a/layer.yaml
48+++ b/layer.yaml
49@@ -1,4 +1,4 @@
50-includes: ['layer:basic', 'interface:http']
51+includes: ['layer:basic', 'interface:http', 'layer:snap']
52 ignore: ['.*.swp' ]
53 options:
54 basic:
55diff --git a/reactive/prometheus-snmp-exporter.py b/reactive/prometheus-snmp-exporter.py
56index 36788fb..aad2631 100644
57--- a/reactive/prometheus-snmp-exporter.py
58+++ b/reactive/prometheus-snmp-exporter.py
59@@ -1,18 +1,18 @@
60 import yaml
61-import subprocess
62
63-from charmhelpers import fetch
64 from charmhelpers.core import host, hookenv
65 from charmhelpers.core.templating import render
66 from charms.reactive import (
67 when, when_not, set_state, remove_state
68 )
69 from charms.reactive.helpers import any_file_changed, data_changed
70+from charms.layer import snap
71
72
73-PKGNAMES = ['prometheus-snmp-exporter']
74+SNAP_NAME = 'prometheus-snmp-exporter'
75 PORT_DEF = 9116
76 SNMP_EXPORTER_YML_TMPL = 'snmp.yaml.j2'
77+CONF_FILE_PATH = '/var/snap/prometheus-snmp-exporter/current/snmp.yml'
78
79
80 def templates_changed(tmpl_list):
81@@ -21,21 +21,12 @@ def templates_changed(tmpl_list):
82
83 @when_not('snmp-exporter.installed')
84 def install_packages():
85- fetch.configure_sources()
86+ hookenv.status_set('maintenance', 'Installing software')
87 config = hookenv.config()
88- source = config.get('install_method', 'snap')
89- channel = '--channel={}'.format(config.get('snap_channel', 'stable'))
90- if source == 'snap':
91- # Switch to check_call once LP1622782 is resolved
92- subprocess.call(['snap', 'install'] + PKGNAMES + [channel])
93- set_state('snmp-exporter.installed')
94- elif source == 'apt':
95- fetch.apt_update()
96- fetch.apt_install(PKGNAMES)
97- set_state('snmp-exporter.installed')
98- else:
99- hookenv.status_set('blocked',
100- 'Unsupported install_method: {}'.format(source))
101+ channel = config.get('snap_channel', 'stable')
102+ snap.install(SNAP_NAME, channel=channel, force_dangerous=False)
103+ set_state('snmp-exporter.installed')
104+ set_state('snmp-exporter.do-check-reconfig')
105
106
107 def validate_config(filename):
108@@ -46,27 +37,16 @@ def validate_config(filename):
109 @when('snmp-exporter.do-reconfig-yaml')
110 def write_snmp_exporter_config_yaml():
111 config = hookenv.config()
112- if config.get('install_method', 'snap') == 'snap':
113- config_file = '/var/snap/prometheus-snmp-exporter/current/snmp.yml'
114- else:
115- config_file = '/etc/prometheus/snmp.yaml'
116 render(source=SNMP_EXPORTER_YML_TMPL,
117- target=config_file,
118+ target=CONF_FILE_PATH,
119 context={'config': config}
120 )
121- validate_config(config_file)
122+ validate_config(CONF_FILE_PATH)
123 hookenv.open_port(PORT_DEF)
124 set_state('snmp-exporter.do-restart')
125 remove_state('snmp-exporter.do-reconfig-yaml')
126
127
128-@when_not('snmp-exporter.started')
129-def setup_snmp_exporter():
130- hookenv.status_set('maintenance', 'Installing software')
131- install_packages()
132- set_state('snmp-exporter.do-check-reconfig')
133-
134-
135 @when('snmp-exporter.started')
136 def check_config():
137 set_state('snmp-exporter.do-check-reconfig')
138@@ -75,9 +55,6 @@ def check_config():
139 @when('snmp-exporter.do-check-reconfig')
140 def check_reconfig_snmp_exporter():
141 config = hookenv.config()
142- install_opts = ('install_sources', 'install_keys', 'install_method')
143- if any(config.changed(opt) for opt in install_opts):
144- remove_state('snmp-exporter.installed')
145
146 if data_changed('snmp-exporter.config', config):
147 set_state('snmp-exporter.do-reconfig-yaml')

Subscribers

People subscribed via source and target branches