nixos-run-vms: If there is only one VM, attach stdio to its serial console

This is useful for interactive testing (quicker than logging in via
SSH and more convenient than logging in via a virtual console).
This commit is contained in:
Eelco Dolstra 2012-07-20 12:03:15 -04:00
parent 1375e7951d
commit 1cde1bdbe6
3 changed files with 10 additions and 6 deletions

View File

@ -50,6 +50,7 @@ sub new {
stateDir => "$tmpDir/vm-state-$name", stateDir => "$tmpDir/vm-state-$name",
monitor => undef, monitor => undef,
log => $args->{log}, log => $args->{log},
redirectSerial => $args->{redirectSerial} // 1,
}; };
mkdir $self->{stateDir}, 0700; mkdir $self->{stateDir}, 0700;
@ -117,10 +118,12 @@ sub start {
close $serialP; close $serialP;
close $monitorS; close $monitorS;
close $shellS; close $shellS;
if ($self->{redirectSerial}) {
open NUL, "</dev/null" or die; open NUL, "</dev/null" or die;
dup2(fileno(NUL), fileno(STDIN)); dup2(fileno(NUL), fileno(STDIN));
dup2(fileno($serialC), fileno(STDOUT)); dup2(fileno($serialC), fileno(STDOUT));
dup2(fileno($serialC), fileno(STDERR)); dup2(fileno($serialC), fileno(STDERR));
}
$ENV{TMPDIR} = $self->{stateDir}; $ENV{TMPDIR} = $self->{stateDir};
$ENV{USE_TMPDIR} = 1; $ENV{USE_TMPDIR} = 1;
$ENV{QEMU_OPTS} = $ENV{QEMU_OPTS} =

View File

@ -50,7 +50,7 @@ my $context = "";
sub createMachine { sub createMachine {
my ($args) = @_; my ($args) = @_;
my $vm = Machine->new({%{$args}, log => $log}); my $vm = Machine->new({%{$args}, log => $log, redirectSerial => ($ENV{USE_SERIAL} // "0") ne "1"});
$vms{$vm->name} = $vm; $vms{$vm->name} = $vm;
return $vm; return $vm;
} }

View File

@ -158,7 +158,8 @@ rec {
wrapProgram $out/bin/nixos-run-vms \ wrapProgram $out/bin/nixos-run-vms \
--add-flags "$vms" \ --add-flags "$vms" \
--set tests '"startAll; joinAll;"' \ --set tests '"startAll; joinAll;"' \
--set VLANS '"${toString vlans}"' --set VLANS '"${toString vlans}"' \
${lib.optionalString (builtins.length vms == 1) "--set USE_SERIAL 1"}
''; # " ''; # "
test = runTests driver; test = runTests driver;