Compare commits
14 commits
56bd796ed2
...
11ad950b25
Author | SHA1 | Date | |
---|---|---|---|
11ad950b25 | |||
c79da8bbdf | |||
9294de36cd | |||
006fa8bfce | |||
c57976a299 | |||
e87a1b23e9 | |||
fe89d1d3c3 | |||
204d3f77eb | |||
3b1e82b33f | |||
c92f1c5ed8 | |||
54ba01d8cd | |||
d015c77ffa | |||
d1c0e9d7f9 | |||
4f6ea4eb8c |
3 changed files with 61 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
|||
{
|
||||
imports = [
|
||||
./options.nix
|
||||
./simulacrum/test-data.nix
|
||||
];
|
||||
|
||||
services.incandescence = {
|
||||
|
@ -15,6 +16,10 @@
|
|||
./provider-options.nix
|
||||
];
|
||||
};
|
||||
simulacrum.deps = [ "consul" ];
|
||||
simulacrum = {
|
||||
enable = true;
|
||||
deps = [ "consul" "locksmith" ];
|
||||
settings = ./simulacrum/test.nix;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
8
cluster/services/incandescence/simulacrum/test-data.nix
Normal file
8
cluster/services/incandescence/simulacrum/test-data.nix
Normal file
|
@ -0,0 +1,8 @@
|
|||
{ config, lib, ... }:
|
||||
{
|
||||
incandescence = lib.mkIf config.simulacrum {
|
||||
providers = config.lib.forService "incandescence" {
|
||||
test.objects.example = [ "example1" "example2" ];
|
||||
};
|
||||
};
|
||||
}
|
47
cluster/services/incandescence/simulacrum/test.nix
Normal file
47
cluster/services/incandescence/simulacrum/test.nix
Normal file
|
@ -0,0 +1,47 @@
|
|||
{ cluster, lib, ... }:
|
||||
|
||||
let
|
||||
providers = lib.take 2 cluster.config.services.incandescence.nodes.provider;
|
||||
in
|
||||
|
||||
{
|
||||
nodes = lib.genAttrs providers (lib.const {
|
||||
services.incandescence.providers.test = {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
partOf = [ ];
|
||||
formulae.example = {
|
||||
create = x: "consul kv put testData/${x} ${x}";
|
||||
destroy = "consul kv delete testData/$OBJECT";
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
testScript = ''
|
||||
import json
|
||||
nodeNames = json.loads('${builtins.toJSON providers}')
|
||||
nodes = [ n for n in machines if n.name in nodeNames ]
|
||||
|
||||
start_all()
|
||||
|
||||
consulConfig = json.loads(nodes[0].succeed("cat /etc/consul.json"))
|
||||
addr = consulConfig["addresses"]["http"]
|
||||
port = consulConfig["ports"]["http"]
|
||||
setEnv = f"CONSUL_HTTP_ADDR={addr}:{port}"
|
||||
|
||||
with subtest("should create objects"):
|
||||
for node in nodes:
|
||||
node.wait_for_unit("incandescence-test.target")
|
||||
nodes[0].succeed(f"[[ $({setEnv} consul kv get testData/example1) == example1 ]]")
|
||||
nodes[0].succeed(f"[[ $({setEnv} consul kv get testData/example2) == example2 ]]")
|
||||
|
||||
with subtest("should destroy objects"):
|
||||
nodes[0].succeed(f"{setEnv} consul kv put testData/example3 example3")
|
||||
nodes[0].succeed(f"{setEnv} consul kv put services/incandescence/providers/test/formulae/example/example3/alive true")
|
||||
nodes[1].succeed(f"{setEnv} consul kv get testData/example3")
|
||||
for node in nodes:
|
||||
node.systemctl("isolate default")
|
||||
for node in nodes:
|
||||
node.wait_for_unit("incandescence-test.target")
|
||||
nodes[0].fail(f"{setEnv} consul kv get testData/example3")
|
||||
'';
|
||||
}
|
Loading…
Reference in a new issue