1
0
Fork 0

windows tests: move qemu/ssh utils into a shared file

This commit is contained in:
Astro 2019-04-13 23:33:31 +02:00 committed by Sébastien Bourdeauducq
parent 3b8c85a70a
commit b4b0ad7a22
3 changed files with 64 additions and 65 deletions

View File

@ -8,34 +8,12 @@
with pkgs; with pkgs;
let let
qemu = qemu_kvm; qemu = import ./qemu.nix {
runQemu = extraArgs: inherit pkgs qemuMem;
let diskImage = "c.img";
args = [ };
"-enable-kvm" ssh = qemu.ssh;
"-m" qemuMem scp = qemu.scp;
"-display" "none"
"-bios" "${OVMF.fd}/FV/OVMF.fd"
"-netdev" "user,id=n1,restrict=on,hostfwd=tcp::2022-:22" "-device" "e1000,netdev=n1"
];
argStr = builtins.concatStringsSep " " (args ++ extraArgs);
in "qemu-system-x86_64 ${argStr}";
sshUser = "user";
sshPassword = "user";
sshOpts = "-o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=$TMPDIR/known_hosts";
ssh = cmd: ''
echo "ssh windows \"${cmd}\""
${sshpass}/bin/sshpass -p${sshPassword} -- \
${openssh}/bin/ssh -np 2022 ${sshOpts} \
${sshUser}@localhost \
"${cmd}"
'';
scp = src: target: ''
echo "Copy ${src} to ${target}"
${sshpass}/bin/sshpass -p${sshPassword} -- \
${openssh}/bin/scp -P 2022 ${sshOpts} \
"${src}" "${sshUser}@localhost:${target}"
'';
condaEnv = "artiq-env"; condaEnv = "artiq-env";
in in
stdenv.mkDerivation { stdenv.mkDerivation {
@ -46,11 +24,11 @@ in
mkdir $out mkdir $out
''; '';
doCheck = true; doCheck = true;
checkInputs = [ qemu sshpass openssh ]; checkInputs = qemu.inputs;
checkPhase = '' checkPhase = ''
# +1 day from last modification of the disk image # +1 day from last modification of the disk image
CLOCK=$(date -Is -d @$(expr $(stat -c %Y ${diskImage}) + 86400)) CLOCK=$(date -Is -d @$(expr $(stat -c %Y ${diskImage}) + 86400))
${runQemu [ ${qemu.runQemu [
"-boot" "order=c" "-boot" "order=c"
"-snapshot" "-snapshot"
"-drive" "file=${diskImage},index=0,media=disk,cache=unsafe" "-drive" "file=${diskImage},index=0,media=disk,cache=unsafe"

View File

@ -16,34 +16,14 @@ let
sha256 = "1kyf03571fhxd0a9f8bcpmqfdpw7461kclfyb4yb3dsi783y4sck"; sha256 = "1kyf03571fhxd0a9f8bcpmqfdpw7461kclfyb4yb3dsi783y4sck";
}; };
qemu = qemu_kvm; qemu = import ./qemu.nix {
runQemu = extraArgs: inherit pkgs qemuMem;
let diskImage = "c.img";
args = [ };
"-enable-kvm" # Double-escape because we produce a script from a shell heredoc
"-m" qemuMem ssh = cmd: qemu.ssh (qemu.escape cmd);
"-bios" "${OVMF.fd}/FV/OVMF.fd" scp = qemu.scp;
"-netdev" "user,id=n1,hostfwd=tcp::2022-:22" "-device" "e1000,netdev=n1"
];
argStr = lib.escapeShellArgs (args ++ extraArgs);
in "${qemu}/bin/qemu-system-x86_64 ${argStr}";
sshUser = "user";
sshPassword = "user";
sshOpts = "-o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=\\$TMPDIR/known_hosts";
ssh = cmd: ''
echo "ssh windows \"${cmd}\""
${sshpass}/bin/sshpass -p${sshPassword} -- \
${openssh}/bin/ssh -np 2022 ${sshOpts} \
${sshUser}@localhost \
"${cmd}"
'';
scp = src: target: ''
echo "Copy ${src} to ${target}"
${sshpass}/bin/sshpass -p${sshPassword} -- \
${openssh}/bin/scp -P 2022 ${sshOpts} \
"${src}" "${sshUser}@localhost:${target}"
'';
condaEnv = "artiq-env"; condaEnv = "artiq-env";
condaDepSpecs = condaDepSpecs =
builtins.concatStringsSep " " builtins.concatStringsSep " "
@ -61,7 +41,7 @@ stdenv.mkDerivation {
unpackCmd = '' unpackCmd = ''
ln -s $curSrc windows.iso ln -s $curSrc windows.iso
''; '';
buildInputs = [ qemu openssh sshpass ]; buildInputs = qemu.inputs;
dontBuild = true; dontBuild = true;
installPhase = '' installPhase = ''
mkdir -p $out/bin $out/data mkdir -p $out/bin $out/data
@ -70,11 +50,9 @@ stdenv.mkDerivation {
#!/usr/bin/env bash #!/usr/bin/env bash
set -e -m set -e -m
TMPDIR=\$(mktemp -d)
if [ ! -f c.img ] ; then if [ ! -f c.img ] ; then
${qemu}/bin/qemu-img create -f qcow2 c.img ${diskImageSize} ${qemu.qemu-img} create -f qcow2 c.img ${diskImageSize}
${runQemu [ ${qemu.runQemu [
"-boot" "order=d" "-boot" "order=d"
"-drive" "file=c.img,index=0,media=disk,cache=unsafe" "-drive" "file=c.img,index=0,media=disk,cache=unsafe"
"-drive" "file=$out/data/windows.iso,index=1,media=cdrom,cache=unsafe" "-drive" "file=$out/data/windows.iso,index=1,media=cdrom,cache=unsafe"
@ -82,7 +60,7 @@ stdenv.mkDerivation {
echo "Please perform a Windows installation." echo "Please perform a Windows installation."
else else
echo "Please finalize your Windows installation (or delete c.img and restart)" echo "Please finalize your Windows installation (or delete c.img and restart)"
${runQemu [ ${qemu.runQemu [
"-boot" "order=c" "-boot" "order=c"
"-drive" "file=c.img,index=0,media=disk" "-drive" "file=c.img,index=0,media=disk"
]} & ]} &
@ -106,8 +84,6 @@ stdenv.mkDerivation {
echo "Waiting for qemu exit" echo "Waiting for qemu exit"
wait wait
rm -rf \$TMPDIR
EOF EOF
chmod a+x $out/bin/networked-installer.sh chmod a+x $out/bin/networked-installer.sh
''; '';

45
artiq/windows/qemu.nix Normal file
View File

@ -0,0 +1,45 @@
{ pkgs,
diskImage,
qemuMem,
sshUser ? "user",
sshPassword ? "user",
}:
with pkgs;
let
qemu = qemu_kvm;
qemu-img = "${qemu}/bin/qemu-img";
runQemu = extraArgs:
let
args = [
"-enable-kvm"
"-m" qemuMem
"-display" "none"
"-bios" "${OVMF.fd}/FV/OVMF.fd"
"-netdev" "user,id=n1,restrict=on,hostfwd=tcp::2022-:22" "-device" "e1000,netdev=n1"
];
argStr = builtins.concatStringsSep " " (args ++ extraArgs);
in "qemu-system-x86_64 ${argStr}";
escape = builtins.replaceStrings [ "\\" ] [ "\\\\" ];
sshOpts = "-o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=/tmp/known_hosts";
ssh = cmd: ''
echo ssh windows '${escape cmd}'
${sshpass}/bin/sshpass -p${sshPassword} -- \
${openssh}/bin/ssh -np 2022 ${sshOpts} \
${sshUser}@localhost \
'${escape cmd}'
'';
scp = src: target: ''
echo "Copy ${src} to ${target}"
${sshpass}/bin/sshpass -p${sshPassword} -- \
${openssh}/bin/scp -P 2022 ${sshOpts} \
"${src}" "${sshUser}@localhost:${target}"
'';
in
{
inherit qemu-img runQemu escape ssh scp;
inputs = [ qemu openssh sshpass ];
}