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

[Xen-devel] [OSSTEST PATCH 21/22] Serial: Factor out Osstest::Serial::keys_real



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.

Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
---
 Osstest/Serial/keys_real.pm |   69 +++++++++++++++++++++++++++++++++++++++++++
 Osstest/Serial/sympathy.pm  |   55 +++++++++++-----------------------
 Osstest/Serial/xenuse.pm    |   51 ++++++++++----------------------
 3 files changed, 102 insertions(+), 73 deletions(-)
 create mode 100644 Osstest/Serial/keys_real.pm

diff --git a/Osstest/Serial/keys_real.pm b/Osstest/Serial/keys_real.pm
new file mode 100644
index 0000000..5c0cabf
--- /dev/null
+++ b/Osstest/Serial/keys_real.pm
@@ -0,0 +1,69 @@
+# 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();
+
+       $mo->keys_write('force attach', "\x05cf", 1); # ^E c f == force attach
+
+       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_write('dettach', "\x05c.", 1); # ^E c . == disconnect
+
+       $mo->keys_shutdown();
+
+       1;
+    }) {
+       warn "failed to send debug key(s): $@\n";
+       return 0;
+    }
+    return 1;
+}
+
+1;
diff --git a/Osstest/Serial/sympathy.pm b/Osstest/Serial/sympathy.pm
index d6bf425..fa34143 100644
--- a/Osstest/Serial/sympathy.pm
+++ b/Osstest/Serial/sympathy.pm
@@ -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 {
diff --git a/Osstest/Serial/xenuse.pm b/Osstest/Serial/xenuse.pm
index 6b9d955..7db2c28 100644
--- a/Osstest/Serial/xenuse.pm
+++ b/Osstest/Serial/xenuse.pm
@@ -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,29 @@ 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
+sub keys_write {
+    my ($mo, $what,$str,$pause) = @_;
+    logm("xenuse sending $what");
 
-    $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);
+    print XENUSEWRITE $str or die $!;
+    sleep($pause);
+}
 
-    $writer->('dettach', "\x05c.", 1); # ^E c . == disconnect
+sub keys_shutdown {
+    my ($mo) = @_;
 
     close XENUSEWRITE or die "$? $!";
-
-    return 1;
 }
 
 sub fetch_logs {
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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