3
0
Fork 0
forked from mirrors/nixpkgs

Merge pull request #72833 from marijanp/port-tests-python

Port tests to Python
This commit is contained in:
Domen Kožar 2019-11-06 13:13:12 +01:00 committed by GitHub
commit f103882328
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 142 additions and 132 deletions

View file

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ... }: import ./make-test-python.nix ({ pkgs, ... }:
{ {
name = "atd"; name = "atd";
@ -14,18 +14,18 @@ import ./make-test.nix ({ pkgs, ... }:
# "at" has a resolution of 1 minute # "at" has a resolution of 1 minute
testScript = '' testScript = ''
startAll; start_all()
$machine->waitForUnit('atd.service'); # wait for atd to start machine.wait_for_unit("atd.service") # wait for atd to start
$machine->fail("test -f ~root/at-1"); machine.fail("test -f ~root/at-1")
$machine->fail("test -f ~alice/at-1"); machine.fail("test -f ~alice/at-1")
$machine->succeed("echo 'touch ~root/at-1' | at now+1min"); machine.succeed("echo 'touch ~root/at-1' | at now+1min")
$machine->succeed("su - alice -c \"echo 'touch at-1' | at now+1min\""); machine.succeed("su - alice -c \"echo 'touch at-1' | at now+1min\"")
$machine->succeed("sleep 1.5m"); machine.succeed("sleep 1.5m")
$machine->succeed("test -f ~root/at-1"); machine.succeed("test -f ~root/at-1")
$machine->succeed("test -f ~alice/at-1"); machine.succeed("test -f ~alice/at-1")
''; '';
}) })

View file

@ -1,5 +1,5 @@
# Test whether `avahi-daemon' and `libnss-mdns' work as expected. # Test whether `avahi-daemon' and `libnss-mdns' work as expected.
import ./make-test.nix ({ pkgs, ... } : { import ./make-test-python.nix ({ pkgs, ... } : {
name = "avahi"; name = "avahi";
meta = with pkgs.stdenv.lib.maintainers; { meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ eelco ]; maintainers = [ eelco ];
@ -23,45 +23,45 @@ import ./make-test.nix ({ pkgs, ... } : {
two = cfg; two = cfg;
}; };
testScript = testScript = ''
'' startAll; start_all()
# mDNS. # mDNS.
$one->waitForUnit("network.target"); one.wait_for_unit("network.target")
$two->waitForUnit("network.target"); two.wait_for_unit("network.target")
$one->succeed("avahi-resolve-host-name one.local | tee out >&2"); one.succeed("avahi-resolve-host-name one.local | tee out >&2")
$one->succeed("test \"`cut -f1 < out`\" = one.local"); one.succeed('test "`cut -f1 < out`" = one.local')
$one->succeed("avahi-resolve-host-name two.local | tee out >&2"); one.succeed("avahi-resolve-host-name two.local | tee out >&2")
$one->succeed("test \"`cut -f1 < out`\" = two.local"); one.succeed('test "`cut -f1 < out`" = two.local')
$two->succeed("avahi-resolve-host-name one.local | tee out >&2"); two.succeed("avahi-resolve-host-name one.local | tee out >&2")
$two->succeed("test \"`cut -f1 < out`\" = one.local"); two.succeed('test "`cut -f1 < out`" = one.local')
$two->succeed("avahi-resolve-host-name two.local | tee out >&2"); two.succeed("avahi-resolve-host-name two.local | tee out >&2")
$two->succeed("test \"`cut -f1 < out`\" = two.local"); two.succeed('test "`cut -f1 < out`" = two.local')
# Basic DNS-SD. # Basic DNS-SD.
$one->succeed("avahi-browse -r -t _workstation._tcp | tee out >&2"); one.succeed("avahi-browse -r -t _workstation._tcp | tee out >&2")
$one->succeed("test `wc -l < out` -gt 0"); one.succeed("test `wc -l < out` -gt 0")
$two->succeed("avahi-browse -r -t _workstation._tcp | tee out >&2"); two.succeed("avahi-browse -r -t _workstation._tcp | tee out >&2")
$two->succeed("test `wc -l < out` -gt 0"); two.succeed("test `wc -l < out` -gt 0")
# More DNS-SD. # More DNS-SD.
$one->execute("avahi-publish -s \"This is a test\" _test._tcp 123 one=1 &"); one.execute('avahi-publish -s "This is a test" _test._tcp 123 one=1 &')
$one->sleep(5); one.sleep(5)
$two->succeed("avahi-browse -r -t _test._tcp | tee out >&2"); two.succeed("avahi-browse -r -t _test._tcp | tee out >&2")
$two->succeed("test `wc -l < out` -gt 0"); two.succeed("test `wc -l < out` -gt 0")
# NSS-mDNS. # NSS-mDNS.
$one->succeed("getent hosts one.local >&2"); one.succeed("getent hosts one.local >&2")
$one->succeed("getent hosts two.local >&2"); one.succeed("getent hosts two.local >&2")
$two->succeed("getent hosts one.local >&2"); two.succeed("getent hosts one.local >&2")
$two->succeed("getent hosts two.local >&2"); two.succeed("getent hosts two.local >&2")
# extra service definitions # extra service definitions
$one->succeed("avahi-browse -r -t _ssh._tcp | tee out >&2"); one.succeed("avahi-browse -r -t _ssh._tcp | tee out >&2")
$one->succeed("test `wc -l < out` -gt 0"); one.succeed("test `wc -l < out` -gt 0")
$two->succeed("avahi-browse -r -t _ssh._tcp | tee out >&2"); two.succeed("avahi-browse -r -t _ssh._tcp | tee out >&2")
$two->succeed("test `wc -l < out` -gt 0"); two.succeed("test `wc -l < out` -gt 0")
''; '';
}) })

