add test for all modules using backup contract

This commit is contained in:
ibizaman 2024-11-28 21:54:21 +01:00
parent cf7b25ca01
commit 42287ff47c
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}/automations.yaml 0755 hass hass"
"f ${config.services.home-assistant.configDir}/scenes.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" "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/headless.nix")
(pkgs.path + "/nixos/modules/profiles/qemu-guest.nix") (pkgs.path + "/nixos/modules/profiles/qemu-guest.nix")
]; ];
in
{ accessScript = lib.makeOverridable ({
accessScript = {
subdomain subdomain
, domain , domain
, hasSSL , hasSSL
@ -95,9 +94,23 @@ in
lib.optionalString (script != "") '' lib.optionalString (script != "") ''
with subtest("extraScript"): with subtest("extraScript"):
${indent 4 script} ${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: { base = pkgs: additionalModules: {
imports = imports =
@ -115,6 +128,30 @@ in
networking.firewall.allowedTCPPorts = [ 80 443 ]; 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, ... }: { certs = domain: { config, ... }: {
imports = [ imports = [
../modules/blocks/ssl.nix ../modules/blocks/ssl.nix

View file

@ -9,7 +9,7 @@ let
adminPassword = "AdminPassword"; adminPassword = "AdminPassword";
commonTestScript = testLib.accessScript { commonTestScript = testLib.mkScripts {
inherit subdomain domain; inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.forgejo.ssl); hasSSL = { node, ... }: !(isNull node.config.shb.forgejo.ssl);
waitForServices = { ... }: [ waitForServices = { ... }: [
@ -111,7 +111,23 @@ in
nodes.client = {}; 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 { https = pkgs.testers.runNixOSTest {
@ -128,7 +144,7 @@ in
nodes.client = {}; nodes.client = {};
testScript = commonTestScript; testScript = commonTestScript.access;
}; };
ldap = pkgs.testers.runNixOSTest { ldap = pkgs.testers.runNixOSTest {
@ -145,7 +161,7 @@ in
nodes.client = {}; nodes.client = {};
testScript = commonTestScript; testScript = commonTestScript.access;
}; };
sso = pkgs.testers.runNixOSTest { sso = pkgs.testers.runNixOSTest {
@ -165,6 +181,6 @@ in
nodes.client = {}; nodes.client = {};
testScript = commonTestScript; testScript = commonTestScript.access;
}; };
} }

View file

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

View file

@ -7,7 +7,7 @@ let
subdomain = "j"; subdomain = "j";
domain = "example.com"; domain = "example.com";
commonTestScript = testLib.accessScript { commonTestScript = testLib.mkScripts {
inherit subdomain domain; inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.jellyfin.ssl); hasSSL = { node, ... }: !(isNull node.config.shb.jellyfin.ssl);
waitForServices = { ... }: [ waitForServices = { ... }: [
@ -87,7 +87,23 @@ in
nodes.client = {}; 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 { https = pkgs.testers.runNixOSTest {
@ -104,7 +120,7 @@ in
nodes.client = {}; nodes.client = {};
testScript = commonTestScript; testScript = commonTestScript.access;
}; };
ldap = pkgs.testers.runNixOSTest { ldap = pkgs.testers.runNixOSTest {
@ -121,7 +137,7 @@ in
nodes.client = {}; nodes.client = {};
testScript = commonTestScript; testScript = commonTestScript.access;
}; };
sso = pkgs.testers.runNixOSTest { sso = pkgs.testers.runNixOSTest {
@ -141,6 +157,6 @@ in
nodes.client = {}; nodes.client = {};
testScript = commonTestScript; testScript = commonTestScript.access;
}; };
} }

View file

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

View file

@ -7,7 +7,7 @@ let
subdomain = "v"; subdomain = "v";
domain = "example.com"; domain = "example.com";
commonTestScript = lib.makeOverridable testLib.accessScript { commonTestScript = testLib.mkScripts {
inherit subdomain domain; inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.vaultwarden.ssl); hasSSL = { node, ... }: !(isNull node.config.shb.vaultwarden.ssl);
waitForServices = { ... }: [ waitForServices = { ... }: [
@ -93,30 +93,6 @@ let
authEndpoint = "https://${config.shb.authelia.subdomain}.${config.shb.authelia.domain}"; 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 in
{ {
basic = pkgs.testers.runNixOSTest { basic = pkgs.testers.runNixOSTest {
@ -131,7 +107,7 @@ in
nodes.client = {}; nodes.client = {};
testScript = commonTestScript; testScript = commonTestScript.access;
}; };
https = pkgs.testers.runNixOSTest { https = pkgs.testers.runNixOSTest {
@ -148,7 +124,7 @@ in
nodes.client = {}; nodes.client = {};
testScript = commonTestScript; testScript = commonTestScript.access;
}; };
# Not yet supported # Not yet supported
@ -164,7 +140,7 @@ in
# #
# nodes.client = {}; # nodes.client = {};
# #
# testScript = commonTestScript; # testScript = commonTestScript.access;
# }; # };
sso = pkgs.testers.runNixOSTest { sso = pkgs.testers.runNixOSTest {
@ -184,7 +160,7 @@ in
nodes.client = {}; nodes.client = {};
testScript = commonTestScript.override { testScript = commonTestScript.access.override {
waitForPorts = { node, ... }: [ waitForPorts = { node, ... }: [
8222 8222
5432 5432
@ -211,17 +187,12 @@ in
imports = [ imports = [
base base
basic basic
backup (testLib.backup config.shb.vaultwarden.backup)
]; ];
}; };
nodes.client = {}; nodes.client = {};
testScript = commonTestScript.override { testScript = commonTestScript.backup;
extraScript = { proto_fqdn, ... }: ''
with subtest("backup"):
server.succeed("systemctl start restic-backups-testinstance_opt_repos_A")
'';
};
}; };
} }