Merge lp:~michael.iatrou/maas/fix-1673378 into lp:~maas-committers/maas/trunk

Proposed by Michael Iatrou
Status: Merged
Approved by: Lee Trager
Approved revision: no longer in the source branch.
Merged at revision: 5834
Proposed branch: lp:~michael.iatrou/maas/fix-1673378
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 50 lines (+35/-0)
2 files modified
src/metadataserver/builtin_scripts/__init__.py (+8/-0)
src/metadataserver/builtin_scripts/ntp.sh (+27/-0)
To merge this branch: bzr merge lp:~michael.iatrou/maas/fix-1673378
Reviewer Review Type Date Requested Status
Lee Trager (community) Approve
Gavin Panella (community) Abstain
Ante Karamatić (community) Approve
Andres Rodriguez Pending
Review via email: mp+320037@code.launchpad.net

Commit message

Add NTP connectivity test.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

I have a suggestion that the script should tidy up after itself, but otherwise this looks good.

review: Needs Fixing
Revision history for this message
Ante Karamatić (ivoks) :
Revision history for this message
Michael Iatrou (michael.iatrou) wrote :

Thank you Gavin! I have amended the patch per your feedback.

Revision history for this message
Gavin Panella (allenap) wrote :

Thanks.

I haven't tested this script. Have you had a chance?

review: Approve
Revision history for this message
Ante Karamatić (ivoks) wrote :

I'll test it right away

Revision history for this message
Ante Karamatić (ivoks) wrote :

I guess it needs a bit more intelligence. Test reports passed even if sync is not done:

...
16 Mar 14:44:42 ntpd[3744]: ntpd 4.2.8p4@1.3265-o Wed Oct 5 12:34:45 UTC 2016 (1): Starting
16 Mar 14:44:42 ntpd[3744]: Command line: ntpd -gq
16 Mar 14:44:42 ntpd[3744]: proto: precision = 0.046 usec (-24)
16 Mar 14:44:42 ntpd[3744]: Listen and drop on 0 v6wildcard [::]:123
16 Mar 14:44:42 ntpd[3744]: Listen and drop on 1 v4wildcard 0.0.0.0:123
16 Mar 14:44:42 ntpd[3744]: Listen normally on 2 lo 127.0.0.1:123
16 Mar 14:44:42 ntpd[3744]: Listen normally on 3 ens255f0 172.16.7.29:123
16 Mar 14:44:42 ntpd[3744]: Listen normally on 4 lo [::1]:123
16 Mar 14:44:42 ntpd[3744]: Listen normally on 5 ens255f0 [fe80::2e60:cff:fef9:6b6a%2]:123
16 Mar 14:44:42 ntpd[3744]: Listening on routing socket on fd #22 for interface updates
16 Mar 14:44:53 ntpd[3744]: ntpd: no servers found
...

When NTP is accessible, it works fine:

...
16 Mar 14:24:52 ntpd[3553]: ntpd 4.2.8p4@1.3265-o Wed Oct 5 12:34:45 UTC 2016 (1): Starting
16 Mar 14:24:52 ntpd[3553]: Command line: ntpd -gq
16 Mar 14:24:52 ntpd[3553]: proto: precision = 0.045 usec (-24)
16 Mar 14:24:52 ntpd[3553]: Listen and drop on 0 v6wildcard [::]:123
16 Mar 14:24:52 ntpd[3553]: Listen and drop on 1 v4wildcard 0.0.0.0:123
16 Mar 14:24:52 ntpd[3553]: Listen normally on 2 lo 127.0.0.1:123
16 Mar 14:24:52 ntpd[3553]: Listen normally on 3 ens255f0 172.16.7.29:123
16 Mar 14:24:52 ntpd[3553]: Listen normally on 4 lo [::1]:123
16 Mar 14:24:52 ntpd[3553]: Listen normally on 5 ens255f0 [fe80::2e60:cff:fef9:6b6a%2]:123
16 Mar 14:24:52 ntpd[3553]: Listening on routing socket on fd #22 for interface updates
16 Mar 14:24:53 ntpd[3553]: ntpd: time slew +0.001707 s
...

Revision history for this message
Gavin Panella (allenap) wrote :

Mmm, not sure ntpd is going to work at all, at least without a lot more work; see my comment.

review: Needs Fixing
Revision history for this message
Michael Iatrou (michael.iatrou) wrote :

> Mmm, not sure ntpd is going to work at all, at least without a lot more work;
> see my comment.

It seems that /var/lib/systemd/clock is not necessarily up to date:

$ timedatectl status
      Local time: Thu 2017-03-16 15:32:40 UTC
  Universal time: Thu 2017-03-16 15:32:40 UTC
        RTC time: n/a
       Time zone: Etc/UTC (UTC, +0000)
 Network time on: yes
NTP synchronized: yes
 RTC in local TZ: no
$ ll /var/lib/systemd/clock
-rw-r--r-- 1 systemd-timesync systemd-timesync 0 Mar 16 14:19 /var/lib/systemd/clock

Revision history for this message
Ante Karamatić (ivoks) wrote :

Gavin I see different results in my tests when I change NTP server in MAAS' settings (ntp.ubuntu.com works, nttypo.ubuntu.com doesn't). So, I guess NTP/ntp.conf does get updated?

Revision history for this message
Ante Karamatić (ivoks) wrote :
Download full text (3.5 KiB)

Failure:
sudo: unable to resolve host helped-swift
Reading package lists...
Building dependency tree...
Reading state information...
ntp is already the newest version (1:4.2.8p4+dfsg-3ubuntu5.3).
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
sudo: unable to resolve host helped-swift
sudo: unable to resolve host helped-swift
16 Mar 15:52:32 ntpd[3682]: ntpd 4.2.8p4@1.3265-o Wed Oct 5 12:34:45 UTC 2016 (1): Starting
16 Mar 15:52:32 ntpd[3682]: Command line: ntpd -gq
16 Mar 15:52:32 ntpd[3682]: proto: precision = 0.045 usec (-24)
16 Mar 15:52:32 ntpd[3682]: Listen and drop on 0 v6wildcard [::]:123
16 Mar 15:52:32 ntpd[3682]: Listen and drop on 1 v4wildcard 0.0.0.0:123
16 Mar 15:52:32 ntpd[3682]: Listen normally on 2 lo 127.0.0.1:123
16 Mar 15:52:32 ntpd[3682]: Listen normally on 3 ens255f0 172.16.7.29:123
16 Mar 15:52:32 ntpd[3682]: Listen normally on 4 lo [::1]:123
16 Mar 15:52:32 ntpd[3682]: Listen normally on 5 ens255f0 [fe80::2e60:cff:fef9:6b6a%2]:123
16 Mar 15:52:32 ntpd[3682]: Listening on routing socket on fd #22 for interface updates
16 Mar 15:52:42 ntpd[3682]: ntpd exiting on signal 15 (Terminated)
16 Mar 15:52:42 ntpd[3682]: 172.16.7.2 local addr 172.16.7.29 -> <null>

Success:
sudo: unable to resolve host helped-swift
Reading package lists...
Building dependency tree...
Reading state information...
ntp is already the newest version (1:4.2.8p4+dfsg-3ubuntu5.3).
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
sudo: unable to resolve host helped-swift
sudo: unable to resolve host helped-swift
16 Mar 16:01:19 ntpd[3735]: ntpd 4.2.8p4@1.3265-o Wed Oct 5 12:34:45 UTC 2016 (1): Starting
16 Mar 16:01:19 ntpd[3735]: Command line: ntpd -gq
16 Mar 16:01:19 ntpd[3735]: proto: precision = 0.045 usec (-24)
16 Mar 16:01:19 ntpd[3735]: Listen and drop on 0 v6wildcard [::]:123
16 Mar 16:01:19 ntpd[3735]: Listen and drop on 1 v4wildcard 0.0.0.0:123
16 Mar 16:01:19 ntpd[3735]: Listen normally on 2 lo 127.0.0.1:123
16 Mar 16:01:19 ntpd[3735]: Listen normally on 3 ens255f0 172.16.7.29:123
16 Mar 16:01:19 ntpd[3735]: Listen normally on 4 lo [::1]:123
16 Mar 16:01:19 ntpd[3735]: Listen normally on 5 ens255f0 [fe80::2e60:cff:fef9:6b6a%2]:123
16 Mar 16:01:19 ntpd[3735]: Listening on routing socket on fd #22 for interface updates
16 Mar 16:01:20 ntpd[3735]: ntpd: time slew +0.009739 s
ntpd: time slew +0.009739s
sudo: unable to resolve host helped-swift
Reading package lists...
Building dependency tree...
Reading state information...
The following package was automatically installed and is no longer required:
libopts25
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED:
ntp*
0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
After this operation, 1,620 kB disk space will be freed.
(Reading database ...
(Reading database ... 5%
(Reading database ... 10%
(Reading database ... 15%
(Reading database ... 20%
(Reading database ... 25%
(Reading database ... 30%
(Reading database ... 35%
(Reading database ... 40%
(Reading database ... 45%
(Reading database ... 50%
(Reading database ... 55%
(Reading database ... 60%
(Reading database ... 65%
(Reading database ... 70%
(Reading database ... 75%
(Read...

Read more...

Revision history for this message
Ante Karamatić (ivoks) wrote :

Looks like ntp is already installed?

Revision history for this message
Andres Rodriguez (andreserl) wrote :

fwiw, in the commissioning environment we send cloud-init metadata for NTP configuration. This gets configured before anywhere else runs. As such, there is NTP configured and running in the ephemeral environment

Revision history for this message
Gavin Panella (allenap) wrote :

Just had a conversation with the team: ntp is already installed, as you've discovered Ante. MAAS instructs cloud-init to install and configure ntp. So, sorry, I've been leading you on a long path round the problem.

So, given that ntp is already installed and running, it might be possible to reduce the script to a single command:

  ntpq -np

which prints the active peers. For my local machine this prints:

       remote refid st t when poll reach delay offset jitter
  ==============================================================================
  *192.168.178.1 141.82.25.202 3 u 290 1024 377 2.379 0.483 0.793

Revision history for this message
Ante Karamatić (ivoks) wrote :

While that's good info to have, with broken NTP servers it also returns
results:

root@helium:~# ntpq -np
     remote refid st t when poll reach delay offset
 jitter
==============================================================================
 typo.ubuntu.com .POOL. 16 p - 64 0 0.000 0.000
0.000
root@helium:~# echo $?
0

On Thu, Mar 16, 2017 at 5:18 PM Gavin Panella <email address hidden>
wrote:

> Just had a conversation with the team: ntp is already installed, as you've
> discovered Ante. MAAS instructs cloud-init to install and configure ntp.
> So, sorry, I've been leading you on a long path round the problem.
>
> So, given that ntp is already installed and running, it might be possible
> to reduce the script to a single command:
>
> ntpq -np
>
> which prints the active peers. For my local machine this prints:
>
> remote refid st t when poll reach delay offset
> jitter
>
> ==============================================================================
> *192.168.178.1 141.82.25.202 3 u 290 1024 377 2.379 0.483
> 0.793
>
> --
> https://code.launchpad.net/~michael.iatrou/maas/fix-1673378/+merge/320037
> You are requested to review the proposed merge of
> lp:~michael.iatrou/maas/fix-1673378 into lp:maas.
>
--
Ante Karamatić
<email address hidden>
Canonical

Revision history for this message
Gavin Panella (allenap) wrote :

The ntpstat command (from the ntpstat) package might do what you need.
From ntpstat(1):

  DESCRIPTION
       ntpstat will report the synchronisation state of the NTP daemon
       running on the local machine. If the local system is found to be
       synchronised to a reference time source, ntpstat will report the
       approximate time accuracy.

  RETURNS
       ntpstat returns 0 if clock is synchronised. ntpstat returns 1 if
       clock is not synchronised. ntpstat returns 2 if clock state is
       indeterminant, for example if ntpd is not contactable.

The only downsides are that it's not installed by default and it's in
universe.

Running locally:

  $ ntpstat
  synchronised to NTP server (192.168.178.1) at stratum 4
     time correct to within 78 ms
     polling server every 1024 s

Revision history for this message
Ante Karamatić (ivoks) wrote :

I approve with latest changes which I tested with correct and incorrect NTPs.

review: Approve
Revision history for this message
Gavin Panella (allenap) wrote :

I think I've spotted a bug in the script. I've made too many mistakes today to trust myself right now, but please check it out.

review: Abstain
Revision history for this message
Lee Trager (ltrager) wrote :

LGTM, thanks for adding the NTP test.

review: Approve
Revision history for this message
Paul Gear (paulgear) wrote :

Or you could use the Nagios check (or a variant on it) from the NTP charm: https://git.launchpad.net/ntpmon/tree/src/check_ntpmon.py

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/metadataserver/builtin_scripts/__init__.py'
2--- src/metadataserver/builtin_scripts/__init__.py 2017-03-10 16:50:30 +0000
3+++ src/metadataserver/builtin_scripts/__init__.py 2017-03-16 23:39:45 +0000
4@@ -124,6 +124,14 @@
5 timeout=60 * 60 * 12 + 60 * 5,
6 filename='stress_ng_memory_long.sh',
7 ),
8+ BuiltinScript(
9+ name='ntp',
10+ title='NTP validation',
11+ description='Run ntp clock set to verify NTP connectivity.',
12+ tags=['network', 'internet'],
13+ timeout=60,
14+ filename='ntp.sh',
15+ ),
16 ]
17
18
19
20=== added file 'src/metadataserver/builtin_scripts/ntp.sh'
21--- src/metadataserver/builtin_scripts/ntp.sh 1970-01-01 00:00:00 +0000
22+++ src/metadataserver/builtin_scripts/ntp.sh 2017-03-16 23:39:45 +0000
23@@ -0,0 +1,27 @@
24+#!/bin/sh -e
25+#
26+# ntp - Run ntp clock set to verify NTP connectivity.
27+#
28+# Author: Michael Iatrou <michael.iatrou (at) canonical.com>
29+#
30+# Copyright (C) 2017 Canonical
31+#
32+# This program is free software: you can redistribute it and/or modify
33+# it under the terms of the GNU Affero General Public License as
34+# published by the Free Software Foundation, either version 3 of the
35+# License, or (at your option) any later version.
36+#
37+# This program is distributed in the hope that it will be useful,
38+# but WITHOUT ANY WARRANTY; without even the implied warranty of
39+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40+# GNU Affero General Public License for more details.
41+#
42+# You should have received a copy of the GNU Affero General Public License
43+# along with this program. If not, see <http://www.gnu.org/licenses/>.
44+
45+e=0
46+ntpq -np
47+sudo systemctl stop ntp.service
48+sudo timeout 10 ntpd -gq || e=$?
49+sudo systemctl start ntp.service
50+exit $e