View file

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ... }: { import ./make-test-python.nix ({ pkgs, ... }: {
name = "bcachefs"; name = "bcachefs";
meta.maintainers = with pkgs.stdenv.lib.maintainers; [ chiiruno ]; meta.maintainers = with pkgs.stdenv.lib.maintainers; [ chiiruno ];
@ -10,29 +10,25 @@ import ./make-test.nix ({ pkgs, ... }: {
}; };
testScript = '' testScript = ''
$machine->succeed("modprobe bcachefs"); machine.succeed("modprobe bcachefs")
$machine->succeed("bcachefs version"); machine.succeed("bcachefs version")
$machine->succeed("ls /dev"); machine.succeed("ls /dev")
$machine->succeed( machine.succeed(
"mkdir /tmp/mnt", "mkdir /tmp/mnt",
"udevadm settle",
"udevadm settle", "parted --script /dev/vdb mklabel msdos",
"parted --script /dev/vdb mklabel msdos", "parted --script /dev/vdb -- mkpart primary 1024M -1s",
"parted --script /dev/vdb -- mkpart primary 1024M -1s", "udevadm settle",
"udevadm settle", # Due to #32279, we cannot use encryption for this test yet
# "echo password | bcachefs format --encrypted /dev/vdb1",
# Due to #32279, we cannot use encryption for this test yet # "echo password | bcachefs unlock /dev/vdb1",
# "echo password | bcachefs format --encrypted /dev/vdb1", "bcachefs format /dev/vdb1",
# "echo password | bcachefs unlock /dev/vdb1", "mount -t bcachefs /dev/vdb1 /tmp/mnt",
"bcachefs format /dev/vdb1", "udevadm settle",
"mount -t bcachefs /dev/vdb1 /tmp/mnt", "bcachefs fs usage /tmp/mnt",
"udevadm settle", "umount /tmp/mnt",
"udevadm settle",
"bcachefs fs usage /tmp/mnt", )
"umount /tmp/mnt",
"udevadm settle"
);
''; '';
}) })

