--- /dev/null
+# 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;
use strict qw(vars);
use Osstest;
+use Osstest::Management qw(:logs);
use Fcntl qw(:flock);
our $dryrun= 0;
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 $!;
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;
printf "(age %dd) ", $age / 86400;
- die "age $age" if $age < dircfg('MinExpireAge');
+ die "age $age" if $age < logcfg('MinExpireAge');
printf "...";
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