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

[Xen-devel] [OSSTEST PATCH 3/5] Logs: Break out logs_select etc. into new Osstest::Management



We are going to want to reuse these minor bits of
cr-ensure-disk-space.  Break them out into a new perl module.

We also need to rename some things to make them have names more
suitable for a wider namespace, even if only selectively exported:
 * @logsshopts from @sshopts (it is not the same variable as
   Osstest::TestSupport::sshopts).
 * $loghost and $logdir from $pubhost and $pubdir).
 * onloghost from ontarget.
 * logcfg from dircfg.

Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
---
 Osstest/Management.pm |   72 +++++++++++++++++++++++++++++++++++++++++++++++++
 cr-ensure-disk-space  |   42 +++++++----------------------
 2 files changed, 81 insertions(+), 33 deletions(-)
 create mode 100644 Osstest/Management.pm

diff --git a/Osstest/Management.pm b/Osstest/Management.pm
new file mode 100644
index 0000000..2c875a7
--- /dev/null
+++ b/Osstest/Management.pm
@@ -0,0 +1,72 @@
+# 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::Management;
+
+use strict;
+use warnings;
+
+use Osstest;
+
+BEGIN {
+    use Exporter ();
+    our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
+    $VERSION     = 1.00;
+    @ISA         = qw(Exporter);
+    @EXPORT      = qw(
+                      );
+    %EXPORT_TAGS = (
+       'logs' => [qw(logs_select onloghost logcfg
+                      $logcfgbase $loghost $logdir @logsshopts)]
+                   );
+
+    @EXPORT_OK   = qw();
+
+    Exporter::export_ok_tags(qw(logs));
+}
+
+our ($logcfgbase, $loghost, $logdir);
+our @logsshopts= qw(-o batchmode=yes);
+
+sub logs_select ($) {
+    ($logcfgbase) = @_;
+    my $cfgvalue = $c{$logcfgbase};
+    return 0 unless $cfgvalue;
+    if ($cfgvalue =~ m/\:/) {
+       ($loghost, $logdir) = ($`,$'); #');
+    } else {
+       ($loghost, $logdir) = (undef, $cfgvalue);
+    }
+    return 1;
+}
+
+sub onloghost ($) {
+    my ($shellcmd) = @_;
+    # returns list to run that command
+    if (defined $loghost) {
+       return qw(ssh -n), @logsshopts, $loghost, $shellcmd;
+    } else {
+       return qw(sh -ec), $shellcmd;
+    }
+}
+
+sub logcfg ($) {
+    my ($k) = @_;
+    return $c{"${logcfgbase}${k}"} // $c{"Logs${k}"};
+}
+
+1;
diff --git a/cr-ensure-disk-space b/cr-ensure-disk-space
index 3788e63..304f262 100755
--- a/cr-ensure-disk-space
+++ b/cr-ensure-disk-space
@@ -22,6 +22,7 @@
 
 use strict qw(vars);
 use Osstest;
+use Osstest::Management qw(:logs);
 use Fcntl qw(:flock);
 
 our $dryrun= 0;
@@ -42,7 +43,7 @@ our ($cfgbase) = @ARGV;
 
 csreadconfig();
 
-exit 0 unless $c{$cfgbase};
+logs_select $cfgbase or exit 0;
 
 open LOCK, "> $c{GlobalLockDir}/publish-lock" or die $!;
 flock LOCK, LOCK_EX or die $!;
@@ -51,45 +52,20 @@ $|=1;
 
 my $chkq= $dbh_tests->prepare("SELECT * FROM flights WHERE flight=?");
 our @flights;
-our @sshopts= qw(-o batchmode=yes);
-
-my $cfgvalue = $c{$cfgbase};
-
-my ($pubhost, $pubdir);
-if ($cfgvalue =~ m/\:/) {
-    ($pubhost, $pubdir) = ($`,$'); #');
-} else {
-    ($pubhost, $pubdir) = (undef, $cfgvalue);
-}
-
-sub ontarget ($) {
-    my ($shellcmd) = @_;
-    # returns list to run that command
-    if (defined $pubhost) {
-       return qw(ssh -n), @sshopts, $pubhost, $shellcmd;
-    } else {
-       return qw(sh -ec), $shellcmd;
-    }
-}
-
-sub dircfg ($) {
-    my ($k) = @_;
-    return $c{"${cfgbase}${k}"} // $c{"Logs${k}"};
-}
 
 for (;;) {
-    open P, "-|", ontarget "df --block-size=1M -P $pubdir" or die $!;
+    open P, "-|", onloghost "df --block-size=1M -P $logdir" or die $!;
     $_= <P>;
     m/^filesystem/i or die "$_ ?";
     $_= <P>;
     m,^\S+\s+\d+\s+\d+\s+(\d+)\s+, or die "$_ ?";
     $!=0; $?=0; close P or die "$! $?";
     my $space= $1;
-    printf "space: %8d, wanted: %8d ", $space, dircfg('MinSpaceMby');
-    last if $space >= dircfg('MinSpaceMby');
+    printf "space: %8d, wanted: %8d ", $space, logcfg('MinSpaceMby');
+    last if $space >= logcfg('MinSpaceMby');
 
     if (!@flights) {
-       open P, "-|", ontarget "ls -1 $pubdir" or die $!;
+       open P, "-|", onloghost "ls -1 $logdir" or die $!;
        while (<P>) {
            next unless m/^(\d+)\n$/;
            push @flights, $1;
@@ -110,7 +86,7 @@ for (;;) {
 
     printf "(age %dd) ", $age / 86400;
 
-    die "age $age" if $age < dircfg('MinExpireAge');
+    die "age $age" if $age < logcfg('MinExpireAge');
 
     printf "...";
 
@@ -119,9 +95,9 @@ for (;;) {
     my $spawn= sub {
         $!=0; my $r= system @_; die "@_ $r $!" if $r;
     };
-    $spawn->(ontarget <<END);
+    $spawn->(onloghost <<END);
              set -e
-             cd $pubdir
+             cd $logdir
              test -e $flight || exit 0
              printf remote...
              rm -rf $flight
-- 
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®.