borgbackup: migrate to clan.nixosTests module
This commit is contained in:
@@ -1,17 +1,18 @@
|
|||||||
{ lib, self, ... }:
|
{ lib, ... }:
|
||||||
|
let
|
||||||
|
module = lib.modules.importApply ./default.nix { };
|
||||||
|
in
|
||||||
{
|
{
|
||||||
clan.modules = {
|
clan.modules = {
|
||||||
borgbackup = lib.modules.importApply ./default.nix { };
|
borgbackup = module;
|
||||||
};
|
};
|
||||||
perSystem =
|
perSystem =
|
||||||
{ pkgs, ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
checks = lib.optionalAttrs (pkgs.stdenv.isLinux) {
|
clan.nixosTests.borgbackup = {
|
||||||
borgbackup = import ./tests/vm/default.nix {
|
imports = [ ./tests/vm/default.nix ];
|
||||||
inherit pkgs;
|
|
||||||
clan-core = self;
|
clan.modules."@clan/borgbackup" = module;
|
||||||
nixosLib = import (self.inputs.nixpkgs + "/nixos/lib") { };
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,118 +1,112 @@
|
|||||||
{
|
{
|
||||||
|
module,
|
||||||
pkgs,
|
pkgs,
|
||||||
nixosLib,
|
|
||||||
clan-core,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
nixosLib.runTest (
|
{
|
||||||
{ ... }:
|
name = "borgbackup";
|
||||||
{
|
|
||||||
imports = [
|
|
||||||
clan-core.modules.nixosVmTest.clanTest
|
|
||||||
];
|
|
||||||
|
|
||||||
hostPkgs = pkgs;
|
clan = {
|
||||||
|
directory = ./.;
|
||||||
|
test.useContainers = true;
|
||||||
|
inventory = {
|
||||||
|
|
||||||
name = "borgbackup";
|
machines.clientone = { };
|
||||||
|
machines.serverone = { };
|
||||||
|
|
||||||
clan = {
|
instances = {
|
||||||
directory = ./.;
|
borgone = {
|
||||||
test.useContainers = true;
|
|
||||||
modules."@clan/borgbackup" = ../../default.nix;
|
|
||||||
inventory = {
|
|
||||||
|
|
||||||
machines.clientone = { };
|
module.name = "@clan/borgbackup";
|
||||||
machines.serverone = { };
|
|
||||||
|
|
||||||
instances = {
|
roles.client.machines."clientone" = { };
|
||||||
borgone = {
|
roles.server.machines."serverone".settings.directory = "/tmp/borg-test";
|
||||||
|
|
||||||
module.name = "@clan/borgbackup";
|
|
||||||
|
|
||||||
roles.client.machines."clientone" = { };
|
|
||||||
roles.server.machines."serverone".settings.directory = "/tmp/borg-test";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
nodes = {
|
nodes = {
|
||||||
|
|
||||||
|
serverone = {
|
||||||
|
services.openssh.enable = true;
|
||||||
|
# Needed so PAM doesn't see the user as locked
|
||||||
|
users.users.borg.password = "borg";
|
||||||
|
};
|
||||||
|
|
||||||
|
clientone =
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
clan-core,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
dependencies = [
|
||||||
|
clan-core
|
||||||
|
pkgs.stdenv.drvPath
|
||||||
|
] ++ builtins.map (i: i.outPath) (builtins.attrValues clan-core.inputs);
|
||||||
|
closureInfo = pkgs.closureInfo { rootPaths = dependencies; };
|
||||||
|
|
||||||
|
in
|
||||||
|
{
|
||||||
|
|
||||||
serverone = {
|
|
||||||
services.openssh.enable = true;
|
services.openssh.enable = true;
|
||||||
# Needed so PAM doesn't see the user as locked
|
|
||||||
users.users.borg.password = "borg";
|
users.users.root.openssh.authorizedKeys.keyFiles = [ ../../../../checks/assets/ssh/pubkey ];
|
||||||
|
|
||||||
|
clan.core.networking.targetHost = config.networking.hostName;
|
||||||
|
|
||||||
|
environment.systemPackages = [ clan-core.packages.${pkgs.system}.clan-cli ];
|
||||||
|
|
||||||
|
environment.etc.install-closure.source = "${closureInfo}/store-paths";
|
||||||
|
nix.settings = {
|
||||||
|
substituters = pkgs.lib.mkForce [ ];
|
||||||
|
hashed-mirrors = null;
|
||||||
|
connect-timeout = pkgs.lib.mkForce 3;
|
||||||
|
flake-registry = pkgs.writeText "flake-registry" ''{"flakes":[],"version":2}'';
|
||||||
|
};
|
||||||
|
system.extraDependencies = dependencies;
|
||||||
|
|
||||||
|
clan.core.state.test-backups.folders = [ "/var/test-backups" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
clientone =
|
};
|
||||||
{ config, pkgs, ... }:
|
|
||||||
let
|
|
||||||
dependencies = [
|
|
||||||
clan-core
|
|
||||||
pkgs.stdenv.drvPath
|
|
||||||
] ++ builtins.map (i: i.outPath) (builtins.attrValues clan-core.inputs);
|
|
||||||
closureInfo = pkgs.closureInfo { rootPaths = dependencies; };
|
|
||||||
|
|
||||||
in
|
testScript = ''
|
||||||
{
|
import json
|
||||||
|
start_all()
|
||||||
|
|
||||||
services.openssh.enable = true;
|
machines = [clientone, serverone]
|
||||||
|
|
||||||
users.users.root.openssh.authorizedKeys.keyFiles = [ ../../../../checks/assets/ssh/pubkey ];
|
for m in machines:
|
||||||
|
m.systemctl("start network-online.target")
|
||||||
|
|
||||||
clan.core.networking.targetHost = config.networking.hostName;
|
for m in machines:
|
||||||
|
m.wait_for_unit("network-online.target")
|
||||||
|
|
||||||
environment.systemPackages = [ clan-core.packages.${pkgs.system}.clan-cli ];
|
# dummy data
|
||||||
|
clientone.succeed("mkdir -p /var/test-backups /var/test-service")
|
||||||
|
clientone.succeed("echo testing > /var/test-backups/somefile")
|
||||||
|
|
||||||
environment.etc.install-closure.source = "${closureInfo}/store-paths";
|
clientone.succeed("${pkgs.coreutils}/bin/install -Dm 600 ${../../../../checks/assets/ssh/privkey} /root/.ssh/id_ed25519")
|
||||||
nix.settings = {
|
clientone.succeed("${pkgs.coreutils}/bin/touch /root/.ssh/known_hosts")
|
||||||
substituters = pkgs.lib.mkForce [ ];
|
clientone.wait_until_succeeds("timeout 2 ssh -o StrictHostKeyChecking=accept-new localhost hostname")
|
||||||
hashed-mirrors = null;
|
clientone.wait_until_succeeds("timeout 2 ssh -o StrictHostKeyChecking=accept-new $(hostname) hostname")
|
||||||
connect-timeout = pkgs.lib.mkForce 3;
|
|
||||||
flake-registry = pkgs.writeText "flake-registry" ''{"flakes":[],"version":2}'';
|
|
||||||
};
|
|
||||||
system.extraDependencies = dependencies;
|
|
||||||
|
|
||||||
clan.core.state.test-backups.folders = [ "/var/test-backups" ];
|
# create
|
||||||
};
|
clientone.succeed("borgbackup-create >&2")
|
||||||
|
clientone.wait_until_succeeds("! systemctl is-active borgbackup-job-serverone >&2")
|
||||||
|
|
||||||
};
|
# list
|
||||||
|
backup_id = json.loads(clientone.succeed("borg-job-serverone list --json"))["archives"][0]["archive"]
|
||||||
|
out = clientone.succeed("borgbackup-list").strip()
|
||||||
|
print(out)
|
||||||
|
assert backup_id in out, f"backup {backup_id} not found in {out}"
|
||||||
|
|
||||||
testScript = ''
|
# borgbackup restore
|
||||||
import json
|
clientone.succeed("rm -f /var/test-backups/somefile")
|
||||||
start_all()
|
clientone.succeed(f"NAME='serverone::borg@serverone:.::{backup_id}' borgbackup-restore >&2")
|
||||||
|
assert clientone.succeed("cat /var/test-backups/somefile").strip() == "testing", "restore failed"
|
||||||
machines = [clientone, serverone]
|
'';
|
||||||
|
}
|
||||||
for m in machines:
|
|
||||||
m.systemctl("start network-online.target")
|
|
||||||
|
|
||||||
for m in machines:
|
|
||||||
m.wait_for_unit("network-online.target")
|
|
||||||
|
|
||||||
# dummy data
|
|
||||||
clientone.succeed("mkdir -p /var/test-backups /var/test-service")
|
|
||||||
clientone.succeed("echo testing > /var/test-backups/somefile")
|
|
||||||
|
|
||||||
clientone.succeed("${pkgs.coreutils}/bin/install -Dm 600 ${../../../../checks/assets/ssh/privkey} /root/.ssh/id_ed25519")
|
|
||||||
clientone.succeed("${pkgs.coreutils}/bin/touch /root/.ssh/known_hosts")
|
|
||||||
clientone.wait_until_succeeds("timeout 2 ssh -o StrictHostKeyChecking=accept-new localhost hostname")
|
|
||||||
clientone.wait_until_succeeds("timeout 2 ssh -o StrictHostKeyChecking=accept-new $(hostname) hostname")
|
|
||||||
|
|
||||||
# create
|
|
||||||
clientone.succeed("borgbackup-create >&2")
|
|
||||||
clientone.wait_until_succeeds("! systemctl is-active borgbackup-job-serverone >&2")
|
|
||||||
|
|
||||||
# list
|
|
||||||
backup_id = json.loads(clientone.succeed("borg-job-serverone list --json"))["archives"][0]["archive"]
|
|
||||||
out = clientone.succeed("borgbackup-list").strip()
|
|
||||||
print(out)
|
|
||||||
assert backup_id in out, f"backup {backup_id} not found in {out}"
|
|
||||||
|
|
||||||
# borgbackup restore
|
|
||||||
clientone.succeed("rm -f /var/test-backups/somefile")
|
|
||||||
clientone.succeed(f"NAME='serverone::borg@serverone:.::{backup_id}' borgbackup-restore >&2")
|
|
||||||
assert clientone.succeed("cat /var/test-backups/somefile").strip() == "testing", "restore failed"
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user