Merge pull request #78670 from tfc/port-installer-test
nixosTests.installer: Port installer and ZFS test to python
This commit is contained in:
commit
dd5f92f20b
|
@ -1,13 +1,17 @@
|
||||||
#! /somewhere/python3
|
#! /somewhere/python3
|
||||||
from contextlib import contextmanager, _GeneratorContextManager
|
from contextlib import contextmanager, _GeneratorContextManager
|
||||||
|
from queue import Queue, Empty
|
||||||
|
from typing import Tuple, Any, Callable, Dict, Iterator, Optional, List
|
||||||
from xml.sax.saxutils import XMLGenerator
|
from xml.sax.saxutils import XMLGenerator
|
||||||
import _thread
|
import _thread
|
||||||
import atexit
|
import atexit
|
||||||
|
import base64
|
||||||
import os
|
import os
|
||||||
|
import pathlib
|
||||||
import ptpython.repl
|
import ptpython.repl
|
||||||
import pty
|
import pty
|
||||||
from queue import Queue, Empty
|
|
||||||
import re
|
import re
|
||||||
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -15,9 +19,6 @@ import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
import unicodedata
|
import unicodedata
|
||||||
from typing import Tuple, Any, Callable, Dict, Iterator, Optional, List
|
|
||||||
import shlex
|
|
||||||
import pathlib
|
|
||||||
|
|
||||||
CHAR_TO_KEY = {
|
CHAR_TO_KEY = {
|
||||||
"A": "shift-a",
|
"A": "shift-a",
|
||||||
|
@ -566,6 +567,41 @@ class Machine:
|
||||||
if ret.returncode != 0:
|
if ret.returncode != 0:
|
||||||
raise Exception("Cannot convert screenshot")
|
raise Exception("Cannot convert screenshot")
|
||||||
|
|
||||||
|
def copy_from_host_via_shell(self, source: str, target: str) -> None:
|
||||||
|
"""Copy a file from the host into the guest by piping it over the
|
||||||
|
shell into the destination file. Works without host-guest shared folder.
|
||||||
|
Prefer copy_from_host for whenever possible.
|
||||||
|
"""
|
||||||
|
with open(source, "rb") as fh:
|
||||||
|
content_b64 = base64.b64encode(fh.read()).decode()
|
||||||
|
self.succeed(
|
||||||
|
f"mkdir -p $(dirname {target})",
|
||||||
|
f"echo -n {content_b64} | base64 -d > {target}",
|
||||||
|
)
|
||||||
|
|
||||||
|
def copy_from_host(self, source: str, target: str) -> None:
|
||||||
|
"""Copy a file from the host into the guest via the `shared_dir` shared
|
||||||
|
among all the VMs (using a temporary directory).
|
||||||
|
"""
|
||||||
|
host_src = pathlib.Path(source)
|
||||||
|
vm_target = pathlib.Path(target)
|
||||||
|
with tempfile.TemporaryDirectory(dir=self.shared_dir) as shared_td:
|
||||||
|
shared_temp = pathlib.Path(shared_td)
|
||||||
|
host_intermediate = shared_temp / host_src.name
|
||||||
|
vm_shared_temp = pathlib.Path("/tmp/shared") / shared_temp.name
|
||||||
|
vm_intermediate = vm_shared_temp / host_src.name
|
||||||
|
|
||||||
|
self.succeed(make_command(["mkdir", "-p", vm_shared_temp]))
|
||||||
|
if host_src.is_dir():
|
||||||
|
shutil.copytree(host_src, host_intermediate)
|
||||||
|
else:
|
||||||
|
shutil.copy(host_src, host_intermediate)
|
||||||
|
self.succeed("sync")
|
||||||
|
self.succeed(make_command(["mkdir", "-p", vm_target.parent]))
|
||||||
|
self.succeed(make_command(["cp", "-r", vm_intermediate, vm_target]))
|
||||||
|
# Make sure the cleanup is synced into VM
|
||||||
|
self.succeed("sync")
|
||||||
|
|
||||||
def copy_from_vm(self, source: str, target_dir: str = "") -> None:
|
def copy_from_vm(self, source: str, target_dir: str = "") -> None:
|
||||||
"""Copy a file from the VM (specified by an in-VM source path) to a path
|
"""Copy a file from the VM (specified by an in-VM source path) to a path
|
||||||
relative to `$out`. The file is copied via the `shared_dir` shared among
|
relative to `$out`. The file is copied via the `shared_dir` shared among
|
||||||
|
|
|
@ -308,6 +308,7 @@ in
|
||||||
xss-lock = handleTest ./xss-lock.nix {};
|
xss-lock = handleTest ./xss-lock.nix {};
|
||||||
yabar = handleTest ./yabar.nix {};
|
yabar = handleTest ./yabar.nix {};
|
||||||
yggdrasil = handleTest ./yggdrasil.nix {};
|
yggdrasil = handleTest ./yggdrasil.nix {};
|
||||||
|
zfs = handleTest ./zfs.nix {};
|
||||||
zsh-history = handleTest ./zsh-history.nix {};
|
zsh-history = handleTest ./zsh-history.nix {};
|
||||||
zookeeper = handleTest ./zookeeper.nix {};
|
zookeeper = handleTest ./zookeeper.nix {};
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,12 +3,10 @@
|
||||||
pkgs ? import ../.. { inherit system config; }
|
pkgs ? import ../.. { inherit system config; }
|
||||||
}:
|
}:
|
||||||
|
|
||||||
with import ../lib/testing.nix { inherit system pkgs; };
|
with import ../lib/testing-python.nix { inherit system pkgs; };
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
makeTest = import ./make-test-python.nix;
|
|
||||||
|
|
||||||
makeZfsTest = name:
|
makeZfsTest = name:
|
||||||
{ kernelPackage ? pkgs.linuxPackages_latest
|
{ kernelPackage ? pkgs.linuxPackages_latest
|
||||||
, enableUnstable ? false
|
, enableUnstable ? false
|
||||||
|
@ -20,41 +18,33 @@ let
|
||||||
maintainers = [ adisbladis ];
|
maintainers = [ adisbladis ];
|
||||||
};
|
};
|
||||||
|
|
||||||
machine = { pkgs, ... }:
|
machine = { pkgs, ... }: {
|
||||||
{
|
virtualisation.emptyDiskImages = [ 4096 ];
|
||||||
virtualisation.emptyDiskImages = [ 4096 ];
|
networking.hostId = "deadbeef";
|
||||||
networking.hostId = "deadbeef";
|
boot.kernelPackages = kernelPackage;
|
||||||
boot.kernelPackages = kernelPackage;
|
boot.supportedFilesystems = [ "zfs" ];
|
||||||
boot.supportedFilesystems = [ "zfs" ];
|
boot.zfs.enableUnstable = enableUnstable;
|
||||||
boot.zfs.enableUnstable = enableUnstable;
|
|
||||||
|
|
||||||
environment.systemPackages = with pkgs; [
|
environment.systemPackages = [ pkgs.parted ];
|
||||||
parted
|
};
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
testScript = ''
|
testScript = ''
|
||||||
machine.succeed("modprobe zfs")
|
|
||||||
machine.succeed("zpool status")
|
|
||||||
|
|
||||||
machine.succeed("ls /dev")
|
|
||||||
|
|
||||||
machine.succeed(
|
machine.succeed(
|
||||||
"mkdir /tmp/mnt",
|
"modprobe zfs",
|
||||||
|
"zpool status",
|
||||||
"udevadm settle",
|
"ls /dev",
|
||||||
"parted --script /dev/vdb mklabel msdos",
|
"mkdir /tmp/mnt",
|
||||||
"parted --script /dev/vdb -- mkpart primary 1024M -1s",
|
"udevadm settle",
|
||||||
"udevadm settle",
|
"parted --script /dev/vdb mklabel msdos",
|
||||||
|
"parted --script /dev/vdb -- mkpart primary 1024M -1s",
|
||||||
"zpool create rpool /dev/vdb1",
|
"udevadm settle",
|
||||||
"zfs create -o mountpoint=legacy rpool/root",
|
"zpool create rpool /dev/vdb1",
|
||||||
"mount -t zfs rpool/root /tmp/mnt",
|
"zfs create -o mountpoint=legacy rpool/root",
|
||||||
"udevadm settle",
|
"mount -t zfs rpool/root /tmp/mnt",
|
||||||
|
"udevadm settle",
|
||||||
"umount /tmp/mnt",
|
"umount /tmp/mnt",
|
||||||
"zpool destroy rpool",
|
"zpool destroy rpool",
|
||||||
"udevadm settle"
|
"udevadm settle",
|
||||||
)
|
)
|
||||||
'' + extraTest;
|
'' + extraTest;
|
||||||
|
|
||||||
|
@ -69,18 +59,17 @@ in {
|
||||||
enableUnstable = true;
|
enableUnstable = true;
|
||||||
extraTest = ''
|
extraTest = ''
|
||||||
machine.succeed(
|
machine.succeed(
|
||||||
"echo password | zpool create -o altroot=\"/tmp/mnt\" -O encryption=aes-256-gcm -O keyformat=passphrase rpool /dev/vdb1",
|
'echo password | zpool create -o altroot="/tmp/mnt" '
|
||||||
"zfs create -o mountpoint=legacy rpool/root",
|
+ "-O encryption=aes-256-gcm -O keyformat=passphrase rpool /dev/vdb1",
|
||||||
"mount -t zfs rpool/root /tmp/mnt",
|
"zfs create -o mountpoint=legacy rpool/root",
|
||||||
"udevadm settle",
|
"mount -t zfs rpool/root /tmp/mnt",
|
||||||
|
"udevadm settle",
|
||||||
"umount /tmp/mnt",
|
"umount /tmp/mnt",
|
||||||
"zpool destroy rpool",
|
"zpool destroy rpool",
|
||||||
"udevadm settle"
|
"udevadm settle",
|
||||||
)
|
)
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
installer = (import ./installer.nix { }).zfsroot;
|
installer = (import ./installer.nix { }).zfsroot;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue