1
0
Fork 0

refactor vm tests to have common test script (#202)

This commit is contained in:
Pierre Penninckx 2024-03-04 20:36:47 -08:00 committed by GitHub
parent 3a6d891224
commit 77de1bb168
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 123 additions and 242 deletions

View file

@ -1,4 +1,42 @@
{ pkgs, lib, ... }: { pkgs, lib, ... }:
let
# TODO: Test login
commonTestScript = { nodes, ... }:
let
hasSSL = !(isNull nodes.server.shb.audiobookshelf.ssl);
fqdn = if hasSSL then "https://a.example.com" else "http://a.example.com";
in
''
import json
import os
import pathlib
start_all()
server.wait_for_unit("audiobookshelf.service")
server.wait_for_unit("nginx.service")
server.wait_for_open_port(${builtins.toString nodes.server.shb.audiobookshelf.webPort})
if ${if hasSSL then "True" else "False"}:
server.copy_from_vm("/etc/ssl/certs/ca-certificates.crt")
client.succeed("rm -r /etc/ssl/certs")
client.copy_from_host(str(pathlib.Path(os.environ.get("out", os.getcwd())) / "ca-certificates.crt"), "/etc/ssl/certs/ca-certificates.crt")
def curl(target, format, endpoint, succeed=True):
return json.loads(target.succeed(
"curl --fail-with-body --silent --show-error --output /dev/null --location"
+ " --connect-to a.example.com:443:server:443"
+ " --connect-to a.example.com:80:server:80"
+ f" --write-out '{format}'"
+ " " + endpoint
))
with subtest("access"):
response = curl(client, """{"code":%{response_code}}""", "${fqdn}")
if response['code'] != 200:
raise Exception(f"Code is {response['code']}")
'';
in
{ {
basic = pkgs.nixosTest { basic = pkgs.nixosTest {
name = "audiobookshelf-basic"; name = "audiobookshelf-basic";
@ -25,29 +63,7 @@
nodes.client = {}; nodes.client = {};
# TODO: Test login testScript = commonTestScript;
testScript = { nodes, ... }: ''
import json
def curl(target, format, endpoint):
return json.loads(target.succeed(
"curl --fail-with-body --silent --show-error --output /dev/null --location"
+ " --connect-to a.example.com:443:server:443"
+ " --connect-to a.example.com:80:server:80"
+ f" --write-out '{format}'"
+ " " + endpoint
))
start_all()
server.wait_for_unit("audiobookshelf.service")
server.wait_for_unit("nginx.service")
server.wait_for_open_port(${builtins.toString nodes.server.shb.audiobookshelf.webPort})
response = curl(client, """{"code":%{response_code}}""", "http://a.example.com")
if response['code'] != 200:
raise Exception(f"Code is {response['code']}")
'';
}; };
cert = pkgs.nixosTest { cert = pkgs.nixosTest {
@ -96,35 +112,7 @@
nodes.client = {}; nodes.client = {};
# TODO: Test login testScript = commonTestScript;
testScript = { nodes, ... }: ''
import json
import os
import pathlib
def curl(target, format, endpoint):
return json.loads(target.succeed(
"curl --fail-with-body --silent --show-error --output /dev/null --location"
+ " --connect-to a.example.com:443:server:443"
+ " --connect-to a.example.com:80:server:80"
+ f" --write-out '{format}'"
+ " " + endpoint
))
start_all()
server.wait_for_unit("audiobookshelf.service")
server.wait_for_unit("nginx.service")
server.wait_for_open_port(${builtins.toString nodes.server.shb.audiobookshelf.webPort})
server.copy_from_vm("/etc/ssl/certs/ca-certificates.crt")
client.succeed("rm -r /etc/ssl/certs")
client.copy_from_host(str(pathlib.Path(os.environ.get("out", os.getcwd())) / "ca-certificates.crt"), "/etc/ssl/certs/ca-certificates.crt")
response = curl(client, """{"code":%{response_code}}""", "https://a.example.com")
if response['code'] != 200:
raise Exception(f"Code is {response['code']}")
'';
}; };
sso = pkgs.nixosTest { sso = pkgs.nixosTest {
@ -208,36 +196,6 @@
nodes.client = {}; nodes.client = {};
# TODO: Test login with ldap user testScript = commonTestScript;
testScript = { nodes, ... }: ''
import json
import os
import pathlib
def curl(target, format, endpoint):
return json.loads(target.succeed(
"curl --fail-with-body --silent --show-error --output /dev/null --location"
+ " --connect-to a.example.com:443:server:443"
+ " --connect-to a.example.com:80:server:80"
+ f" --write-out '{format}'"
+ " " + endpoint
))
start_all()
server.wait_for_unit("audiobookshelf.service")
server.wait_for_unit("nginx.service")
server.wait_for_unit("lldap.service")
server.wait_for_unit("authelia-auth.example.com.service")
server.wait_for_open_port(${builtins.toString nodes.server.shb.audiobookshelf.webPort})
server.copy_from_vm("/etc/ssl/certs/ca-certificates.crt")
client.succeed("rm -r /etc/ssl/certs")
client.copy_from_host(str(pathlib.Path(os.environ.get("out", os.getcwd())) / "ca-certificates.crt"), "/etc/ssl/certs/ca-certificates.crt")
response = curl(client, """{"code":%{response_code}}""", "https://a.example.com")
if response['code'] != 200:
raise Exception(f"Code is {response['code']}")
'';
}; };
} }

View file

@ -1,4 +1,42 @@
{ pkgs, lib, ... }: { pkgs, lib, ... }:
let
# TODO: Test login
commonTestScript = { nodes, ... }:
let
hasSSL = !(isNull nodes.server.shb.grocy.ssl);
fqdn = if hasSSL then "https://g.example.com" else "http://g.example.com";
in
''
import json
import os
import pathlib
start_all()
server.wait_for_unit("phpfpm-grocy.service")
server.wait_for_unit("nginx.service")
server.wait_for_open_unix_socket("${nodes.server.services.phpfpm.pools.grocy.socket}")
if ${if hasSSL then "True" else "False"}:
server.copy_from_vm("/etc/ssl/certs/ca-certificates.crt")
client.succeed("rm -r /etc/ssl/certs")
client.copy_from_host(str(pathlib.Path(os.environ.get("out", os.getcwd())) / "ca-certificates.crt"), "/etc/ssl/certs/ca-certificates.crt")
def curl(target, format, endpoint, succeed=True):
return json.loads(target.succeed(
"curl --fail-with-body --silent --show-error --output /dev/null --location"
+ " --connect-to g.example.com:443:server:443"
+ " --connect-to g.example.com:80:server:80"
+ f" --write-out '{format}'"
+ " " + endpoint
))
with subtest("access"):
response = curl(client, """{"code":%{response_code}}""", "${fqdn}")
if response['code'] != 200:
raise Exception(f"Code is {response['code']}")
'';
in
{ {
basic = pkgs.nixosTest { basic = pkgs.nixosTest {
name = "grocy-basic"; name = "grocy-basic";
@ -24,29 +62,7 @@
nodes.client = {}; nodes.client = {};
# TODO: Test login testScript = commonTestScript;
testScript = { nodes, ... }: ''
import json
def curl(target, format, endpoint):
return json.loads(target.succeed(
"curl --fail-with-body --silent --show-error --output /dev/null --location"
+ " --connect-to g.example.com:443:server:443"
+ " --connect-to g.example.com:80:server:80"
+ f" --write-out '{format}'"
+ " " + endpoint
))
start_all()
server.wait_for_unit("phpfpm-grocy.service")
server.wait_for_unit("nginx.service")
server.wait_for_open_unix_socket("${nodes.server.services.phpfpm.pools.grocy.socket}")
response = curl(client, """{"code":%{response_code}}""", "http://g.example.com")
if response['code'] != 200:
raise Exception(f"Code is {response['code']}")
'';
}; };
cert = pkgs.nixosTest { cert = pkgs.nixosTest {
@ -95,34 +111,6 @@
nodes.client = {}; nodes.client = {};
# TODO: Test login testScript = commonTestScript;
testScript = { nodes, ... }: ''
import json
import os
import pathlib
def curl(target, format, endpoint):
return json.loads(target.succeed(
"curl --fail-with-body --silent --show-error --output /dev/null --location"
+ " --connect-to g.example.com:443:server:443"
+ " --connect-to g.example.com:80:server:80"
+ f" --write-out '{format}'"
+ " " + endpoint
))
start_all()
server.wait_for_unit("phpfpm-grocy.service")
server.wait_for_unit("nginx.service")
server.wait_for_open_unix_socket("${nodes.server.services.phpfpm.pools.grocy.socket}")
server.copy_from_vm("/etc/ssl/certs/ca-certificates.crt")
client.succeed("rm -r /etc/ssl/certs")
client.copy_from_host(str(pathlib.Path(os.environ.get("out", os.getcwd())) / "ca-certificates.crt"), "/etc/ssl/certs/ca-certificates.crt")
response = curl(client, """{"code":%{response_code}}""", "https://g.example.com")
if response['code'] != 200:
raise Exception(f"Code is {response['code']}")
'';
}; };
} }

View file

@ -1,4 +1,42 @@
{ pkgs, lib, ... }: { pkgs, lib, ... }:
let
# TODO: Test login
commonTestScript = { nodes, ... }:
let
hasSSL = !(isNull nodes.server.shb.jellyfin.ssl);
fqdn = if hasSSL then "https://j.example.com" else "http://j.example.com";
in
''
import json
import os
import pathlib
start_all()
server.wait_for_unit("jellyfin.service")
server.wait_for_unit("nginx.service")
server.wait_for_open_port(8096)
if ${if hasSSL then "True" else "False"}:
server.copy_from_vm("/etc/ssl/certs/ca-certificates.crt")
client.succeed("rm -r /etc/ssl/certs")
client.copy_from_host(str(pathlib.Path(os.environ.get("out", os.getcwd())) / "ca-certificates.crt"), "/etc/ssl/certs/ca-certificates.crt")
def curl(target, format, endpoint, succeed=True):
return json.loads(target.succeed(
"curl --fail-with-body --silent --show-error --output /dev/null --location"
+ " --connect-to j.example.com:443:server:443"
+ " --connect-to j.example.com:80:server:80"
+ f" --write-out '{format}'"
+ " " + endpoint
))
with subtest("access"):
response = curl(client, """{"code":%{response_code}}""", "${fqdn}")
if response['code'] != 200:
raise Exception(f"Code is {response['code']}")
'';
in
{ {
basic = pkgs.nixosTest { basic = pkgs.nixosTest {
name = "jellyfin-basic"; name = "jellyfin-basic";
@ -25,29 +63,7 @@
nodes.client = {}; nodes.client = {};
# TODO: Test login testScript = commonTestScript;
testScript = { nodes, ... }: ''
import json
def curl(target, format, endpoint):
return json.loads(target.succeed(
"curl --fail-with-body --silent --show-error --output /dev/null --location"
+ " --connect-to j.example.com:443:server:443"
+ " --connect-to j.example.com:80:server:80"
+ f" --write-out '{format}'"
+ " " + endpoint
))
start_all()
server.wait_for_unit("jellyfin.service")
server.wait_for_unit("nginx.service")
server.wait_for_open_port(8096)
response = curl(client, """{"code":%{response_code}}""", "http://j.example.com")
if response['code'] != 200:
raise Exception(f"Code is {response['code']}")
'';
}; };
ldap = pkgs.nixosTest { ldap = pkgs.nixosTest {
@ -95,30 +111,7 @@
nodes.client = {}; nodes.client = {};
# TODO: Test login with ldap user testScript = commonTestScript;
testScript = { nodes, ... }: ''
import json
def curl(target, format, endpoint):
return json.loads(target.succeed(
"curl --fail-with-body --silent --show-error --output /dev/null --location"
+ " --connect-to j.example.com:443:server:443"
+ " --connect-to j.example.com:80:server:80"
+ f" --write-out '{format}'"
+ " " + endpoint
))
start_all()
server.wait_for_unit("jellyfin.service")
server.wait_for_unit("nginx.service")
server.wait_for_unit("lldap.service")
server.wait_for_open_port(8096)
response = curl(client, """{"code":%{response_code}}""", "http://j.example.com")
if response['code'] != 200:
raise Exception(f"Code is {response['code']}")
'';
}; };
cert = pkgs.nixosTest { cert = pkgs.nixosTest {
@ -168,35 +161,7 @@
nodes.client = {}; nodes.client = {};
# TODO: Test login testScript = commonTestScript;
testScript = { nodes, ... }: ''
import json
import os
import pathlib
def curl(target, format, endpoint):
return json.loads(target.succeed(
"curl --fail-with-body --silent --show-error --output /dev/null --location"
+ " --connect-to j.example.com:443:server:443"
+ " --connect-to j.example.com:80:server:80"
+ f" --write-out '{format}'"
+ " " + endpoint
))
start_all()
server.wait_for_unit("jellyfin.service")
server.wait_for_unit("nginx.service")
server.wait_for_open_port(8096)
server.copy_from_vm("/etc/ssl/certs/ca-certificates.crt")
client.succeed("rm -r /etc/ssl/certs")
client.copy_from_host(str(pathlib.Path(os.environ.get("out", os.getcwd())) / "ca-certificates.crt"), "/etc/ssl/certs/ca-certificates.crt")
response = curl(client, """{"code":%{response_code}}""", "https://j.example.com")
if response['code'] != 200:
raise Exception(f"Code is {response['code']}")
'';
}; };
sso = pkgs.nixosTest { sso = pkgs.nixosTest {
@ -291,36 +256,6 @@
nodes.client = {}; nodes.client = {};
# TODO: Test login with ldap user testScript = commonTestScript;
testScript = { nodes, ... }: ''
import json
import os
import pathlib
def curl(target, format, endpoint):
return json.loads(target.succeed(
"curl --fail-with-body --silent --show-error --output /dev/null --location"
+ " --connect-to j.example.com:443:server:443"
+ " --connect-to j.example.com:80:server:80"
+ f" --write-out '{format}'"
+ " " + endpoint
))
start_all()
server.wait_for_unit("jellyfin.service")
server.wait_for_unit("nginx.service")
server.wait_for_unit("lldap.service")
server.wait_for_unit("authelia-auth.example.com.service")
server.wait_for_open_port(8096)
server.copy_from_vm("/etc/ssl/certs/ca-certificates.crt")
client.succeed("rm -r /etc/ssl/certs")
client.copy_from_host(str(pathlib.Path(os.environ.get("out", os.getcwd())) / "ca-certificates.crt"), "/etc/ssl/certs/ca-certificates.crt")
response = curl(client, """{"code":%{response_code}}""", "https://j.example.com")
if response['code'] != 200:
raise Exception(f"Code is {response['code']}")
'';
}; };
} }