nixos/tests/invidious: move postgres-tcp into second machine and fix tests

Using PostgreSQL 15 without the init script fails due to
https://github.com/NixOS/nixpkgs/issues/216989.
This commit is contained in:
Sophie Tauchert 2023-11-06 14:23:24 +01:00
parent 4a7faeaff3
commit 460e34b273
No known key found for this signature in database
GPG key ID: 52701DE5F5F51125

View file

@ -5,48 +5,51 @@ import ./make-test-python.nix ({ pkgs, ... }: {
maintainers = [ sbruder ];
};
nodes.machine = { config, lib, pkgs, ... }: {
services.invidious = {
enable = true;
};
specialisation = {
nginx.configuration = {
services.invidious = {
nginx.enable = true;
domain = "invidious.example.com";
};
services.nginx.virtualHosts."invidious.example.com" = {
forceSSL = false;
enableACME = false;
};
networking.hosts."127.0.0.1" = [ "invidious.example.com" ];
nodes = {
postgres-tcp = { config, pkgs, ... }: {
services.postgresql = {
enable = true;
initialScript = pkgs.writeText "init-postgres-with-password" ''
CREATE USER kemal WITH PASSWORD 'correct horse battery staple';
CREATE DATABASE invidious WITH OWNER kemal;
'';
enableTCPIP = true;
authentication = ''
host invidious kemal samenet scram-sha-256
'';
};
postgres-tcp.configuration = {
services.invidious = {
database = {
createLocally = false;
host = "127.0.0.1";
passwordFile = toString (pkgs.writeText "database-password" "correct horse battery staple");
networking.firewall.allowedTCPPorts = [ config.services.postgresql.port ];
};
machine = { config, lib, pkgs, ... }: {
services.invidious = {
enable = true;
};
services.postgresql.initialScript = pkgs.writeText "init-postgres-with-password" ''
CREATE USER kemal;
CREATE DATABASE invidious WITH OWNER kemal;
'';
specialisation = {
nginx.configuration = {
services.invidious = {
nginx.enable = true;
domain = "invidious.example.com";
};
services.nginx.virtualHosts."invidious.example.com" = {
forceSSL = false;
enableACME = false;
};
networking.hosts."127.0.0.1" = [ "invidious.example.com" ];
};
postgres-tcp.configuration = {
services.invidious = {
database = {
createLocally = false;
host = "postgres-tcp";
passwordFile = toString (pkgs.writeText "database-password" "correct horse battery staple");
};
};
};
# Normally not needed because when connecting to postgres over TCP/IP
# the database is most likely on another host.
systemd.services.invidious = {
after = [ "postgresql.service" ];
requires = [ "postgresql.service" ];
};
services.postgresql =
let
inherit (config.services.invidious.settings.db) dbname user;
in
{
enable = true;
initialScript = pkgs.writeText "init-postgres-with-password" ''
CREATE USER kemal WITH PASSWORD 'correct horse battery staple';
CREATE DATABASE invidious OWNER kemal;
'';
};
};
};
};
@ -63,6 +66,9 @@ import ./make-test-python.nix ({ pkgs, ... }: {
url = "http://localhost:${toString nodes.machine.config.services.invidious.port}"
port = ${toString nodes.machine.config.services.invidious.port}
# start postgres vm now
postgres_tcp.start()
machine.wait_for_open_port(port)
curl_assert_status_code(f"{url}/search", 200)
@ -70,9 +76,7 @@ import ./make-test-python.nix ({ pkgs, ... }: {
machine.wait_for_open_port(80)
curl_assert_status_code("http://invidious.example.com/search", 200)
# Remove the state so the `initialScript` gets run
machine.succeed("systemctl stop postgresql")
machine.succeed("rm -r /var/lib/postgresql")
postgres_tcp.wait_for_unit("postgresql.service")
activate_specialisation("postgres-tcp")
machine.wait_for_open_port(port)
curl_assert_status_code(f"{url}/search", 200)