From: Anthony PERARD Date: Wed, 15 Nov 2017 12:31:04 +0000 (+0000) Subject: WORKAROUND: TestSupport: Make target_reboot works with systemd X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=6eb8135f9e12d4f1f62bdd6fb6f72eabb7b7ef8d;p=people%2Faperard%2Fosstest.git WORKAROUND: TestSupport: Make target_reboot works with systemd 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 --- diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm index c480b429..3f195f1f 100644 --- a/Osstest/TestSupport.pm +++ b/Osstest/TestSupport.pm @@ -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") {