]> xenbits.xensource.com Git - people/iwj/osstest.git/commitdiff
Serial: Factor out Osstest::Serial::keys_real
authorIan Jackson <ian.jackson@eu.citrix.com>
Tue, 10 Nov 2015 19:11:01 +0000 (19:11 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Fri, 13 Nov 2015 12:42:16 +0000 (12:42 +0000)
The sympathy and xenuse serial modules had too much in common.  Factor
out the common code, which is now responsible for
  - knowledge of the Xen console switch
  - splitting strings up into individual keys
  - timing decisions
  - error trapping and logging

This new class is an abstract base class for the concrete serial
method classes, and calls back to its derived class to prepare, send
each actual key, and shut down.

There is some functional change: notably, after failure to send the
first debug key, sending the remainder will not be attempted.

While we're here, fix a typo `dettach' to `detach'.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
v17: Move `force attach' and `force detach' writes into xenuse.pm
      where they belong.
     Add typo fix.

Osstest/Serial/keys_real.pm [new file with mode: 0644]
Osstest/Serial/sympathy.pm
Osstest/Serial/xenuse.pm

diff --git a/Osstest/Serial/keys_real.pm b/Osstest/Serial/keys_real.pm
new file mode 100644 (file)
index 0000000..80a159d
--- /dev/null
@@ -0,0 +1,65 @@
+# This is part of "osstest", an automated testing framework for Xen.
+# Copyright (C) 2015 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::Serial::keys_real;
+
+# Base class providing debug keys for real serial ports.
+# Derived class is expected to provide:
+#   $mo->keys_prepare();
+#   $mo->keys_prepare($what,$str,$pause);
+#   $mo->keys_shutdown();
+
+
+use strict;
+use warnings;
+
+use Osstest::TestSupport;
+
+sub request_debug {
+    my ($mo,$conswitch,$xenkeys,$guestkeys) = @_;
+
+    if (!eval {
+       local ($SIG{'PIPE'}) = 'IGNORE';
+
+       $mo->keys_prepare();
+
+       my $debugkeys= sub {
+           my ($what, $keys) = @_;
+           foreach my $k (split //, $keys) {
+               $mo->keys_write("$what debug info request, debug key $k",
+                               $k, 2);
+           }
+       };
+
+       $mo->keys_write('request for input to Xen', $conswitch, 1);
+       $debugkeys->('Xen', $xenkeys);
+       sleep(10);
+       $debugkeys->('guest', $guestkeys);
+       sleep(10);
+       $mo->keys_write("RET to dom0","$conswitch\r", 5);
+
+       $mo->keys_shutdown();
+
+       1;
+    }) {
+       warn "failed to send debug key(s): $@\n";
+       return 0;
+    }
+    return 1;
+}
+
+1;
index d6bf425012c1ad0c659f26eaf8b4358ec6735a10..fa34143ce34bb6c0bee93e7ebb3cbbc410537150 100644 (file)
@@ -22,12 +22,13 @@ use warnings;
 
 use Osstest;
 use Osstest::TestSupport;
+use Osstest::Serial::keys_real;
 
 BEGIN {
     use Exporter ();
     our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
     $VERSION     = 1.00;
-    @ISA         = qw(Exporter);
+    @ISA         = qw(Exporter Osstest::Serial::keys_real);
     @EXPORT      = qw();
     %EXPORT_TAGS = ( );
 
@@ -57,48 +58,28 @@ sub new {
     return bless $mo, $class;
 }
 
-sub request_debug {
-    my ($mo,$conswitch,$xenkeys,$guestkeys) = @_;
+sub keys_prepare {
+}
 
-    my $targhost= $mo->{Server};
+sub keys_write {
+    my ($mo, $what,$str,$pause) = @_;
 
+    my $targhost= $mo->{Server};
     my ($sshopts) = sshopts();
-    my $sympwrite= sub {
-        my ($what,$str,$pause) = @_;
-        logm("sympathy sending $what");
-        if (!eval {
-            local ($SIG{'PIPE'}) = 'IGNORE';
-            my $sock= $mo->{Socket};
-            my $rcmd= "sympathy -c -k $sock -N >/dev/null";
-            $rcmd= "alarm 5 $rcmd";
-            open SYMPWRITE, "|ssh @$sshopts root\@$targhost '$rcmd'" or die $!;
-            autoflush SYMPWRITE 1;
-            print SYMPWRITE $str or die $!;
-            sleep($pause);
-            close SYMPWRITE or die "$? $!";
-            1;
-        }) {
-            warn "failed to send $what: $@\n";
-            return 0;
-        }
-        return 1;
-    };
 
-    my $debugkeys= sub {
-       my ($what, $keys) = @_;
-       foreach my $k (split //, $keys) {
-           $sympwrite->("$what debug info request, debug key $k", $k, 2);
-       }
-    };
+    logm("sympathy sending $what");
 
-    $sympwrite->('request for input to Xen', $conswitch, 1);
-    $debugkeys->('Xen', $xenkeys);
-    sleep(10);
-    $debugkeys->('guest', $guestkeys);
-    sleep(10);
-    $sympwrite->("RET to dom0","$conswitch\r", 5);
+    my $sock= $mo->{Socket};
+    my $rcmd= "sympathy -c -k $sock -N >/dev/null";
+    $rcmd= "alarm 5 $rcmd";
+    open SYMPWRITE, "|ssh @$sshopts root\@$targhost '$rcmd'" or die $!;
+    autoflush SYMPWRITE 1;
+    print SYMPWRITE $str or die $!;
+    sleep($pause);
+    close SYMPWRITE or die "$? $!";
+}
 
-    return 1;
+sub keys_shutdown {
 }
 
 sub fetch_logs {
index 6b9d95538aaae6149e247e03720fe1ac958bbab8..e1270e0f9c17711ef041597b4d5f212f18c38927 100644 (file)
@@ -23,6 +23,7 @@ use warnings;
 
 use Osstest;
 use Osstest::TestSupport;
+use Osstest::Serial::keys_real;
 
 use File::Temp;
 use File::Copy;
@@ -31,7 +32,7 @@ BEGIN {
     use Exporter ();
     our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
     $VERSION     = 1.00;
-    @ISA         = qw(Exporter);
+    @ISA         = qw(Exporter Osstest::Serial::keys_real);
     @EXPORT      = qw();
     %EXPORT_TAGS = ( );
 
@@ -46,51 +47,35 @@ sub new {
     return bless $mo, $class;
 }
 
-sub request_debug {
-    my ($mo,$conswitch,$xenkeys,$guestkeys) = @_;
-    my $xenuse= $c{XenUsePath} || "xenuse";
+sub keys_prepare {
+    my ($mo) = @_;
 
     my $ho= $mo->{Host};
 
-    my $writer= sub {
-        my ($what,$str,$pause) = @_;
-        logm("xenuse sending $what");
-        if (!eval {
-            print XENUSEWRITE $str or die $!;
-            sleep($pause);
-            1;
-        }) {
-            warn "failed to send $what: $@\n";
-            return 0;
-        }
-        return 1;
-    };
-
-    my $debugkeys= sub {
-       my ($what, $keys) = @_;
-       foreach my $k (split //, $keys) {
-           $writer->("$what debug info request, debug key $k", $k, 2);
-       }
-    };
-
-    local ($SIG{'PIPE'}) = 'IGNORE';
+    my $xenuse= $c{XenUsePath} || "xenuse";
+
     open XENUSEWRITE, "|$xenuse -t $ho->{Name}" or die $!;
     autoflush XENUSEWRITE 1;
 
-    $writer->('force attach', "\x05cf", 1); # ^E c f == force attach
+    $mo->keys_write('force attach', "\x05cf", 1); # ^E c f == force attach
 
-    $writer->('request for input to Xen', $conswitch, 1);
-    $debugkeys->('Xen', $xenkeys);
-    sleep(10);
-    $debugkeys->('guest', $guestkeys);
-    sleep(10);
-    $writer->("RET to dom0","$conswitch\r", 5);
+    sleep 5;
+}
 
-    $writer->('dettach', "\x05c.", 1); # ^E c . == disconnect
+sub keys_write {
+    my ($mo, $what,$str,$pause) = @_;
+    logm("xenuse sending $what");
 
-    close XENUSEWRITE or die "$? $!";
+    print XENUSEWRITE $str or die $!;
+    sleep($pause);
+}
+
+sub keys_shutdown {
+    my ($mo) = @_;
 
-    return 1;
+    $mo->keys_write('dettach', "\x05c.", 1); # ^E c . == disconnect
+
+    close XENUSEWRITE or die "$? $!";
 }
 
 sub fetch_logs {