Merge ~paulgear/ntp-charm/+git/ntp-charm:master into ntp-charm:master

Proposed by Paul Gear
Status: Merged
Merged at revision: 25a55e92bb0bcfbc747ecff10ca48f4c58e4c3f9
Proposed branch: ~paulgear/ntp-charm/+git/ntp-charm:master
Merge into: ntp-charm:master
Diff against target: 227 lines (+63/-34)
4 files modified
README.md (+32/-11)
config.yaml (+14/-2)
hooks/ntp_hooks.py (+14/-21)
templates/ntp.conf (+3/-0)
Reviewer Review Type Date Requested Status
Haw Loeung Approve
Review via email: mp+313917@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Haw Loeung (hloeung) wrote :

LGTM, +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/README.md b/README.md
2index 59ee007..e635e7a 100644
3--- a/README.md
4+++ b/README.md
5@@ -7,23 +7,23 @@ across computers.
6 Usage
7 -----
8
9-The ntp charm is a subordinate charm that is design for use with other
10-principle charms. It can be used in two ways:
11+The ntp charm is a subordinate charm which is designed for use with other
12+principal charms. It can be used in two ways:
13
14 Standalone
15 ==========
16
17-In this mode the ntp charm is used to configure NTP in other service units to
18+In this mode, the ntp charm is used to configure NTP in other service units to
19 talk directly to a set of NTP time sources:
20
21 juju deploy ntp
22 juju add-relation ntp myservice
23
24-By default this is the standard set of NTP pool servers that are configured in
25-the ntp Ubuntu package.
26+By default this charm uses the standard set of NTP pool servers which are
27+configured in the ntp Ubuntu package.
28
29 However, if you have a handy atomic clock on your network which you would prefer
30-to trust then you can use that instead:
31+to use then you can add that:
32
33 juju set ntp source=myatomiclock.local.net
34
35@@ -32,21 +32,26 @@ You can also specify multiple sources and peers:
36 juju set ntp source="mac1.local.net mac2.local.net mac3.local.net"
37 juju set ntp peers="mac1.local.net mac2.local.net mac3.local.net"
38
39-Sources and peers should be space separated.
40+To disable the default list of pool servers, set that to the empty string:
41+
42+ juju set ntp pools=""
43+
44+Sources, peers, and pools should be space separated.
45
46 When you need a set of services to keep close time to each other, it may
47 be useful to have them automatically peer with each other. This means
48-any set of services that use the same ntp subordinate will peer together.
49+any set of services which use the same ntp subordinate will peer together.
50
51 juju set ntp auto_peers=true
52
53-This will add all the hosts as peers to each other.
54+This will add all the hosts as peers to each other. Using auto_peers is not
55+recommended when more than 10 units are expected to be deployed.
56
57 Mastered
58 ========
59
60 In the event that you don't wish every server on your network to talk directly to
61-your trusted time sources, you can use this charm in-conjunction with the ntpmaster
62+your configured time sources, you can use this charm in-conjunction with the ntpmaster
63 charm:
64
65 juju deploy ntp
66@@ -59,7 +64,7 @@ This might have application in more secure network environments where general
67 outbound network access to the Internet is not avaliable or desirable and you don't
68 have a good internal time source such as an atomic clock.
69
70-You can of course have more that one ntpmaster:
71+You can of course have more than one ntpmaster:
72
73 juju add-unit ntpmaster
74
75@@ -67,3 +72,19 @@ All services that the ntp charm is subordinate to will be configured to sync wit
76 all avaliable masters.
77
78 The ntpmaster charm supports the same "source" configuration that the ntp charm does.
79+
80+The ntp charm can also be used in place of the ntpmaster charm when coupled with
81+another primary charm:
82+
83+ juju deploy ntp ntp-masters
84+ juju deploy ubuntu --num-units=4
85+ juju add-relation ubuntu ntp-masters
86+ juju set ntp-masters auto_peers=true
87+
88+ juju deploy ntp
89+ juju deploy my-other-service --num-units=30
90+ juju add-relation ntp my-other-service
91+ juju add-relation ntp ntp-masters
92+
93+This is the recommended method, since this charm provides better monitoring and
94+more flexible configuration than ntpmaster.
95diff --git a/config.yaml b/config.yaml
96index d9c9680..1405f4b 100644
97--- a/config.yaml
98+++ b/config.yaml
99@@ -10,6 +10,18 @@ options:
100 description: >
101 Space-separated list of NTP servers to use as peers for time.
102 Peers are allowed to query the local NTP server via ntpq.
103+ pools:
104+ default: >
105+ 0.ubuntu.pool.ntp.org
106+ 1.ubuntu.pool.ntp.org
107+ 2.ubuntu.pool.ntp.org
108+ 3.ubuntu.pool.ntp.org
109+ ntp.ubuntu.com
110+ type: string
111+ description: >
112+ Space-separated list of NTP servers to use as pool sources for
113+ time. Pool sources are recommended over normal sources for their
114+ self-healing capabilities. Leave empty to disable pool sources.
115 orphan_stratum:
116 default: 6
117 type: int
118@@ -17,8 +29,8 @@ options:
119 The NTP stratum at which ntp most lose connectivity to before it
120 considers itself orphaned, and starts communicating with local peers.
121 The default value of 6 will enable orphaned operation when there are
122- no stratum 6 servers or servers of a higher stratum available, which is
123- two stratum below most internet NTP hosts.
124+ no stratum 6 servers or servers of a higher stratum available, which
125+ is two strata below most Internet NTP hosts.
126 Set to 0 to disable orphan mode entirely.
127 nagios_context:
128 default: "juju"
129diff --git a/hooks/ntp_hooks.py b/hooks/ntp_hooks.py
130index 2a36c8c..61ba2ec 100755
131--- a/hooks/ntp_hooks.py
132+++ b/hooks/ntp_hooks.py
133@@ -43,7 +43,7 @@ def get_sources(sources, iburst=True, source_list=None):
134 if sources:
135 # allow both strings and lists
136 if isinstance(sources, str):
137- sources = sources.split(" ")
138+ sources = sources.split()
139 for s in sources:
140 if len(s) > 0:
141 if iburst:
142@@ -66,6 +66,8 @@ def write_config():
143 source = hookenv.config('source')
144 orphan_stratum = hookenv.config('orphan_stratum')
145 remote_sources = get_sources(source, iburst=use_iburst)
146+ pools = hookenv.config('pools')
147+ remote_pools = get_sources(pools, iburst=use_iburst)
148 for relid in hookenv.relation_ids('master'):
149 for unit in hookenv.related_units(relid=relid):
150 u_addr = hookenv.relation_get(attribute='private-address',
151@@ -79,8 +81,8 @@ def write_config():
152 remote_peers = get_sources(get_peer_nodes(), iburst=use_iburst,
153 source_list=remote_peers)
154
155- if len(remote_sources) == 0 and len(remote_peers) == 0:
156- # we have no peers/servers; restore default ntp.conf provided by OS
157+ if len(remote_sources) == 0 and len(remote_peers) == 0 and len(remote_pools) == 0:
158+ # we have no peers/pools/servers; restore default ntp.conf provided by OS
159 shutil.copy(NTP_CONF_ORIG, NTP_CONF)
160 else:
161 # otherwise, write our own configuration
162@@ -88,6 +90,7 @@ def write_config():
163 ntpconf.write(render(os.path.basename(NTP_CONF), {
164 'orphan_stratum': orphan_stratum,
165 'peers': remote_peers,
166+ 'pools': remote_pools,
167 'servers': remote_sources,
168 }))
169
170@@ -102,7 +105,7 @@ def update_nrpe_config():
171 # python-dbus is used by check_upstart_job
172 # python-psutil is used by check_ntpmon
173 fetch.apt_install(['python-dbus', 'python-psutil'])
174- nagios_ntpmon_checks = hookenv.config('nagios_ntpmon_checks').split(" ")
175+ nagios_ntpmon_checks = hookenv.config('nagios_ntpmon_checks').split()
176 if os.path.isdir(NAGIOS_PLUGINS):
177 host.rsync(os.path.join(os.getenv('CHARM_DIR'), 'files', 'nagios',
178 'check_ntpmon.py'),
179@@ -110,7 +113,7 @@ def update_nrpe_config():
180
181 hostname = nrpe.get_nagios_hostname()
182 current_unit = nrpe.get_nagios_unit_name()
183- nrpe_setup = nrpe.NRPE(hostname=hostname)
184+ nrpe_setup = nrpe.NRPE(hostname=hostname, primary=False)
185
186 allchecks = set(['offset', 'peers', 'reachability', 'sync'])
187
188@@ -119,22 +122,12 @@ def update_nrpe_config():
189 for c in allchecks:
190 nrpe_setup.remove_check(shortname="ntpmon_%s" % c)
191
192- # If all checks are specified, combine them into a single check to reduce
193- # Nagios noise.
194- if set(nagios_ntpmon_checks) == allchecks:
195- nrpe_setup.add_check(
196- shortname="ntpmon",
197- description='Check NTPmon {}'.format(current_unit),
198- check_cmd='check_ntpmon.py'
199- )
200- else:
201- nrpe_setup.add_check(
202- shortname="ntpmon",
203- description='Check NTPmon {}'.format(current_unit),
204- check_cmd=('check_ntpmon.py --checks ' +
205- ' '.join(nagios_ntpmon_checks))
206- )
207-
208+ nrpe_setup.add_check(
209+ shortname="ntpmon",
210+ description='Check NTPmon {}'.format(current_unit),
211+ check_cmd=('check_ntpmon.py --checks ' +
212+ ' '.join(nagios_ntpmon_checks))
213+ )
214 nrpe_setup.write()
215
216
217diff --git a/templates/ntp.conf b/templates/ntp.conf
218index c28b8d5..edc36a9 100644
219--- a/templates/ntp.conf
220+++ b/templates/ntp.conf
221@@ -22,3 +22,6 @@ orphan tos {{ orphan_stratum }}
222 # PEERS
223 {% for peer in peers %}peer {{ peer.name }} {{ peer.iburst }}
224 {% endfor %}
225+# POOLS
226+{% for pool in pools %}pool {{ pool.name }} {{ pool.iburst }}
227+{% endfor %}

Subscribers

People subscribed via source and target branches