View file

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, lib, ... }: import ./make-test-python.nix ({ pkgs, lib, ... }:
let let
pythonEnv = pkgs.python3.withPackages (p: [p.beanstalkc]); pythonEnv = pkgs.python3.withPackages (p: [p.beanstalkc]);
@ -34,12 +34,16 @@ in
}; };
testScript = '' testScript = ''
startAll; start_all()
$machine->waitForUnit('beanstalkd.service'); machine.wait_for_unit("beanstalkd.service")
$machine->succeed("${produce}"); machine.succeed("${produce}")
$machine->succeed("${consume}") eq "this is a job\n" or die; assert "this is a job\n" == machine.succeed(
$machine->succeed("${consume}") eq "this is another job\n" or die; "${consume}"
)
assert "this is another job\n" == machine.succeed(
"${consume}"
)
''; '';
}) })

View file

@ -1,4 +1,4 @@
import ./make-test.nix { import ./make-test-python.nix {
name = "bind"; name = "bind";
machine = { pkgs, lib, ... }: { machine = { pkgs, lib, ... }: {
@ -20,8 +20,8 @@ import ./make-test.nix {
}; };
testScript = '' testScript = ''
$machine->waitForUnit('bind.service'); machine.wait_for_unit("bind.service")
$machine->waitForOpenPort(53); machine.wait_for_open_port(53)
$machine->succeed('host 192.168.0.1 127.0.0.1 | grep -qF ns.example.org'); machine.succeed("host 192.168.0.1 127.0.0.1 | grep -qF ns.example.org")
''; '';
} }

View file

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ... }: { import ./make-test-python.nix ({ pkgs, ... }: {
name = "boot-stage1"; name = "boot-stage1";
machine = { config, pkgs, lib, ... }: { machine = { config, pkgs, lib, ... }: {
@ -150,12 +150,12 @@ import ./make-test.nix ({ pkgs, ... }: {
}; };
testScript = '' testScript = ''
$machine->waitForUnit("multi-user.target"); machine.wait_for_unit("multi-user.target")
$machine->succeed('test -s /run/canary2.pid'); machine.succeed("test -s /run/canary2.pid")
$machine->fail('pgrep -a canary1'); machine.fail("pgrep -a canary1")
$machine->fail('kill -0 $(< /run/canary2.pid)'); machine.fail("kill -0 $(< /run/canary2.pid)")
$machine->succeed('pgrep -a -f \'^@canary3$\'''); machine.succeed('pgrep -a -f "^@canary3$"')
$machine->succeed('pgrep -a -f \'^kcanary$\'''); machine.succeed('pgrep -a -f "^kcanary$"')
''; '';
meta.maintainers = with pkgs.stdenv.lib.maintainers; [ aszlig ]; meta.maintainers = with pkgs.stdenv.lib.maintainers; [ aszlig ];

View file

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ... }: import ./make-test-python.nix ({ pkgs, ... }:
let let
passphrase = "supersecret"; passphrase = "supersecret";
@ -106,60 +106,70 @@ in {
}; };
testScript = '' testScript = ''
startAll; start_all()
$client->fail('test -d "${remoteRepo}"'); client.fail('test -d "${remoteRepo}"')
$client->succeed("cp ${privateKey} /root/id_ed25519"); client.succeed(
$client->succeed("chmod 0600 /root/id_ed25519"); "cp ${privateKey} /root/id_ed25519"
$client->succeed("cp ${privateKeyAppendOnly} /root/id_ed25519.appendOnly"); )
$client->succeed("chmod 0600 /root/id_ed25519.appendOnly"); client.succeed("chmod 0600 /root/id_ed25519")
client.succeed(
"cp ${privateKeyAppendOnly} /root/id_ed25519.appendOnly"
)
client.succeed("chmod 0600 /root/id_ed25519.appendOnly")
$client->succeed("mkdir -p ${dataDir}"); client.succeed("mkdir -p ${dataDir}")
$client->succeed("touch ${dataDir}/${excludeFile}"); client.succeed("touch ${dataDir}/${excludeFile}")
$client->succeed("echo '${keepFileData}' > ${dataDir}/${keepFile}"); client.succeed("echo '${keepFileData}' > ${dataDir}/${keepFile}")
subtest "local", sub { with subtest("local"):
my $borg = "BORG_PASSPHRASE='${passphrase}' borg"; borg = "BORG_PASSPHRASE='${passphrase}' borg"
$client->systemctl("start --wait borgbackup-job-local"); client.systemctl("start --wait borgbackup-job-local")
$client->fail("systemctl is-failed borgbackup-job-local"); client.fail("systemctl is-failed borgbackup-job-local")
# Make sure exactly one archive has been created # Make sure exactly one archive has been created
$client->succeed("c=\$($borg list '${localRepo}' | wc -l) && [[ \$c == '1' ]]"); assert int(client.succeed("{} list '${localRepo}' | wc -l".format(borg))) > 0
# Make sure excludeFile has been excluded # Make sure excludeFile has been excluded
$client->fail("$borg list '${localRepo}::${archiveName}' | grep -qF '${excludeFile}'"); client.fail(
# Make sure keepFile has the correct content "{} list '${localRepo}::${archiveName}' | grep -qF '${excludeFile}'".format(borg)
$client->succeed("$borg extract '${localRepo}::${archiveName}'"); )
$client->succeed('c=$(cat ${dataDir}/${keepFile}) && [[ "$c" == "${keepFileData}" ]]'); # Make sure keepFile has the correct content
# Make sure the same is true when using `borg mount` client.succeed("{} extract '${localRepo}::${archiveName}'".format(borg))
$client->succeed("mkdir -p /mnt/borg && $borg mount '${localRepo}::${archiveName}' /mnt/borg"); assert "${keepFileData}" in client.succeed("cat ${dataDir}/${keepFile}")
$client->succeed('c=$(cat /mnt/borg/${dataDir}/${keepFile}) && [[ "$c" == "${keepFileData}" ]]'); # Make sure the same is true when using `borg mount`
}; client.succeed(
"mkdir -p /mnt/borg && {} mount '${localRepo}::${archiveName}' /mnt/borg".format(
borg
)
)
assert "${keepFileData}" in client.succeed(
"cat /mnt/borg/${dataDir}/${keepFile}"
)
subtest "remote", sub { with subtest("remote"):
my $borg = "BORG_RSH='ssh -oStrictHostKeyChecking=no -i /root/id_ed25519' borg"; borg = "BORG_RSH='ssh -oStrictHostKeyChecking=no -i /root/id_ed25519' borg"
$server->waitForUnit("sshd.service"); server.wait_for_unit("sshd.service")
$client->waitForUnit("network.target"); client.wait_for_unit("network.target")
$client->systemctl("start --wait borgbackup-job-remote"); client.systemctl("start --wait borgbackup-job-remote")
$client->fail("systemctl is-failed borgbackup-job-remote"); client.fail("systemctl is-failed borgbackup-job-remote")
# Make sure we can't access repos other than the specified one # Make sure we can't access repos other than the specified one
$client->fail("$borg list borg\@server:wrong"); client.fail("{} list borg\@server:wrong".format(borg))
#TODO: Make sure that data is actually deleted # TODO: Make sure that data is actually deleted
};
subtest "remoteAppendOnly", sub { with subtest("remoteAppendOnly"):
my $borg = "BORG_RSH='ssh -oStrictHostKeyChecking=no -i /root/id_ed25519.appendOnly' borg"; borg = (
$server->waitForUnit("sshd.service"); "BORG_RSH='ssh -oStrictHostKeyChecking=no -i /root/id_ed25519.appendOnly' borg"
$client->waitForUnit("network.target"); )
$client->systemctl("start --wait borgbackup-job-remoteAppendOnly"); server.wait_for_unit("sshd.service")
$client->fail("systemctl is-failed borgbackup-job-remoteAppendOnly"); client.wait_for_unit("network.target")
client.systemctl("start --wait borgbackup-job-remoteAppendOnly")
client.fail("systemctl is-failed borgbackup-job-remoteAppendOnly")
# Make sure we can't access repos other than the specified one # Make sure we can't access repos other than the specified one
$client->fail("$borg list borg\@server:wrong"); client.fail("{} list borg\@server:wrong".format(borg))
#TODO: Make sure that data is not actually deleted
};
# TODO: Make sure that data is not actually deleted
''; '';
}) })