From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Jackson Subject: [OSSTEST PATCH 3/6] ts-logs-capture: Break out guest listing and do it earlier Date: Fri, 3 Jul 2015 12:49:28 +0100 Message-ID: <1435924171-20789-3-git-send-email-ian.jackson@eu.citrix.com> References: <21910.28952.574765.545182@mariner.uk.xensource.com> <1435924171-20789-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZAzTS-0007qe-QS for xen-devel@lists.xenproject.org; Fri, 03 Jul 2015 11:49:42 +0000 In-Reply-To: <1435924171-20789-1-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org Break out the function find_guests from what was fetch_logs_host_guests, and have it save its results in the @guests global. We do this soon because in the next patch we are going to want to do something to each guest before we call serial_fetch_logs. The loop containing fetch_logs_guest is now in the main program. Signed-off-by: Ian Jackson Acked-by: Ian Campbell --- ts-logs-capture | 60 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/ts-logs-capture b/ts-logs-capture index 13795e8..7127675 100755 --- a/ts-logs-capture +++ b/ts-logs-capture @@ -33,6 +33,34 @@ our ($whhost) = @ARGV; $whhost ||= 'host'; our $ho= selecthost($whhost); +our @guests; + +sub find_guests () { + my $sth= $dbh_tests->prepare(<execute($flight, $job); + my $row; + while ($row= $sth->fetchrow_hashref) { + my $gn= $row->{name}; + $gn =~ s/_domname$//; + + my $gho= selectguest($gn,$ho); + if (!eval { + guest_find_domid($ho,$gho); + 1; + }) { + logm("cannot find domid: $@");; + next; + } + + push @guests, $gho; + } + $sth->finish(); +} + sub try_fetch_logs ($$) { my ($lho, $logfilepats) = @_; my $ok= 0; @@ -97,7 +125,7 @@ sub try_cmd_output_save ($;$) { close $fh or die $!; } -sub fetch_logs_host_guests () { +sub fetch_logs_host () { my $logs= [qw( /var/log/kern.log* /var/log/syslog* @@ -173,33 +201,13 @@ sub fetch_logs_host_guests () { ) { try_cmd_output_save($cmd); } - - my $sth= $dbh_tests->prepare(<execute($flight, $job); - my $row; - while ($row= $sth->fetchrow_hashref) { - my $gn= $row->{name}; - $gn =~ s/_domname$//; - fetch_logs_guest($gn); - } - $sth->finish(); } sub fetch_logs_guest ($) { - my ($gn) = @_; + my ($gho) = @_; + my $gn = $gho->{Name}; logm("saving logs for $gn"); - my $gho= selectguest($gn,$ho); - if (!eval { - guest_find_domid($ho,$gho); - 1; - }) { - logm("cannot find domid: $@"); - return; - } + my $consolecmd= toolstack($ho)->consolecmd($gho); try_cmd_output_save("sleep 1 | $consolecmd | cat", "guest-$gho->{Name}-console"); @@ -226,6 +234,8 @@ sub fetch_logs_guest ($) { } } +find_guests(); serial_fetch_logs($ho); -fetch_logs_host_guests(); +fetch_logs_host(); +fetch_logs_guest($_) foreach @guests; logm("logs captured to $stash"); -- 1.7.10.4