[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [OSSTEST PATCH 12/26] 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 <ian.jackson@xxxxxxxxxxxxx>
---
 Osstest/PDU/ssh.pm | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 Osstest/PDU/ssh.pm

diff --git a/Osstest/PDU/ssh.pm b/Osstest/PDU/ssh.pm
new file mode 100644
index 00000000..ac1eb919
--- /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 <http://www.gnu.org/licenses/>.
+
+
+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 </dev/null 2>&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;
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.