Merge lp:~paulgear/charms/trusty/ntp/sync-canonical-is-charms into lp:charms/trusty/ntp

Proposed by Paul Gear
Status: Merged
Merged at revision: 25
Proposed branch: lp:~paulgear/charms/trusty/ntp/sync-canonical-is-charms
Merge into: lp:charms/trusty/ntp
Diff against target: 179 lines (+62/-38)
3 files modified
config.yaml (+6/-5)
hooks/ntp_hooks.py (+53/-30)
templates/ntp.conf (+3/-3)
To merge this branch: bzr merge lp:~paulgear/charms/trusty/ntp/sync-canonical-is-charms
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review Queue (community) automated testing Needs Fixing
Review via email: mp+276951@code.launchpad.net

Description of the change

This has the following features/fixes:

- The use_iburst and auto_peers config options are now true by default. In environments which perform outbound UDP rate-limiting, it is recommended to change this to false.

- If all Nagios checks are enabled, they are merged into a single check, reducing noise and increasing efficiency.

- Should fix https://bugs.launchpad.net/charms/+source/ntp/+bug/1480564 due to consolidated handling of peers & sources in hook code.

This eliminates the differences in canonical-is-charms and will allow us to use the trunk charm.

To post a comment you must log in.
Revision history for this message
Review Queue (review-queue) wrote :

This item has failed automated testing! Results available here http://juju-ci.vapour.ws:8080/job/charm-bundle-test-lxc/1392/

review: Needs Fixing (automated testing)
29. By Paul Gear

Run of make lint with vanilla flake8 config

Revision history for this message
Review Queue (review-queue) wrote :

This item has failed automated testing! Results available here http://juju-ci.vapour.ws:8080/job/charm-bundle-test-lxc/1448/

review: Needs Fixing (automated testing)
Revision history for this message
Review Queue (review-queue) wrote :

This item has failed automated testing! Results available here http://juju-ci.vapour.ws:8080/job/charm-bundle-test-aws/1433/

review: Needs Fixing (automated testing)
Revision history for this message
Stuart Bishop (stub) wrote :

This all looks good and makes sense.

The test suite is all green at http://reports.vapour.ws/all-bundle-and-charm-results/ntp

Will land.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2015-03-27 07:09:38 +0000
3+++ config.yaml 2015-11-16 04:00:52 +0000
4@@ -17,7 +17,7 @@
5 juju-myservice-0
6 If you're running multiple environments with the same services in them
7 this allows you to differentiate between them.
8- nagios_servicegroups:
9+ nagios_servicegroups:
10 default: ""
11 type: string
12 description: |
13@@ -27,13 +27,14 @@
14 default: "offset peers reachability sync"
15 type: string
16 description: |
17- A space-seperated list of nagios ntpmon checks to enable.
18- If left empty, no ntpmon checks will be used.
19+ A space-separated list of nagios ntpmon checks to enable.
20+ Options are "offset peers reachability sync"; if all are specified,
21+ they are combined into a single check; leave empty for no checks.
22 auto_peers:
23- default: false
24+ default: true
25 type: boolean
26 description: Will ntp auto peer between the environment
27 use_iburst:
28- default: false
29+ default: true
30 type: boolean
31 description: Use iburst for all servers, not just ntpmaster
32
33=== modified file 'hooks/ntp_hooks.py'
34--- hooks/ntp_hooks.py 2015-08-31 01:39:26 +0000
35+++ hooks/ntp_hooks.py 2015-11-16 04:00:52 +0000
36@@ -37,6 +37,22 @@
37 shutil.copy(NTP_CONF, NTP_CONF_ORIG)
38
39
40+def get_sources(sources, iburst=True, source_list=None):
41+ if source_list is None:
42+ source_list = []
43+ if sources:
44+ # allow both strings and lists
45+ if isinstance(sources, basestring):
46+ sources = sources.split(" ")
47+ for s in sources:
48+ if len(s) > 0:
49+ if iburst:
50+ source_list.append({'name': s, 'iburst': 'iburst'})
51+ else:
52+ source_list.append({'name': s, 'iburst': ''})
53+ return source_list
54+
55+
56 @hooks.hook('upgrade-charm')
57 @hooks.hook('config-changed')
58 @hooks.hook('master-relation-changed')
59@@ -47,40 +63,30 @@
60 def write_config():
61 use_iburst = hookenv.config('use_iburst')
62 source = hookenv.config('source')
63- remote_sources = []
64- if source:
65- for s in source.split(" "):
66- if len(s) > 0:
67- if use_iburst:
68- remote_sources.append({'name': '%s iburst' % s})
69- else:
70- remote_sources.append({'name': s})
71+ remote_sources = get_sources(source, iburst=use_iburst)
72 for relid in hookenv.relation_ids('master'):
73 for unit in hookenv.related_units(relid=relid):
74 u_addr = hookenv.relation_get(attribute='private-address',
75 unit=unit, rid=relid)
76- remote_sources.append({'name': '%s iburst' % u_addr})
77+ remote_sources.append({'name': u_addr, 'iburst': 'iburst'})
78
79+ peers = hookenv.config('peers')
80+ remote_peers = get_sources(peers, iburst=use_iburst)
81 auto_peers = hookenv.config('auto_peers')
82- peers = hookenv.config('peers')
83- remote_peers = []
84- if peers:
85- for p in peers.split(" "):
86- if len(p) > 0:
87- remote_peers.append(p)
88- if hookenv.relation_ids('ntp-peers'):
89- if auto_peers:
90- for rp in get_peer_nodes():
91- remote_peers.append(rp)
92+ if hookenv.relation_ids('ntp-peers') and auto_peers:
93+ remote_peers = get_sources(get_peer_nodes(), iburst=use_iburst,
94+ source_list=remote_peers)
95
96- if len(remote_sources) == 0:
97+ if len(remote_sources) == 0 and len(remote_peers) == 0:
98+ # we have no peers/servers; restore default ntp.conf provided by OS
99 shutil.copy(NTP_CONF_ORIG, NTP_CONF)
100 else:
101+ # otherwise, write our own configuration
102 with open(NTP_CONF, "w") as ntpconf:
103 ntpconf.write(render(os.path.basename(NTP_CONF),
104 {'servers': remote_sources,
105 'peers': remote_peers,
106- 'use_iburst': use_iburst}))
107+ }))
108
109 if hookenv.relation_ids('nrpe-external-master'):
110 update_nrpe_config()
111@@ -92,23 +98,40 @@
112 # python-dbus is used by check_upstart_job
113 # python-psutil is used by check_ntpmon
114 fetch.apt_install(['python-dbus', 'python-psutil'])
115- nagios_ntpmon_checks = hookenv.config('nagios_ntpmon_checks')
116+ nagios_ntpmon_checks = hookenv.config('nagios_ntpmon_checks').split(" ")
117 if os.path.isdir(NAGIOS_PLUGINS):
118- if nagios_ntpmon_checks:
119- host.rsync(os.path.join(os.getenv('CHARM_DIR'), 'files', 'nagios',
120- 'check_ntpmon.py'),
121- os.path.join(NAGIOS_PLUGINS, 'check_ntpmon.py'))
122+ host.rsync(os.path.join(os.getenv('CHARM_DIR'), 'files', 'nagios',
123+ 'check_ntpmon.py'),
124+ os.path.join(NAGIOS_PLUGINS, 'check_ntpmon.py'))
125
126 hostname = nrpe.get_nagios_hostname()
127 current_unit = nrpe.get_nagios_unit_name()
128 nrpe_setup = nrpe.NRPE(hostname=hostname)
129 nrpe.add_init_service_checks(nrpe_setup, ['ntp'], current_unit)
130- for nc in nagios_ntpmon_checks.split(" "):
131+
132+ allchecks = set(['offset', 'peers', 'reachability', 'sync'])
133+
134+ # remove any previously-created ntpmon checks
135+ nrpe_setup.remove_check(shortname="ntpmon")
136+ for c in allchecks:
137+ nrpe_setup.remove_check(shortname="ntpmon_%s" % c)
138+
139+ # If all checks are specified, combine them into a single check to reduce
140+ # Nagios noise.
141+ if set(nagios_ntpmon_checks) == allchecks:
142 nrpe_setup.add_check(
143- shortname="ntpmon_%s" % nc,
144- description='Check NTPmon %s {%s}' % (nc, current_unit),
145- check_cmd='check_ntpmon.py --check %s' % nc
146+ shortname="ntpmon",
147+ description='Check NTPmon {}'.format(current_unit),
148+ check_cmd='check_ntpmon.py'
149 )
150+ else:
151+ for nc in nagios_ntpmon_checks:
152+ if len(nc) > 0:
153+ nrpe_setup.add_check(
154+ shortname="ntpmon_%s" % nc,
155+ description='Check NTPmon %s {%s}' % (nc, current_unit),
156+ check_cmd='check_ntpmon.py --check %s' % nc
157+ )
158
159 nrpe_setup.write()
160
161
162=== modified file 'templates/ntp.conf'
163--- templates/ntp.conf 2015-03-16 07:16:25 +0000
164+++ templates/ntp.conf 2015-11-16 04:00:52 +0000
165@@ -8,11 +8,11 @@
166 restrict -6 default kod notrap nomodify nopeer noquery
167 restrict 127.0.0.1
168 restrict ::1
169-{% for peer in peers %}restrict {{ peer }} kod notrap nomodify
170+{% for peer in peers %}restrict {{ peer.name }} kod notrap nomodify
171 {% endfor %}
172 # SERVERS
173-{% for server in servers %}server {{ server.name }}
174+{% for server in servers %}server {{ server.name }} {{ server.iburst }}
175 {% endfor %}
176 # PEERS
177-{% for peer in peers %}peer {{ peer }} {% if use_iburst %}iburst{% endif %}
178+{% for peer in peers %}peer {{ peer.name }} {{ peer.iburst }}
179 {% endfor %}

Subscribers

People subscribed via source and target branches

to all changes: