Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #6394: capture git stderr/stdout #414

Merged
merged 1 commit into from
Aug 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions DEPENDENCIES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ FindBin
Getopt::Long
IO::Socket::INET6
IO::Socket::SSL
IPC::Run
JSON
LWP::UserAgent
List::MoreUtils
Expand Down
34 changes: 34 additions & 0 deletions lib/OpenQA/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use strict;
require 5.002;

use Carp;
use IPC::Run();

require Exporter;
our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
Expand All @@ -20,6 +21,7 @@ $VERSION = sprintf "%d.%03d", q$Revision: 1.12 $ =~ /(\d+)/g;
&file_content
&log_debug
&save_base64_png
&run_cmd_with_log
);


Expand Down Expand Up @@ -114,6 +116,21 @@ sub log_debug {
$app->log->debug(shift) if $app && $app->log;
}

sub log_info {
# useful for models, but doesn't work in tests
$app->log->info(shift) if $app && $app->log;
}

sub log_warning {
# useful for models, but doesn't work in tests
$app->log->warning(shift) if $app && $app->log;
}

sub log_error {
# useful for models, but doesn't work in tests
$app->log->error(shift) if $app && $app->log;
}

sub save_base64_png($$$) {
my ($dir, $newfile, $png) = @_;
return unless $newfile;
Expand All @@ -135,5 +152,22 @@ sub image_md5_filename($) {
return ($imagesdir . "/$prefix/$md5.png", $imagesdir . "/$prefix/.thumbs/$md5.png");
}

sub run_cmd_with_log($) {
my ($cmd) = @_;
my ($stdin, $stdout_err, $ret);
log_info("Running cmd: " . join(' ', @$cmd));
$ret = IPC::Run::run($cmd, \$stdin, '>&', \$stdout_err);
chomp $stdout_err;
if ($ret) {
log_debug($stdout_err);
log_info("cmd returned 0");
}
else {
log_warning($stdout_err);
log_error("cmd returned non-zero value");
}
return $ret;
}

1;
# vim: set sw=4 et:
11 changes: 6 additions & 5 deletions lib/OpenQA/WebAPI/Controller/Step.pm
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,17 @@ sub _commit_git {
}
my @git = ('git', '--git-dir', "$dir/.git", '--work-tree', $dir);
my @files = ($dir . '/' . $name . '.json', $dir . '/' . $name . '.png');
if (system(@git, 'add', @files) != 0) {

unless (run_cmd_with_log([@git, 'add', @files])) {
die "failed to git add $name";
}
my @cmd = (@git, 'commit', '-q', '-m', sprintf("%s for %s", $name, $job->name), sprintf('--author=%s <%s>', $self->current_user->fullname, $self->current_user->email), @files);
$self->app->log->debug(join(' ', @cmd));
if (system(@cmd) != 0) {

unless (run_cmd_with_log([@git, 'commit', '-q', '-m', sprintf("%s for %s", $name, $job->name), sprintf('--author=%s <%s>', $self->current_user->fullname, $self->current_user->email), @files])) {
die "failed to git commit $name";
}

if (($self->app->config->{'scm git'}->{'do_push'} || '') eq 'yes') {
if (system(@git, 'push') != 0) {
unless (run_cmd_with_log([@git, 'push'])) {
die "failed to git push $name";
}
}
Expand Down
30 changes: 30 additions & 0 deletions t/16-utils-runcmd.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env perl -w

# Copyright (C) 2015 SUSE Linux GmbH
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

BEGIN {
unshift @INC, 'lib';
}

use strict;
use OpenQA::Utils;
use Test::More;

ok(run_cmd_with_log(['echo', 'Hallo', 'Welt']));
is(run_cmd_with_log(['false']), "");

done_testing();