mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-03 20:33:21 +00:00
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:
parent
1375e7951d
commit
1cde1bdbe6
@ -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;
|
||||||
open NUL, "</dev/null" or die;
|
if ($self->{redirectSerial}) {
|
||||||
dup2(fileno(NUL), fileno(STDIN));
|
open NUL, "</dev/null" or die;
|
||||||
dup2(fileno($serialC), fileno(STDOUT));
|
dup2(fileno(NUL), fileno(STDIN));
|
||||||
dup2(fileno($serialC), fileno(STDERR));
|
dup2(fileno($serialC), fileno(STDOUT));
|
||||||
|
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} =
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user