]> xenbits.xensource.com Git - people/aperard/osstest.git/commitdiff
WORKAROUND: TestSupport: Make target_reboot works with systemd
authorAnthony PERARD <anthony.perard@citrix.com>
Wed, 15 Nov 2017 12:31:04 +0000 (12:31 +0000)
committerAnthony PERARD <anthony.perard@citrix.com>
Thu, 12 Jul 2018 15:49:19 +0000 (16:49 +0100)
On host running with systemd as init, doing `ssh host reboot` will
result in ssh returning an error. It is likely that systemd kill sshd
before the `reboot`/`init 6` command return.

This patch works around by calling `shutdown -r` instead. By default
shutdown will have the host reboot 1 minute after invocation.

With systemd, an alternative would be to call reboot remotely:
  systemctl -H root@host reboot
That would return cleanly ($?==0) like `ssh host init 6` does without
systemd involved.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Osstest/TestSupport.pm

index c480b42948e3006cde29480f0f4054a84621cf72..3f195f1f2774fa8cda5a10cd7dc6a2e4c284d12a 100644 (file)
@@ -1347,7 +1347,17 @@ sub host_get_free_memory($) {
 
 sub target_reboot ($) {
     my ($ho) = @_;
-    target_cmd_root($ho, "init 6");
+    if (is_host_using_systemd($ho)) {
+        # systemd whould kill sshd before it had time to send the result of the
+        # command which result in the call below to fail
+        # instead, ask the host to reboot in 1 minute
+        #
+        # an alternative to reboot a host using systemd is:
+        # systemctl -H root@host reboot
+        target_cmd_root($ho, "shutdown -r");
+    } else {
+        target_cmd_root($ho, "init 6");
+    }
     target_await_down($ho, $timeout{RebootDown});
     await_tcp(get_timeout($ho,'reboot',$timeout{RebootUp}), 5,$ho);
 }
@@ -2952,6 +2962,11 @@ sub is_host_redhat_derived ($) {
         $ho->{OS} eq "centos");
 }
 
+sub is_host_using_systemd ($) {
+    my ($ho) = @_;
+    return (is_host_redhat_derived($ho) and $ho->{RedhatRelease} >= 7);
+}
+
 sub host_install_recipe_create ($) {
     my ($ho) = @_;
     if ($ho->{OS} eq "debian") {