Skip to contentSkip to conversation

Fix NTP unreliability, and other fixes

PATCH New Ian Jackson 1 participant 10 messages Feb 17, 2015

lore
Share & tools
lore
#0 lore raw

cover Fix NTP unreliability, and other fixes

We are having persistent spurious "xen-boot" failures. Cursory investigation revealed that this was due to problems with NTP startup, so we put it down to infrastructure problems.

However, it turns out that the cause is that we are using the Debian-default NTP servers from pool.ntp.org. We might expect some of these servers don't work some of the time.

The underlying cause is a bug in Debian: the NTP servers specified via preseeding are used during the installer environment to set the clock, but the information is not used to configure the actual ntp server package in the install. I have reported this as a bug in Debian but we need to work around it by editing ntp.conf after installation.

There are also two unrelated fixes in this series.

One of the changes (`Provide get_target_property') is likely to be useful for nested virt.

In the absence of objections I am going to push this series soon.

#1 lore raw

PATCH 1/9 cs-adjust-flight: Add missing `use Data::Dumper'

Dumper is used in some of the error reporting so we need to `use' it.

---
 cs-adjust-flight |    1 +
 1 file changed, 1 insertion(+)
cs-adjust-flight +1 -0
index d6cab1a..9bd8757 100755
@@ -40,6 +40,7 @@
 use strict qw(vars);
 use DBI;
 use Osstest;
+use Data::Dumper;
 
 csreadconfig();
 
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/9 sg-report-job-history: Increase default history depth to 500

In reply to Ian Jackson

We are putting through a lot more jobs and branches. Older history is still interesting.

---
 sg-report-job-history |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sg-report-job-history +1 -1
index 3e4b0ef..e7052a3 100755
@@ -27,7 +27,7 @@ use HTML::Entities;
 use Osstest::TestSupport;
 
 our (@blessings,@branches);
-our $limit= 100;
+our $limit= 500;
 our $htmlout;
 
 open DEBUG, ">/dev/null";
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 3/9 config: Tiny fixes

In reply to Ian Jackson

* Default $c{DebianPreseed} to '' (previously, if it wasn't specified, there would be undefined variable warnings).

* Cope with empty <<END-notated config items in the configuration file parser.

---
 Osstest.pm |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Osstest.pm +3 -1
index fc9698b..6d7c083 100644
@@ -74,6 +74,8 @@ our %c = qw(
     DebianNonfreeFirmware firmware-bnx2
 );
 
+$c{DebianPreseed} = '';
+
 #---------- general setup and config reading ----------
 
 sub getmethod {
@@ -120,7 +122,7 @@ sub readglobalconfig () {
 			$val .= $_;
 		    }
 		    die $! unless length $_;
-		    die unless $val =~ m/\n$/;
+		    die unless !length $val || $val =~ m/\n$/;
 		    if ($qu eq '') {
 			my $reconstruct =
 			    "\$val = <<${qu}${delim}${qu}; 1;\n".
Signature · 1 line
1.7.10.4
#4 lore raw

PATCH 4/9 TestSupport: Provide get_target_property

In reply to Ian Jackson

This looks in the supplied $ho, but if that's a $gho (ie it has a $gho->{Host}) it also looks in its host.

This is going to be useful for a fair variety of host-specific or infrastructure-determined properties.

It seems to me that whether a property ought to be looked up in the host if not found in a particular guest depends mostly on the property, and not on the way the guest is configured. The easiest way to represent that in the osstest codebase is probably to call get_target_property instead of get_host_property in the appropriate places.

The use of recursion will make this look through a series of nested hosts if we have nested virtualisation going on. Indeed, nested virtualisation may benefit from replacement of get_host_property by get_target_property in a number of cases. (At the time of writing there is no nested virt in osstest mainline, but it's on the way.)

Currently there are no callers of get_target_property. One will appear shortly.

CC Robert Hu <[email protected]>
CC LongtaoX Pang <[email protected]>
---
 Osstest/TestSupport.pm |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
Osstest/TestSupport.pm +12 -1
index 8aed285..8754e22 100644
@@ -66,7 +66,7 @@ BEGIN {
                       contents_make_cpio file_simple_write_contents
 
                       selecthost get_hostflags get_host_property
-                      get_host_native_linux_console
+                      get_target_property get_host_native_linux_console
                       power_state power_cycle power_cycle_sleep
                       serial_fetch_logs
                       propname_massage
@@ -906,6 +906,17 @@ sub get_host_property ($$;$) {
     return defined($val) ? $val : $defval;
 }
 
+sub get_target_property ($$;$);
+sub get_target_property ($$;$) {
+    my ($ho, $prop, $defval) = @_;
+    # $ho may be a guest; if so we look for the property in the
+    # guest and failing that the same property in the host.
+    return
+	get_host_property($ho, $prop) //
+	($ho->{Host} && get_target_property($ho->{Host}, $prop)) //
+	$defval;
+}
+
 sub get_host_native_linux_console ($) {
     my ($ho) = @_;
 
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH 5/9 Debian.pm: Pass $ho/$gho to preseed_base

In reply to Ian Jackson

This is going to be useful soon.

---
 Osstest/Debian.pm     |    6 +++---
 ts-debian-hvm-install |    2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
Osstest/Debian.pm +3 -3
index e3e1c90..a044f8f 100644
@@ -503,8 +503,8 @@ sub di_installcmdline_core ($$;@) {
     return @cl;
 }
 
-sub preseed_base ($$;@) {
-    my ($suite,$extra_packages,%xopts) = @_;
+sub preseed_base ($$$;@) {
+    my ($ho,$suite,$extra_packages,%xopts) = @_;
 
     return <<"END";
 d-i mirror/suite string $suite
@@ -813,7 +813,7 @@ END
 
     my $extra_packages = join(",",@extra_packages);
 
-    my $preseed_file= preseed_base($suite,$extra_packages,%xopts);
+    my $preseed_file= preseed_base($ho,$suite,$extra_packages,%xopts);
 
     $preseed_file .= (<<END);
 d-i partman-auto/method string lvm
ts-debian-hvm-install +1 -1
index 449b96c..cfd5144 100755
@@ -43,7 +43,7 @@ our $gho;
 
 sub preseed () {
 
-    my $preseed_file = preseed_base('wheezy','',());
+    my $preseed_file = preseed_base($gho,'wheezy','',());
     my $authkeys = join('\\n', split(/\n/, authorized_keys()));
 
     $preseed_file .= (<<END);
Signature · 1 line
1.7.10.4
#6 lore raw

PATCH 6/9 Debian.pm: Slightly refactor preseed_base

In reply to Ian Jackson

Arrange for preseed_base to accumulate its result in a variable. This is going to make it easier to add entries which are determined programatically.

No functional change.

---
 Osstest/Debian.pm |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
Osstest/Debian.pm +8 -3
index a044f8f..315d25c 100644
@@ -506,7 +506,7 @@ sub di_installcmdline_core ($$;@) {
 sub preseed_base ($$$;@) {
     my ($ho,$suite,$extra_packages,%xopts) = @_;
 
-    return <<"END";
+    my $preseed = <<"END";
 d-i mirror/suite string $suite
 
 d-i debian-installer/locale string en_GB
@@ -572,10 +572,15 @@ d-i pkgsel/include string openssh-server, ntp, ntpdate, ethtool, chiark-utils-bi
 
 $xopts{ExtraPreseed}
 
-### END OF DEBIAN PRESEED BASE
+END
+
+    $preseed .= <<"END";
 
+### END OF DEBIAN PRESEED BASE
 END
-}          
+
+    return $preseed;
+}
 
 sub preseed_create ($$;@) {
     my ($ho, $sfx, %xopts) = @_;
Signature · 1 line
1.7.10.4
#7 lore raw

PATCH 7/9 NTP servers: Introduce new NtpServer host property

In reply to Ian Jackson

Allow the specification of NTP servers in a dedicated NtpServer host property, which we honour in preseed_create.

Change the documentation to recommend this, rather than use of ad-hoc text in DebianPreseed.

Osstest/Debian.pm +15 -3
index a044f8f..cc075a4 100644
@@ -506,7 +506,7 @@ sub di_installcmdline_core ($$;@) {
 sub preseed_base ($$$;@) {
     my ($ho,$suite,$extra_packages,%xopts) = @_;
 
-    return <<"END";
+    my $preseed = <<"END";
 d-i mirror/suite string $suite
 
 d-i debian-installer/locale string en_GB
@@ -572,10 +572,22 @@ d-i pkgsel/include string openssh-server, ntp, ntpdate, ethtool, chiark-utils-bi
 
 $xopts{ExtraPreseed}
 
-### END OF DEBIAN PRESEED BASE
+END
+
+    my $ntpserver = get_target_property($ho,'NtpServer');
+use Data::Dumper;
+print STDERR "PRESEED NTP ", Dumper($ntpserver);
+    $preseed .= <<"END" if $ntpserver;
+d-i clock-setup/ntp-server string $ntpserver
+END
 
+    $preseed .= <<"END";
+
+### END OF DEBIAN PRESEED BASE
 END
-}
+
+    return $preseed;
+}
 
 sub preseed_create ($$;@) {
     my ($ho, $sfx, %xopts) = @_;
README +6 -3
index 6e63e97..0a0242c 100644
@@ -334,6 +334,11 @@ HostProp_<testbox>_TftpScope
    Defines the Tftp scope (i.e. subnet) where this host resides. See
    "TftpFoo_<scope> and TftpFoo" below.
 
+HostProp_<testbox>_NtpServer
+   NTP server to use.  You should probably have your own local
+   NTP server for production use; the default is to use the operating
+   system's default (normally, Debian's pool.ntp.org servers).
+
 HostFlags_<testbox>
    Defines a set of flags for the host. Flags is a list separated by
    whitespace, comma or semi-colon. A flag can be unset by prepending
@@ -357,9 +362,7 @@ HostGroupFlags_<group>
    merged with the host specific flags. Only used in standalone mode.
 
 DebianPreseed
-   Text to add to the debian-installer preseed file.  Optional
-   but you will need to set some NTP servers here if your firewall
-   doesn't permit NTP to Debian's pool.ntp.org servers.
+   Text to add to the debian-installer preseed file.  Optional.
 
 ========================================
 
production-config +2 -1
index 515bd98..5fbca50 100644
@@ -77,8 +77,9 @@ XenUseUser osstest
 #DebianMirrorHost debian.uk.xensource.com
 DebianMirrorHost 10.80.16.196
 
+HostProp_NtpServer ntp.uk.xensource.com
+
 DebianPreseed= <<'END'
-d-i clock-setup/ntp-server string ntp.uk.xensource.com
 END
 
 HostProp_Serial sympathy woking
---
 Osstest/Debian.pm |    5 +++++
 README            |    9 ++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)
Osstest/Debian.pm +5 -0
index 315d25c..7633b51 100644
@@ -574,6 +574,11 @@ $xopts{ExtraPreseed}
 
 END
 
+    my $ntpserver = get_target_property($ho,'NtpServer');
+    $preseed .= <<"END" if $ntpserver;
+d-i clock-setup/ntp-server string $ntpserver
+END
+
     $preseed .= <<"END";
 
 ### END OF DEBIAN PRESEED BASE
README +6 -3
index 6e63e97..0a0242c 100644
@@ -334,6 +334,11 @@ HostProp_<testbox>_TftpScope
    Defines the Tftp scope (i.e. subnet) where this host resides. See
    "TftpFoo_<scope> and TftpFoo" below.
 
+HostProp_<testbox>_NtpServer
+   NTP server to use.  You should probably have your own local
+   NTP server for production use; the default is to use the operating
+   system's default (normally, Debian's pool.ntp.org servers).
+
 HostFlags_<testbox>
    Defines a set of flags for the host. Flags is a list separated by
    whitespace, comma or semi-colon. A flag can be unset by prepending
@@ -357,9 +362,7 @@ HostGroupFlags_<group>
    merged with the host specific flags. Only used in standalone mode.
 
 DebianPreseed
-   Text to add to the debian-installer preseed file.  Optional
-   but you will need to set some NTP servers here if your firewall
-   doesn't permit NTP to Debian's pool.ntp.org servers.
+   Text to add to the debian-installer preseed file.  Optional.
 
 ========================================
 
Signature · 1 line
1.7.10.4
#8 lore raw

PATCH 8/9 NTP servers: Use NtpServer host property

In reply to Ian Jackson

Move the specification of NTP servers in the production-config from the ad-hoc entry in DebianPreseed to a dedicated NtpServer host property.

This results in no overall functional change, except that the order of elements in the preseed file is slightly different.

Osstest/Debian.pm +15 -3
index a044f8f..cc075a4 100644
@@ -506,7 +506,7 @@ sub di_installcmdline_core ($$;@) {
 sub preseed_base ($$$;@) {
     my ($ho,$suite,$extra_packages,%xopts) = @_;
 
-    return <<"END";
+    my $preseed = <<"END";
 d-i mirror/suite string $suite
 
 d-i debian-installer/locale string en_GB
@@ -572,10 +572,22 @@ d-i pkgsel/include string openssh-server, ntp, ntpdate, ethtool, chiark-utils-bi
 
 $xopts{ExtraPreseed}
 
-### END OF DEBIAN PRESEED BASE
+END
+
+    my $ntpserver = get_target_property($ho,'NtpServer');
+use Data::Dumper;
+print STDERR "PRESEED NTP ", Dumper($ntpserver);
+    $preseed .= <<"END" if $ntpserver;
+d-i clock-setup/ntp-server string $ntpserver
+END
 
+    $preseed .= <<"END";
+
+### END OF DEBIAN PRESEED BASE
 END
-}
+
+    return $preseed;
+}
 
 sub preseed_create ($$;@) {
     my ($ho, $sfx, %xopts) = @_;
README +6 -3
index 6e63e97..0a0242c 100644
@@ -334,6 +334,11 @@ HostProp_<testbox>_TftpScope
    Defines the Tftp scope (i.e. subnet) where this host resides. See
    "TftpFoo_<scope> and TftpFoo" below.
 
+HostProp_<testbox>_NtpServer
+   NTP server to use.  You should probably have your own local
+   NTP server for production use; the default is to use the operating
+   system's default (normally, Debian's pool.ntp.org servers).
+
 HostFlags_<testbox>
    Defines a set of flags for the host. Flags is a list separated by
    whitespace, comma or semi-colon. A flag can be unset by prepending
@@ -357,9 +362,7 @@ HostGroupFlags_<group>
    merged with the host specific flags. Only used in standalone mode.
 
 DebianPreseed
-   Text to add to the debian-installer preseed file.  Optional
-   but you will need to set some NTP servers here if your firewall
-   doesn't permit NTP to Debian's pool.ntp.org servers.
+   Text to add to the debian-installer preseed file.  Optional.
 
 ========================================
 
production-config +2 -1
index 515bd98..5fbca50 100644
@@ -77,8 +77,9 @@ XenUseUser osstest
 #DebianMirrorHost debian.uk.xensource.com
 DebianMirrorHost 10.80.16.196
 
+HostProp_NtpServer ntp.uk.xensource.com
+
 DebianPreseed= <<'END'
-d-i clock-setup/ntp-server string ntp.uk.xensource.com
 END
 
 HostProp_Serial sympathy woking
---
 production-config |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
production-config +2 -1
index 515bd98..5fbca50 100644
@@ -77,8 +77,9 @@ XenUseUser osstest
 #DebianMirrorHost debian.uk.xensource.com
 DebianMirrorHost 10.80.16.196
 
+HostProp_NtpServer ntp.uk.xensource.com
+
 DebianPreseed= <<'END'
-d-i clock-setup/ntp-server string ntp.uk.xensource.com
 END
 
 HostProp_Serial sympathy woking
Signature · 1 line
1.7.10.4
#9 lore raw

PATCH 9/9 NTP servers: Work around Debian's failure to honour preseed

In reply to Ian Jackson

Setting clock-setup/ntp-server is not sufficient: it only takes effect in the installer (!)

I have reported this as Debian #778564. In the meantime we should work around it for current releases (including jessie, which is frozen).

For later releases, the new ntp.conf editing code arranges to bomb out if we have an NTP server configured and find it hasn't been honoured during the install.

---
 ts-host-install |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
ts-host-install +20 -0
index ae1d228..9656079 100755
@@ -119,6 +119,26 @@ END
 
     target_install_packages($ho, qw(ed));
 
+    my $ntpserver = get_target_property($ho, 'NtpServer');
+    if ($ntpserver) {
+	target_editfile_root($ho, '/etc/ntp.conf', sub {
+	    my $done= 0;
+	    while (<EI>) {
+		if (m/^server\s/) {
+		    if ($ho->{Suite} =~ m/lenny|squeeze|wheezy|jessie/) {
+			$_= $done ? "" : "server $ntpserver\n";
+		    } else {
+			m/^server \Q$ntpserver\E\s/ or
+			    die "NTP server not honoured, Debian #778564 ";
+		    }
+		    $done= 1;
+		}
+		print EO or die $!;
+	    }
+	    $done or die;
+	});
+    }
+
     target_cmd_root($ho, "update-rc.d osstest-confirm-booted start 99 2 .");
 
     logm('OK: install completed');
Signature · 1 line
1.7.10.4