Compare commits
No commits in common. "5257d4e70b19c9079710c1aa827ba6f63256fa11" and "340383f160f510eba77613398b9aa85b598de841" have entirely different histories.
5257d4e70b
...
340383f160
3 changed files with 2 additions and 39 deletions
|
@ -49,9 +49,7 @@ in
|
||||||
user = {
|
user = {
|
||||||
destroyAfterDays = 0;
|
destroyAfterDays = 0;
|
||||||
create = user: psqlSecret "${genPassword} ${user}" ''
|
create = user: psqlSecret "${genPassword} ${user}" ''
|
||||||
SELECT 'CREATE USER ${user}'
|
CREATE USER ${user} PASSWORD '@SECRET@';
|
||||||
WHERE NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '${user}')\gexec
|
|
||||||
ALTER USER ${user} PASSWORD '@SECRET@';
|
|
||||||
'';
|
'';
|
||||||
destroy = psqlSecret "printenv OBJECT" ''
|
destroy = psqlSecret "printenv OBJECT" ''
|
||||||
DROP USER @SECRET@;
|
DROP USER @SECRET@;
|
||||||
|
@ -61,11 +59,7 @@ in
|
||||||
destroyAfterDays = 30;
|
destroyAfterDays = 30;
|
||||||
deps = [ "user" ];
|
deps = [ "user" ];
|
||||||
create = db: psql ''
|
create = db: psql ''
|
||||||
SELECT 'CREATE DATABASE ${db} OWNER ${cfg.databases.${db}.owner}'
|
CREATE DATABASE ${db} OWNER ${cfg.databases.${db}.owner};
|
||||||
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '${db}')\gexec
|
|
||||||
'';
|
|
||||||
change = db: psql ''
|
|
||||||
ALTER DATABASE ${db} OWNER TO ${cfg.databases.${db}.owner};
|
|
||||||
'';
|
'';
|
||||||
destroy = psqlSecret "printenv OBJECT" ''
|
destroy = psqlSecret "printenv OBJECT" ''
|
||||||
DROP DATABASE @SECRET@;
|
DROP DATABASE @SECRET@;
|
||||||
|
|
|
@ -3,17 +3,12 @@
|
||||||
patroni = lib.mkIf config.simulacrum {
|
patroni = lib.mkIf config.simulacrum {
|
||||||
databases = config.lib.forService "patroni" {
|
databases = config.lib.forService "patroni" {
|
||||||
testdb.owner = "testuser";
|
testdb.owner = "testuser";
|
||||||
existingdb.owner = "existinguser";
|
|
||||||
};
|
};
|
||||||
users = config.lib.forService "patroni" {
|
users = config.lib.forService "patroni" {
|
||||||
testuser.locksmith = {
|
testuser.locksmith = {
|
||||||
nodes = config.services.patroni.nodes.haproxy;
|
nodes = config.services.patroni.nodes.haproxy;
|
||||||
format = "pgpass";
|
format = "pgpass";
|
||||||
};
|
};
|
||||||
existinguser.locksmith = {
|
|
||||||
nodes = config.services.patroni.nodes.haproxy;
|
|
||||||
format = "pgpass";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,31 +87,5 @@ in
|
||||||
for client in clients:
|
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.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("PGPASSFILE=/run/locksmith/patroni-testuser psql -h ${link.ipv4} -p ${link.portStr} -U testuser -d postgres --command='select * from dummy;'")
|
client.fail("PGPASSFILE=/run/locksmith/patroni-testuser psql -h ${link.ipv4} -p ${link.portStr} -U testuser -d postgres --command='select * from dummy;'")
|
||||||
|
|
||||||
with subtest("should take over existing databases and users via incandescence"):
|
|
||||||
for cmd in [
|
|
||||||
"drop database existingdb;",
|
|
||||||
"drop user existinguser;",
|
|
||||||
"create database existingdb owner postgres;",
|
|
||||||
"create user existinguser;"
|
|
||||||
]:
|
|
||||||
clients[0].succeed(f"psql -h ${link.ipv4} -p ${link.portStr} -U postgres --command='{cmd}'")
|
|
||||||
|
|
||||||
for client in clients:
|
|
||||||
client.fail(f"PGPASSFILE=/run/locksmith/patroni-existinguser psql -h ${link.ipv4} -p ${link.portStr} -U existinguser -d existingdb --command='create table test_table_{client.name} as select * from generate_series(1, 10) as val;'")
|
|
||||||
|
|
||||||
consulConfig = json.loads(clients[0].succeed("cat /etc/consul.json"))
|
|
||||||
addr = consulConfig["addresses"]["http"]
|
|
||||||
port = consulConfig["ports"]["http"]
|
|
||||||
setEnv = f"CONSUL_HTTP_ADDR={addr}:{port}"
|
|
||||||
clients[0].succeed(f"{setEnv} consul kv delete --recurse services/incandescence/providers/patroni/formulae/database/existingdb")
|
|
||||||
clients[0].succeed(f"{setEnv} consul kv delete --recurse services/incandescence/providers/patroni/formulae/user/existinguser")
|
|
||||||
|
|
||||||
for node in nodes:
|
|
||||||
node.systemctl("restart incandescence-patroni.target")
|
|
||||||
clients[0].succeed("[[ $(psql -h ${link.ipv4} -p ${link.portStr} -U postgres --tuples-only --csv --command=\"SELECT pg_roles.rolname FROM pg_database JOIN pg_roles ON pg_database.datdba = pg_roles.oid WHERE pg_database.datname = 'existingdb'\") == existinguser ]]")
|
|
||||||
for client in clients:
|
|
||||||
client.succeed(f"PGPASSFILE=/run/locksmith/patroni-existinguser psql -h ${link.ipv4} -p ${link.portStr} -U existinguser -d existingdb --command='create table test_table_{client.name} as select * from generate_series(1, 10) as val;'")
|
|
||||||
client.fail("PGPASSFILE=/run/locksmith/patroni-existinguser psql -h ${link.ipv4} -p ${link.portStr} -U existinguser -d postgres --command='select * from dummy;'")
|
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue