From: Ian Jackson Date: Tue, 22 Jan 2019 14:44:52 +0000 (+0000) Subject: power: Provide `ssh' power method X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=01c6862e604b23cb64ac36fb77758a72ac648c7a;p=osstest.git power: Provide `ssh' power method This is not really a power method but it can pretend to be one. On power off, it does nothing. On power on it logs into the host to ask it to do a hard reboot. This is rather best effort, but it is eminently suitable for our new approach/attempts arrangements because those will try another approach if ssh didn't work. Signed-off-by: Ian Jackson --- diff --git a/Osstest/PDU/ssh.pm b/Osstest/PDU/ssh.pm new file mode 100644 index 0000000..ac1eb91 --- /dev/null +++ b/Osstest/PDU/ssh.pm @@ -0,0 +1,74 @@ +# This is part of "osstest", an automated testing framework for Xen. +# Copyright (C) 2009-2013 Citrix Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + + +package Osstest::PDU::ssh; + +# This power method is used automatically, even when not configured. + +use strict; +use warnings; + +use Osstest; +use Osstest::TestSupport; + +use parent qw(Osstest::PDU::unsupported); + +our $tty; + +sub pdu_sleep_required { + return 0; +} + +sub pdu_power_state { + my ($mo, $on) = @_; + + if (!$on) { + logm("power: request to turn off via SSH method, ignored"); + return; + } + + # These games with ( )& are needed because the command to request + # a hard reboot request will not return, so the tcp connection + # carrying our ssh command request would just hang. + + my $delay = 5; + + target_cmd_root($mo->{Host}, <<'END', 60); + set -e + type reboot + exec >>/var/log/osstest-reboot.log + date + exec &1 + set -x + ( + set +e + sleep $delay + reboot -f -n -d # Linux sysvinit/systemd + reboot -nq # FreeBSD (rejects above due to -f) + )& +END + + sleep($delay); +} + +sub instantaneous { + my ($mo) = @_; + # This does not need any more sleep, if it worked. + return 1; +} + +1;