Skip to content

Commit

Permalink
Replace run_vagrant_cmd with a assert_script_run
Browse files Browse the repository at this point in the history
The function was not dying properly in the failure case as !$ret was not
evaluating to true. Actually it is just a glorified assert_script_run so let's
just use the real thing and upload the logs in post_fail_hook
  • Loading branch information
dcermak committed Dec 19, 2023
1 parent 9ef701b commit 3a165ae
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
20 changes: 4 additions & 16 deletions lib/vagrant.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use warnings;
use utils;

our @ISA = qw(Exporter);
our @EXPORT = qw(setup_vagrant_libvirt setup_vagrant_virtualbox run_vagrant_cmd);
our @EXPORT = qw(setup_vagrant_libvirt setup_vagrant_virtualbox run_vagrant_cmd $vagrant_logfile);

our $vagrant_logfile = 'vagrant_cmd.log';

sub install_vagrant {
# no need to repeat if vagrant is already installed
Expand Down Expand Up @@ -40,19 +42,5 @@ sub setup_vagrant_virtualbox {

sub run_vagrant_cmd {
my ($cmd, %args) = @_;

my $logfile = 'vagrant_cmd.log';
local $@;
my $ret = eval {
return script_run("VAGRANT_LOG=DEBUG vagrant $cmd 2> $logfile", %args);
};
return undef if $ret == 0;
if (!$ret) {
upload_logs($logfile);

if ($@) {
die $@;
}
die "'vagrant $cmd' failed with $ret";
}
assert_script_run("VAGRANT_LOG=DEBUG vagrant $cmd 2> $vagrant_logfile", %args);
}
1 change: 1 addition & 0 deletions tests/virtualization/vagrant/add_box_virtualbox.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ sub run() {
}

sub post_fail_hook() {
upload_logs($vagrant_logfile);
assert_script_run('rm -rf Vagrantfile testfile .vagrant');
}

Expand Down
4 changes: 4 additions & 0 deletions tests/virtualization/vagrant/boxes/tumbleweed.pm
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@ sub run() {
assert_script_run("popd");
}

sub post_fail_hook() {
upload_logs($vagrant_logfile);
}

1;

0 comments on commit 3a165ae

Please sign in to comment.