Merge pull request #78556 from tfc/port-tests
nixosTests: Port more tests
This commit is contained in:
commit
0ec03e182c
@ -1,12 +1,11 @@
|
||||
# Test ensures buildbot master comes up correctly and workers can connect
|
||||
|
||||
{ system ? builtins.currentSystem,
|
||||
config ? {},
|
||||
pkgs ? import ../.. { inherit system config; }
|
||||
}:
|
||||
|
||||
with import ../lib/testing.nix { inherit system pkgs; };
|
||||
|
||||
# Test ensures buildbot master comes up correctly and workers can connect
|
||||
makeTest {
|
||||
import ./make-test-python.nix {
|
||||
name = "buildbot";
|
||||
|
||||
nodes = {
|
||||
@ -39,75 +38,76 @@ makeTest {
|
||||
services.openssh.enable = true;
|
||||
networking.firewall.allowedTCPPorts = [ 22 9418 ];
|
||||
environment.systemPackages = with pkgs; [ git ];
|
||||
systemd.services.git-daemon = {
|
||||
description = "Git daemon for the test";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network.target" ];
|
||||
|
||||
serviceConfig.Restart = "always";
|
||||
path = with pkgs; [ coreutils git openssh ];
|
||||
environment = { HOME = "/root"; };
|
||||
preStart = ''
|
||||
git config --global user.name 'Nobody Fakeuser'
|
||||
git config --global user.email 'nobody\@fakerepo.com'
|
||||
rm -rvf /srv/repos/fakerepo.git /tmp/fakerepo
|
||||
mkdir -pv /srv/repos/fakerepo ~/.ssh
|
||||
ssh-keyscan -H gitrepo > ~/.ssh/known_hosts
|
||||
cat ~/.ssh/known_hosts
|
||||
|
||||
mkdir -p /src/repos/fakerepo
|
||||
cd /srv/repos/fakerepo
|
||||
rm -rf *
|
||||
git init
|
||||
echo -e '#!/bin/sh\necho fakerepo' > fakerepo.sh
|
||||
cat fakerepo.sh
|
||||
touch .git/git-daemon-export-ok
|
||||
git add fakerepo.sh .git/git-daemon-export-ok
|
||||
git commit -m fakerepo
|
||||
'';
|
||||
script = ''
|
||||
git daemon --verbose --export-all --base-path=/srv/repos --reuseaddr
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
#Start up and populate fake repo
|
||||
$gitrepo->waitForUnit("multi-user.target");
|
||||
print($gitrepo->execute(" \
|
||||
git config --global user.name 'Nobody Fakeuser' && \
|
||||
git config --global user.email 'nobody\@fakerepo.com' && \
|
||||
rm -rvf /srv/repos/fakerepo.git /tmp/fakerepo && \
|
||||
mkdir -pv /srv/repos/fakerepo ~/.ssh && \
|
||||
ssh-keyscan -H gitrepo > ~/.ssh/known_hosts && \
|
||||
cat ~/.ssh/known_hosts && \
|
||||
cd /srv/repos/fakerepo && \
|
||||
git init && \
|
||||
echo -e '#!/bin/sh\necho fakerepo' > fakerepo.sh && \
|
||||
cat fakerepo.sh && \
|
||||
touch .git/git-daemon-export-ok && \
|
||||
git add fakerepo.sh .git/git-daemon-export-ok && \
|
||||
git commit -m fakerepo && \
|
||||
git daemon --verbose --export-all --base-path=/srv/repos --reuseaddr & \
|
||||
"));
|
||||
gitrepo.wait_for_unit("git-daemon.service")
|
||||
gitrepo.wait_for_unit("multi-user.target")
|
||||
|
||||
# Test gitrepo
|
||||
$bbmaster->waitForUnit("network-online.target");
|
||||
#$bbmaster->execute("nc -z gitrepo 9418");
|
||||
print($bbmaster->execute(" \
|
||||
rm -rfv /tmp/fakerepo && \
|
||||
git clone git://gitrepo/fakerepo /tmp/fakerepo && \
|
||||
pwd && \
|
||||
ls -la && \
|
||||
ls -la /tmp/fakerepo \
|
||||
"));
|
||||
with subtest("Repo is accessible via git daemon"):
|
||||
bbmaster.wait_for_unit("network-online.target")
|
||||
bbmaster.succeed("rm -rfv /tmp/fakerepo")
|
||||
bbmaster.succeed("git clone git://gitrepo/fakerepo /tmp/fakerepo")
|
||||
|
||||
# Test start master and connect worker
|
||||
$bbmaster->waitForUnit("buildbot-master.service");
|
||||
$bbmaster->waitUntilSucceeds("curl -s --head http://bbmaster:8010") =~ /200 OK/;
|
||||
$bbworker->waitForUnit("network-online.target");
|
||||
$bbworker->execute("nc -z bbmaster 8010");
|
||||
$bbworker->execute("nc -z bbmaster 9989");
|
||||
$bbworker->waitForUnit("buildbot-worker.service");
|
||||
print($bbworker->execute("ls -la /home/bbworker/worker"));
|
||||
with subtest("Master service and worker successfully connect"):
|
||||
bbmaster.wait_for_unit("buildbot-master.service")
|
||||
bbmaster.wait_until_succeeds("curl --fail -s --head http://bbmaster:8010")
|
||||
bbworker.wait_for_unit("network-online.target")
|
||||
bbworker.succeed("nc -z bbmaster 8010")
|
||||
bbworker.succeed("nc -z bbmaster 9989")
|
||||
bbworker.wait_for_unit("buildbot-worker.service")
|
||||
|
||||
with subtest("Stop buildbot worker"):
|
||||
bbmaster.succeed("systemctl -l --no-pager status buildbot-master")
|
||||
bbmaster.succeed("systemctl stop buildbot-master")
|
||||
bbworker.fail("nc -z bbmaster 8010")
|
||||
bbworker.fail("nc -z bbmaster 9989")
|
||||
bbworker.succeed("systemctl -l --no-pager status buildbot-worker")
|
||||
bbworker.succeed("systemctl stop buildbot-worker")
|
||||
|
||||
# Test stop buildbot master and worker
|
||||
print($bbmaster->execute(" \
|
||||
systemctl -l --no-pager status buildbot-master && \
|
||||
systemctl stop buildbot-master \
|
||||
"));
|
||||
$bbworker->fail("nc -z bbmaster 8010");
|
||||
$bbworker->fail("nc -z bbmaster 9989");
|
||||
print($bbworker->execute(" \
|
||||
systemctl -l --no-pager status buildbot-worker && \
|
||||
systemctl stop buildbot-worker && \
|
||||
ls -la /home/bbworker/worker \
|
||||
"));
|
||||
|
||||
|
||||
# Test buildbot daemon mode
|
||||
$bbmaster->execute("buildbot create-master /tmp");
|
||||
$bbmaster->execute("mv -fv /tmp/master.cfg.sample /tmp/master.cfg");
|
||||
$bbmaster->execute("sed -i 's/8010/8011/' /tmp/master.cfg");
|
||||
$bbmaster->execute("buildbot start /tmp");
|
||||
$bbworker->execute("nc -z bbmaster 8011");
|
||||
$bbworker->waitUntilSucceeds("curl -s --head http://bbmaster:8011") =~ /200 OK/;
|
||||
$bbmaster->execute("buildbot stop /tmp");
|
||||
$bbworker->fail("nc -z bbmaster 8011");
|
||||
|
||||
with subtest("Buildbot daemon mode works"):
|
||||
bbmaster.succeed(
|
||||
"buildbot create-master /tmp",
|
||||
"mv -fv /tmp/master.cfg.sample /tmp/master.cfg",
|
||||
"sed -i 's/8010/8011/' /tmp/master.cfg",
|
||||
"buildbot start /tmp",
|
||||
"nc -z bbmaster 8011",
|
||||
)
|
||||
bbworker.wait_until_succeeds("curl --fail -s --head http://bbmaster:8011")
|
||||
bbmaster.wait_until_succeeds("buildbot stop /tmp")
|
||||
bbworker.fail("nc -z bbmaster 8011")
|
||||
'';
|
||||
|
||||
meta.maintainers = with pkgs.stdenv.lib.maintainers; [ nand0p ];
|
||||
}
|
||||
} {}
|
||||
|
@ -1,13 +1,5 @@
|
||||
{ system ? builtins.currentSystem
|
||||
, config ? {}
|
||||
, pkgs ? import ../.. { inherit system config; }
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (import ../lib/testing.nix { inherit system pkgs; }) makeTest;
|
||||
in
|
||||
map (
|
||||
backend: makeTest {
|
||||
f = backend: import ./make-test-python.nix ({ pkgs, ... }: {
|
||||
name = "ihatemoney-${backend}";
|
||||
machine = { lib, ... }: {
|
||||
services.ihatemoney = {
|
||||
@ -30,23 +22,34 @@ map (
|
||||
};
|
||||
};
|
||||
testScript = ''
|
||||
$machine->waitForOpenPort(8000);
|
||||
$machine->waitForUnit("uwsgi.service");
|
||||
my $return = $machine->succeed("curl -X POST http://localhost:8000/api/projects -d 'name=yay&id=yay&password=yay&contact_email=yay\@example.com'");
|
||||
die "wrong project id $return" unless "\"yay\"\n" eq $return;
|
||||
my $timestamp = $machine->succeed("stat --printf %Y /var/lib/ihatemoney/secret_key");
|
||||
my $owner = $machine->succeed("stat --printf %U:%G /var/lib/ihatemoney/secret_key");
|
||||
die "wrong ownership for the secret key: $owner, is uwsgi running as the right user ?" unless $owner eq "ihatemoney:ihatemoney";
|
||||
$machine->shutdown();
|
||||
$machine->start();
|
||||
$machine->waitForOpenPort(8000);
|
||||
$machine->waitForUnit("uwsgi.service");
|
||||
# check that the database is really persistent
|
||||
print $machine->succeed("curl --basic -u yay:yay http://localhost:8000/api/projects/yay");
|
||||
# check that the secret key is really persistent
|
||||
my $timestamp2 = $machine->succeed("stat --printf %Y /var/lib/ihatemoney/secret_key");
|
||||
die unless $timestamp eq $timestamp2;
|
||||
$machine->succeed("curl http://localhost:8000 | grep ihatemoney");
|
||||
machine.wait_for_open_port(8000)
|
||||
machine.wait_for_unit("uwsgi.service")
|
||||
|
||||
assert '"yay"' in machine.succeed(
|
||||
"curl -X POST http://localhost:8000/api/projects -d 'name=yay&id=yay&password=yay&contact_email=yay\@example.com'"
|
||||
)
|
||||
owner, timestamp = machine.succeed(
|
||||
"stat --printf %U:%G___%Y /var/lib/ihatemoney/secret_key"
|
||||
).split("___")
|
||||
assert "ihatemoney:ihatemoney" == owner
|
||||
|
||||
with subtest("Restart machine and service"):
|
||||
machine.shutdown()
|
||||
machine.start()
|
||||
machine.wait_for_open_port(8000)
|
||||
machine.wait_for_unit("uwsgi.service")
|
||||
|
||||
with subtest("check that the database is really persistent"):
|
||||
machine.succeed("curl --basic -u yay:yay http://localhost:8000/api/projects/yay")
|
||||
|
||||
with subtest("check that the secret key is really persistent"):
|
||||
timestamp2 = machine.succeed("stat --printf %Y /var/lib/ihatemoney/secret_key")
|
||||
assert timestamp == timestamp2
|
||||
|
||||
assert "ihatemoney" in machine.succeed("curl http://localhost:8000")
|
||||
'';
|
||||
}
|
||||
) [ "sqlite" "postgresql" ]
|
||||
});
|
||||
in {
|
||||
ihatemoney-sqlite = f "sqlite";
|
||||
ihatemoney-postgresql = f "postgresql";
|
||||
}
|
||||
|
@ -3,14 +3,13 @@
|
||||
pkgs ? import ../.. { inherit system config; }
|
||||
}:
|
||||
|
||||
with import ../lib/testing.nix { inherit system pkgs; };
|
||||
with import ../lib/testing-python.nix { inherit system pkgs; };
|
||||
|
||||
let
|
||||
readyFile = "/tmp/readerReady";
|
||||
resultFile = "/tmp/readerResult";
|
||||
|
||||
testReader = pkgs.writeScript "test-input-reader" ''
|
||||
#!${pkgs.stdenv.shell}
|
||||
rm -f ${resultFile} ${resultFile}.tmp
|
||||
logger "testReader: START: Waiting for $1 characters, expecting '$2'."
|
||||
touch ${readyFile}
|
||||
@ -27,56 +26,75 @@ let
|
||||
'';
|
||||
|
||||
|
||||
mkKeyboardTest = layout: { extraConfig ? {}, tests }: with pkgs.lib; let
|
||||
combinedTests = foldAttrs (acc: val: acc ++ val) [] (builtins.attrValues tests);
|
||||
perlStr = val: "'${escape ["'" "\\"] val}'";
|
||||
lq = length combinedTests.qwerty;
|
||||
le = length combinedTests.expect;
|
||||
msg = "length mismatch between qwerty (${toString lq}) and expect (${toString le}) lists!";
|
||||
send = concatMapStringsSep ", " perlStr combinedTests.qwerty;
|
||||
expect = if (lq == le) then concatStrings combinedTests.expect else throw msg;
|
||||
|
||||
in makeTest {
|
||||
mkKeyboardTest = layout: { extraConfig ? {}, tests }: with pkgs.lib; makeTest {
|
||||
name = "keymap-${layout}";
|
||||
|
||||
machine.console.keyMap = mkOverride 900 layout;
|
||||
machine.services.xserver.desktopManager.xterm.enable = false;
|
||||
machine.i18n.consoleKeyMap = mkOverride 900 layout;
|
||||
machine.services.xserver.layout = mkOverride 900 layout;
|
||||
machine.imports = [ ./common/x11.nix extraConfig ];
|
||||
|
||||
testScript = ''
|
||||
import json
|
||||
import shlex
|
||||
|
||||
sub mkTest ($$) {
|
||||
my ($desc, $cmd) = @_;
|
||||
|
||||
subtest $desc, sub {
|
||||
# prepare and start testReader
|
||||
$machine->execute("rm -f ${readyFile} ${resultFile}");
|
||||
$machine->succeed("$cmd ${testReader} ${toString le} ".q(${escapeShellArg expect} & ));
|
||||
def run_test_case(cmd, xorg_keymap, test_case_name, inputs, expected):
|
||||
with subtest(test_case_name):
|
||||
assert len(inputs) == len(expected)
|
||||
machine.execute("rm -f ${readyFile} ${resultFile}")
|
||||
|
||||
if ($desc eq "Xorg keymap") {
|
||||
# make sure the xterm window is open and has focus
|
||||
$machine->waitForWindow(qr/testterm/);
|
||||
$machine->waitUntilSucceeds("${pkgs.xdotool}/bin/xdotool search --sync --onlyvisible --class testterm windowfocus --sync");
|
||||
}
|
||||
# set up process that expects all the keys to be entered
|
||||
machine.succeed(
|
||||
"{} {} {} {} &".format(
|
||||
cmd,
|
||||
"${testReader}",
|
||||
len(inputs),
|
||||
shlex.quote("".join(expected)),
|
||||
)
|
||||
)
|
||||
|
||||
# wait for reader to be ready
|
||||
$machine->waitForFile("${readyFile}");
|
||||
$machine->sleep(1);
|
||||
if xorg_keymap:
|
||||
# make sure the xterm window is open and has focus
|
||||
machine.wait_for_window("testterm")
|
||||
machine.wait_until_succeeds(
|
||||
"${pkgs.xdotool}/bin/xdotool search --sync --onlyvisible "
|
||||
"--class testterm windowfocus --sync"
|
||||
)
|
||||
|
||||
# send all keys
|
||||
foreach ((${send})) { $machine->sendKeys($_); };
|
||||
# wait for reader to be ready
|
||||
machine.wait_for_file("${readyFile}")
|
||||
machine.sleep(1)
|
||||
|
||||
# wait for result and check
|
||||
$machine->waitForFile("${resultFile}");
|
||||
$machine->succeed("grep -q 'PASS:' ${resultFile}");
|
||||
};
|
||||
};
|
||||
# send all keys
|
||||
for key in inputs:
|
||||
machine.send_key(key)
|
||||
|
||||
$machine->waitForX;
|
||||
# wait for result and check
|
||||
machine.wait_for_file("${resultFile}")
|
||||
machine.succeed("grep -q 'PASS:' ${resultFile}")
|
||||
|
||||
mkTest "VT keymap", "openvt -sw --";
|
||||
mkTest "Xorg keymap", "DISPLAY=:0 xterm -title testterm -class testterm -fullscreen -e";
|
||||
|
||||
with open("${pkgs.writeText "tests.json" (builtins.toJSON tests)}") as json_file:
|
||||
tests = json.load(json_file)
|
||||
|
||||
keymap_environments = {
|
||||
"VT Keymap": "openvt -sw --",
|
||||
"Xorg Keymap": "DISPLAY=:0 xterm -title testterm -class testterm -fullscreen -e",
|
||||
}
|
||||
|
||||
machine.wait_for_x()
|
||||
|
||||
for keymap_env_name, command in keymap_environments.items():
|
||||
with subtest(keymap_env_name):
|
||||
for test_case_name, test_data in tests.items():
|
||||
run_test_case(
|
||||
command,
|
||||
False,
|
||||
test_case_name,
|
||||
test_data["qwerty"],
|
||||
test_data["expect"],
|
||||
)
|
||||
'';
|
||||
};
|
||||
|
||||
@ -89,7 +107,7 @@ in pkgs.lib.mapAttrs mkKeyboardTest {
|
||||
altgr.expect = [ "~" "#" "{" "[" "|" ];
|
||||
};
|
||||
|
||||
extraConfig.i18n.consoleKeyMap = "azerty/fr";
|
||||
extraConfig.console.keyMap = "azerty/fr";
|
||||
extraConfig.services.xserver.layout = "fr";
|
||||
};
|
||||
|
||||
@ -99,7 +117,7 @@ in pkgs.lib.mapAttrs mkKeyboardTest {
|
||||
homerow.expect = [ "a" "r" "s" "t" "n" "e" "i" "o" ];
|
||||
};
|
||||
|
||||
extraConfig.i18n.consoleKeyMap = "colemak/colemak";
|
||||
extraConfig.console.keyMap = "colemak/colemak";
|
||||
extraConfig.services.xserver.layout = "us";
|
||||
extraConfig.services.xserver.xkbVariant = "colemak";
|
||||
};
|
||||
@ -151,7 +169,7 @@ in pkgs.lib.mapAttrs mkKeyboardTest {
|
||||
altgr.expect = [ "@" "|" "{" "[" "]" "}" ];
|
||||
};
|
||||
|
||||
extraConfig.i18n.consoleKeyMap = "de";
|
||||
extraConfig.console.keyMap = "de";
|
||||
extraConfig.services.xserver.layout = "de";
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user