nixos/rkvm: add nixos test

This commit is contained in:
h7x4 2023-10-05 14:32:38 +02:00 committed by ckie
parent f3ad4def37
commit 2295751a5a
No known key found for this signature in database
GPG Key ID: 13E79449C0525215
5 changed files with 156 additions and 0 deletions

View File

@ -673,6 +673,7 @@ in {
restartByActivationScript = handleTest ./restart-by-activation-script.nix {};
restic = handleTest ./restic.nix {};
retroarch = handleTest ./retroarch.nix {};
rkvm = handleTest ./rkvm {};
robustirc-bridge = handleTest ./robustirc-bridge.nix {};
roundcube = handleTest ./roundcube.nix {};
rshim = handleTest ./rshim.nix {};

18
nixos/tests/rkvm/cert.pem Normal file
View File

@ -0,0 +1,18 @@
-----BEGIN CERTIFICATE-----
MIIC3jCCAcagAwIBAgIUWW1hb9xdRtxAhA42jkS89goW9LUwDQYJKoZIhvcNAQEL
BQAwDzENMAsGA1UEAwwEcmt2bTAeFw0yMzA4MjIxOTI1NDlaFw0zMzA4MTkxOTI1
NDlaMA8xDTALBgNVBAMMBHJrdm0wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK
AoIBAQCuBsh0+LDXN4b2o/PJjzuiZ9Yv9Pz1Oho9WRiXtNIuHTRdBCcht/iu3PGF
ICIX+H3dqQOziGSCTAQGJD2p+1ik8d+boJbpa0oxXuHuomsMAT3mib3GpipQoBLP
KaEbWEsvQbr3RMx8WOtG4dmRQFzSVVtmAXyM0pNyisd4eUCplyIl9gsRJIvsO/0M
OkgOZW9XLfKiAWlZoyXEkBmPAshg3EkwQtmwxPA/NgWbAOW3zJKSChxnnGYiuIIu
R/wJ8OQXHP6boQLQGUhCWBKa1uK1gEBmV3Pj6uK8RzTkQq6/47F5sPa6VfqQYdyl
TCs9bSqHXZjqMBoiSp22uH6+Lh9RAgMBAAGjMjAwMA8GA1UdEQQIMAaHBAoAAAEw
HQYDVR0OBBYEFEh9HEsnY3dfNKVyPWDbwfR0qHopMA0GCSqGSIb3DQEBCwUAA4IB
AQB/r+K20JqegUZ/kepPxIU95YY81aUUoxvLbu4EAgh8o46Fgm75qrTZPg4TaIZa
wtVejekrF+p3QVf0ErUblh/iCjTZPSzCmKHZt8cc9OwTH7bt3bx7heknzLDyIa5z
szAL+6241UggQ5n5NUGn5+xZHA7TMe47xAZPaRMlCQ/tp5pWFjH6WSSQSP5t4Ag9
ObhY+uudFjmWi3QIBTr3iIscbWx7tD8cjus7PzM7+kszSDRV04xb6Ox8JzW9MKIN
GwgwVgs3zCuyqBmTGnR1og3aMk6VtlyZUYE78uuc+fMBxqoBZ0mykeOp0Tbzgtf7
gPkYcQ6vonoQhuTXYj/NrY+b
-----END CERTIFICATE-----

View File

@ -0,0 +1,104 @@
import ../make-test-python.nix ({ pkgs, ... }:
let
# Generated with
#
# nix shell .#rkvm --command "rkvm-certificate-gen --ip-addresses 10.0.0.1 cert.pem key.pem"
#
snakeoil-cert = ./cert.pem;
snakeoil-key = ./key.pem;
in
{
name = "rkvm";
nodes = {
server = { pkgs, ... }: {
imports = [ ../common/user-account.nix ];
virtualisation.vlans = [ 1 ];
networking = {
useNetworkd = true;
useDHCP = false;
firewall.enable = false;
};
systemd.network.networks."01-eth1" = {
name = "eth1";
networkConfig.Address = "10.0.0.1/24";
};
services.getty.autologinUser = "alice";
services.rkvm.server = {
enable = true;
settings = {
certificate = snakeoil-cert;
key = snakeoil-key;
password = "snakeoil";
switch-keys = [ "left-alt" "right-alt" ];
};
};
};
client = { pkgs, ... }: {
imports = [ ../common/user-account.nix ];
virtualisation.vlans = [ 1 ];
networking = {
useNetworkd = true;
useDHCP = false;
firewall.enable = false;
};
systemd.network.networks."01-eth1" = {
name = "eth1";
networkConfig.Address = "10.0.0.2/24";
};
services.getty.autologinUser = "alice";
services.rkvm.client = {
enable = true;
settings = {
server = "10.0.0.1:5258";
certificate = snakeoil-cert;
key = snakeoil-key;
password = "snakeoil";
};
};
};
};
testScript = ''
server.wait_for_unit("getty@tty1.service")
server.wait_until_succeeds("pgrep -f 'agetty.*tty1'")
server.wait_for_unit("rkvm-server")
server.wait_for_open_port(5258)
client.wait_for_unit("getty@tty1.service")
client.wait_until_succeeds("pgrep -f 'agetty.*tty1'")
client.wait_for_unit("rkvm-client")
server.sleep(1)
# Switch to client
server.send_key("alt-alt_r", delay=0.2)
server.send_chars("echo 'hello client' > /tmp/test.txt\n")
# Switch to server
server.send_key("alt-alt_r", delay=0.2)
server.send_chars("echo 'hello server' > /tmp/test.txt\n")
server.sleep(1)
client.systemctl("stop rkvm-client.service")
server.systemctl("stop rkvm-server.service")
server_file = server.succeed("cat /tmp/test.txt")
assert server_file.strip() == "hello server"
client_file = client.succeed("cat /tmp/test.txt")
assert client_file.strip() == "hello client"
'';
})

28
nixos/tests/rkvm/key.pem Normal file
View File

@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCuBsh0+LDXN4b2
o/PJjzuiZ9Yv9Pz1Oho9WRiXtNIuHTRdBCcht/iu3PGFICIX+H3dqQOziGSCTAQG
JD2p+1ik8d+boJbpa0oxXuHuomsMAT3mib3GpipQoBLPKaEbWEsvQbr3RMx8WOtG
4dmRQFzSVVtmAXyM0pNyisd4eUCplyIl9gsRJIvsO/0MOkgOZW9XLfKiAWlZoyXE
kBmPAshg3EkwQtmwxPA/NgWbAOW3zJKSChxnnGYiuIIuR/wJ8OQXHP6boQLQGUhC
WBKa1uK1gEBmV3Pj6uK8RzTkQq6/47F5sPa6VfqQYdylTCs9bSqHXZjqMBoiSp22
uH6+Lh9RAgMBAAECggEABo2V1dBu5E51zsAiFCMdypdLZEyUNphvWC5h3oXowONz
pH8ICYfXyEnkma/kk2+ALy0dSRDn6/94dVIUX7Fpx0hJCcoJyhSysK+TJWfIonqX
ffYOMeFG8vicIgs+GFKs/hoPtB5LREbFkUqRj/EoWE6Y3aX3roaCwTZC8vaUk0OK
54gExcNXRwQtFmfM9BiPT76F2J641NVsddgKumrryMi605CgZ57OFfSYEena6T3t
JbQ1TKB3SH1LvSQIspy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
@ -31,6 +32,10 @@ rustPlatform.buildRustPackage rec {
wrapProgram $out/bin/rkvm-certificate-gen --prefix PATH : ${lib.makeBinPath [ openssl ]}
'';
passthru.tests = {
inherit (nixosTests) rkvm;
};
meta = with lib; {
description = "Virtual KVM switch for Linux machines";
homepage = "https://github.com/htrefil/rkvm";