Compare commits

..

4 commits

3 changed files with 22 additions and 71 deletions

View file

@ -4,6 +4,7 @@
imports = [
./options.nix
./incandescence.nix
./simulacrum/test-data.nix
];
links = {
@ -39,7 +40,7 @@
simulacrum = {
enable = true;
deps = [ "consul" "incandescence" "locksmith" ];
settings = ./test.nix;
settings = ./simulacrum/test.nix;
};
};
}

View file

@ -0,0 +1,14 @@
{ config, lib, ... }:
{
patroni = lib.mkIf config.simulacrum {
databases = config.lib.forService "patroni" {
testdb.owner = "testuser";
};
users = config.lib.forService "patroni" {
testuser.locksmith = {
nodes = config.services.patroni.nodes.haproxy;
format = "pgpass";
};
};
};
}

View file

@ -1,75 +1,6 @@
{ cluster, ... }:
let
createNode = index: { pkgs, ... }:
{
networking.firewall.allowedTCPPorts = [ 5432 8008 5010 ];
environment.systemPackages = [ pkgs.jq ];
services.patroni = {
enable = true;
softwareWatchdog = true;
settings = {
bootstrap = {
dcs = {
ttl = 30;
loop_wait = 10;
retry_timeout = 10;
maximum_lag_on_failover = 1048576;
};
initdb = [
{ encoding = "UTF8"; }
"data-checksums"
];
};
postgresql = {
use_pg_rewind = true;
use_slots = true;
authentication = {
replication = {
username = "replicator";
};
superuser = {
username = "postgres";
};
rewind = {
username = "rewind";
};
};
parameters = {
wal_level = "replica";
hot_standby_feedback = "on";
unix_socket_directories = "/tmp";
};
pg_hba = [
"host replication replicator 192.168.1.0/24 md5"
# Unsafe, do not use for anything other than tests
"host all all 0.0.0.0/0 trust"
];
};
etcd3 = {
host = "192.168.1.4:2379";
};
};
environmentFiles = {
PATRONI_REPLICATION_PASSWORD = pkgs.writeText "replication-password" "postgres";
PATRONI_SUPERUSER_PASSWORD = pkgs.writeText "superuser-password" "postgres";
PATRONI_REWIND_PASSWORD = pkgs.writeText "rewind-password" "postgres";
};
};
# We always want to restart so the tests never hang
systemd.services.patroni.serviceConfig.StartLimitIntervalSec = 0;
};
clusterName = "poseidon";
link = cluster.config.links.patroni-pg-access;
in
@ -80,7 +11,7 @@ in
depot.packages.postgresql
];
services.patroni.settings.postgresql.pg_hba = [
"host all all 0.0.0.0/0 trust"
"host postgres postgres 0.0.0.0/0 trust"
];
};
@ -151,5 +82,10 @@ in
# Execute some queries with the node back up.
run_dummy_queries()
with subtest("should create databases and users via incandescence"):
for client in clients:
client.succeed(f"PGPASSFILE=/run/locksmith/patroni-testuser psql -h ${link.ipv4} -p ${link.portStr} -U testuser -d testdb --command='create table test_table_{client.name} as select * from generate_series(1, 10) as val;'")
client.fail(f"PGPASSFILE=/run/locksmith/patroni-testuser psql -h ${link.ipv4} -p ${link.portStr} -U testuser -d postgres --command='select 1;'")
'';
}