add test for all modules using backup contract (#383)

Co-authored-by: ibizaman <ibizapeanut@gmail.com>
This commit is contained in:
Pierre Penninckx 2024-11-28 22:17:14 +01:00 committed by GitHub
parent cf7b25ca01
commit 34c4b75871
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 136 additions and 63 deletions

View file

@ -315,6 +315,7 @@ in
"f ${config.services.home-assistant.configDir}/automations.yaml 0755 hass hass"
"f ${config.services.home-assistant.configDir}/scenes.yaml 0755 hass hass"
"f ${config.services.home-assistant.configDir}/scripts.yaml 0755 hass hass"
"d /var/lib/hass/backups 0750 hass hass"
];
};
}

View file

@ -4,9 +4,8 @@ let
(pkgs.path + "/nixos/modules/profiles/headless.nix")
(pkgs.path + "/nixos/modules/profiles/qemu-guest.nix")
];
in
{
accessScript = {
accessScript = lib.makeOverridable ({
subdomain
, domain
, hasSSL
@ -95,9 +94,23 @@ in
lib.optionalString (script != "") ''
with subtest("extraScript"):
${indent 4 script}
'');
''));
inherit baseImports;
backupScript = args: (accessScript args).override {
extraScript = { proto_fqdn, ... }: ''
with subtest("backup"):
server.succeed("systemctl start restic-backups-testinstance_opt_repos_A")
'';
};
in
{
inherit baseImports accessScript;
mkScripts = args:
{
access = accessScript args;
backup = backupScript args;
};
base = pkgs: additionalModules: {
imports =
@ -115,6 +128,30 @@ in
networking.firewall.allowedTCPPorts = [ 80 443 ];
};
backup = backupOption: { config, ... }: {
imports = [
../modules/blocks/restic.nix
];
shb.restic.instances."testinstance" = {
request = backupOption.request;
settings = {
enable = true;
passphrase.result = config.shb.hardcodedsecret.backupPassphrase.result;
repository = {
path = "/opt/repos/A";
timerConfig = {
OnCalendar = "00:00:00";
RandomizedDelaySec = "5h";
};
};
};
};
shb.hardcodedsecret.backupPassphrase = {
request = config.shb.restic.instances."testinstance".settings.passphrase.request;
settings.content = "PassPhrase";
};
};
certs = domain: { config, ... }: {
imports = [
../modules/blocks/ssl.nix

View file

@ -9,7 +9,7 @@ let
adminPassword = "AdminPassword";
commonTestScript = testLib.accessScript {
commonTestScript = testLib.mkScripts {
inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.forgejo.ssl);
waitForServices = { ... }: [
@ -111,7 +111,23 @@ in
nodes.client = {};
testScript = commonTestScript;
testScript = commonTestScript.access;
};
backup = pkgs.testers.runNixOSTest {
name = "forgejo_backup";
nodes.server = { config, ... }: {
imports = [
base
basic
(testLib.backup config.shb.forgejo.backup)
];
};
nodes.client = {};
testScript = commonTestScript.backup;
};
https = pkgs.testers.runNixOSTest {
@ -128,7 +144,7 @@ in
nodes.client = {};
testScript = commonTestScript;
testScript = commonTestScript.access;
};
ldap = pkgs.testers.runNixOSTest {
@ -145,7 +161,7 @@ in
nodes.client = {};
testScript = commonTestScript;
testScript = commonTestScript.access;
};
sso = pkgs.testers.runNixOSTest {
@ -165,6 +181,6 @@ in
nodes.client = {};
testScript = commonTestScript;
testScript = commonTestScript.access;
};
}

View file

@ -7,7 +7,7 @@ let
subdomain = "ha";
domain = "example.com";
commonTestScript = lib.makeOverridable testLib.accessScript {
commonTestScript = testLib.mkScripts {
inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.home-assistant.ssl);
waitForServices = { ... }: [
@ -78,7 +78,23 @@ in
nodes.client = {};
testScript = commonTestScript;
testScript = commonTestScript.access;
};
backup = pkgs.testers.runNixOSTest {
name = "homeassistant_backup";
nodes.server = { config, ... }: {
imports = [
base
basic
(testLib.backup config.shb.home-assistant.backup)
];
};
nodes.client = {};
testScript = commonTestScript.backup;
};
https = pkgs.testers.runNixOSTest {
@ -95,7 +111,7 @@ in
nodes.client = {};
testScript = commonTestScript;
testScript = commonTestScript.access;
};
ldap = pkgs.testers.runNixOSTest {
@ -112,7 +128,7 @@ in
nodes.client = {};
testScript = commonTestScript;
testScript = commonTestScript.access;
};
# Not yet supported
@ -133,6 +149,6 @@ in
#
# nodes.client = {};
#
# testScript = commonTestScript;
# testScript = commonTestScript.access;
# };
}

View file

@ -7,7 +7,7 @@ let
subdomain = "j";
domain = "example.com";
commonTestScript = testLib.accessScript {
commonTestScript = testLib.mkScripts {
inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.jellyfin.ssl);
waitForServices = { ... }: [
@ -87,7 +87,23 @@ in
nodes.client = {};
testScript = commonTestScript;
testScript = commonTestScript.access;
};
backup = pkgs.testers.runNixOSTest {
name = "jellyfin_backup";
nodes.server = { config, ... }: {
imports = [
base
basic
(testLib.backup config.shb.jellyfin.backup)
];
};
nodes.client = {};
testScript = commonTestScript.backup;
};
https = pkgs.testers.runNixOSTest {
@ -104,7 +120,7 @@ in
nodes.client = {};
testScript = commonTestScript;
testScript = commonTestScript.access;
};
ldap = pkgs.testers.runNixOSTest {
@ -121,7 +137,7 @@ in
nodes.client = {};
testScript = commonTestScript;
testScript = commonTestScript.access;
};
sso = pkgs.testers.runNixOSTest {
@ -141,6 +157,6 @@ in
nodes.client = {};
testScript = commonTestScript;
testScript = commonTestScript.access;
};
}

View file

@ -11,7 +11,7 @@ let
testLib = pkgs.callPackage ../common.nix {};
commonTestScript = lib.makeOverridable testLib.accessScript {
commonTestScript = testLib.mkScripts {
inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.nextcloud.ssl);
waitForServices = { ... }: [
@ -227,7 +227,23 @@ in
nodes.client = {};
testScript = commonTestScript;
testScript = commonTestScript.access;
};
backup = pkgs.testers.runNixOSTest {
name = "nextcloud_backup";
nodes.server = { config, ... }: {
imports = [
base
basic
(testLib.backup config.shb.nextcloud.backup)
];
};
nodes.client = {};
testScript = commonTestScript.backup;
};
https = pkgs.testers.runNixOSTest {
@ -245,7 +261,7 @@ in
nodes.client = {};
# TODO: Test login
testScript = commonTestScript;
testScript = commonTestScript.access;
};
previewGenerator = pkgs.testers.runNixOSTest {
@ -263,7 +279,7 @@ in
nodes.client = {};
testScript = commonTestScript;
testScript = commonTestScript.access;
};
externalStorage = pkgs.testers.runNixOSTest {
@ -281,7 +297,7 @@ in
nodes.client = {};
testScript = commonTestScript;
testScript = commonTestScript.access;
};
ldap = pkgs.testers.runNixOSTest {
@ -300,7 +316,7 @@ in
nodes.client = {};
testScript = commonTestScript;
testScript = commonTestScript.access;
};
sso = pkgs.testers.runNixOSTest {
@ -321,6 +337,6 @@ in
nodes.client = {};
testScript = commonTestScript;
testScript = commonTestScript.access;
};
}

View file

@ -7,7 +7,7 @@ let
subdomain = "v";
domain = "example.com";
commonTestScript = lib.makeOverridable testLib.accessScript {
commonTestScript = testLib.mkScripts {
inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.vaultwarden.ssl);
waitForServices = { ... }: [
@ -93,30 +93,6 @@ let
authEndpoint = "https://${config.shb.authelia.subdomain}.${config.shb.authelia.domain}";
};
};
backup = { config, ... }: {
imports = [
../../modules/blocks/restic.nix
];
shb.restic.instances."testinstance" = {
request = config.shb.vaultwarden.backup.request;
settings = {
enable = true;
passphrase.result = config.shb.hardcodedsecret.backupPassphrase.result;
repository = {
path = "/opt/repos/A";
timerConfig = {
OnCalendar = "00:00:00";
RandomizedDelaySec = "5h";
};
};
};
};
shb.hardcodedsecret.backupPassphrase = {
request = config.shb.restic.instances."testinstance".settings.passphrase.request;
settings.content = "PassPhrase";
};
};
in
{
basic = pkgs.testers.runNixOSTest {
@ -131,7 +107,7 @@ in
nodes.client = {};
testScript = commonTestScript;
testScript = commonTestScript.access;
};
https = pkgs.testers.runNixOSTest {
@ -148,7 +124,7 @@ in
nodes.client = {};
testScript = commonTestScript;
testScript = commonTestScript.access;
};
# Not yet supported
@ -164,7 +140,7 @@ in
#
# nodes.client = {};
#
# testScript = commonTestScript;
# testScript = commonTestScript.access;
# };
sso = pkgs.testers.runNixOSTest {
@ -184,7 +160,7 @@ in
nodes.client = {};
testScript = commonTestScript.override {
testScript = commonTestScript.access.override {
waitForPorts = { node, ... }: [
8222
5432
@ -211,17 +187,12 @@ in
imports = [
base
basic
backup
(testLib.backup config.shb.vaultwarden.backup)
];
};
nodes.client = {};
testScript = commonTestScript.override {
extraScript = { proto_fqdn, ... }: ''
with subtest("backup"):
server.succeed("systemctl start restic-backups-testinstance_opt_repos_A")
'';
};
testScript = commonTestScript.backup;
};
}