From 337f663c13e46f815ce1f13b070b492f8d248b0c Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Tue, 2 Feb 2016 10:54:42 +0000 Subject: [PATCH] ts-fetch-check-file: new ts to fetch a file and check for corruption Compares a checksum computed on the target with one computed after cat'ting the file over ssh. Picks up on network corruption errors etc which might be missed with smaller interactions. Works for guests or hosts. To support this add a variant of target_cmd_output which returns the file descriptor instead of the actual data (which could be large), allowing us to pipe it to the local sum. Signed-off-by: Ian Campbell --- Osstest/TestSupport.pm | 10 ++++++-- ts-fetch-check-file | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100755 ts-fetch-check-file diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm index 2141905..3c287b2 100644 --- a/Osstest/TestSupport.pm +++ b/Osstest/TestSupport.pm @@ -51,6 +51,7 @@ BEGIN { target_cmd_root target_cmd target_cmd_build target_cmd_output_root target_cmd_output + target_cmd_stdoutfd target_cmd_stdoutfd_root target_cmd_inputfh_root sshuho target_getfile target_getfile_root target_putfile target_putfile_root @@ -646,9 +647,11 @@ sub target_cmd ($$;$$) { tcmd(undef,undef,'osstest',@_); } sub target_cmd_root ($$;$$) { tcmd(undef,undef,'root',@_); } sub tcmdout { + my $wantfd = shift; my $stdout= IO::File::new_tmpfile(); tcmd(undef,$stdout,@_); $stdout->seek(0,0) or die "$stdout $!"; + return $stdout if $wantfd; my $r; { local ($/) = undef; $r= <$stdout>; } @@ -657,8 +660,11 @@ sub tcmdout { return $r; } -sub target_cmd_output ($$;$) { tcmdout('osstest',@_); } -sub target_cmd_output_root ($$;$) { tcmdout('root',@_); } +sub target_cmd_output ($$;$) { tcmdout(0,'osstest',@_); } +sub target_cmd_output_root ($$;$) { tcmdout(0,'root',@_); } + +sub target_cmd_stdoutfd ($$;$$) { tcmdout(1,'osstest',@_); } +sub target_cmd_stdoutfd_root ($$;$$) { tcmdout(1,'root',@_); } sub target_cmd_inputfh_root ($$$;$$) { my ($tho,$stdinfh,$tcmd,@rest) = @_; diff --git a/ts-fetch-check-file b/ts-fetch-check-file new file mode 100755 index 0000000..bfceb6b --- /dev/null +++ b/ts-fetch-check-file @@ -0,0 +1,68 @@ +#!/usr/bin/perl -w +# This is part of "osstest", an automated testing framework for Xen. +# Copyright (C) 2016 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 . + +use strict qw(vars); +use DBI; +use Osstest; +use Osstest::TestSupport; + +use IO::Pipe; + +tsreadconfig(); + +our ($whhost,$guest) = @ARGV; +$whhost ||= 'host'; + +our ($ho,$gho); +our $fn = "/bin/bash"; # reasonable size, present in most guests and hosts + +$ho= selecthost($whhost); +$gho= selectguest($guest,$ho) if $guest; + +sub fetch_and_check_file ($$) { + my ($t,$fn) = @_; + + target_check_ip($t); + + target_cmd_root($t, "ls -lH $fn"); + + my $expect = target_cmd_output_root($t,"sum $fn"); + logm($expect); + + my $stdout= target_cmd_stdoutfd_root($t,"cat $fn",5,[qw(-v)]); + + my $pipe= IO::Pipe->new(); + my $child= fork; die $! unless defined $child; + if (!$child) { + $pipe->writer(); + open STDIN, "<&", $stdout or die "STDIN $!"; + open STDOUT, ">&", $pipe or die "STDOUT $!"; + exec("sum") or die "pipe writer $!"; + } + + $pipe->reader(); + + my $got = <$pipe>; + chomp($got); + + logm("expected $expect"); + logm("got $got"); + + die unless $expect eq $got; +} + +fetch_and_check_file($gho ? $gho : $ho, $fn); -- 2.6.1