nixos/borgbackup: port test to python
This commit is contained in:
parent
54cc018b1e
commit
af117c388b
|
@ -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
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user