1 import ./make-test-python.nix ({ pkgs, lib, ... }: rec {
3 meta = with pkgs.lib.maintainers; {
4 maintainers = [ astro ];
10 networking.interfaces.eth1.ipv4.addresses = [ {
11 address = "192.168.0.${toString i}";
17 clusterName = "zentralwerk-network";
18 nodelist = lib.imap (i: name: {
22 (builtins.head nodes.${name}.networking.interfaces.eth1.ipv4.addresses).address
24 }) (builtins.attrNames nodes);
26 environment.etc."corosync/authkey" = {
27 source = builtins.toFile "authkey"
28 # minimum length: 128 bytes
29 "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest";
33 services.pacemaker.enable = true;
35 # used for pacemaker resource
36 systemd.services.ha-cat = {
37 description = "Highly available netcat";
38 serviceConfig.ExecStart = "${pkgs.netcat}/bin/nc -l discard";
47 # sets up pacemaker with resources configuration, then crashes a
48 # node and waits for service restart on another node
51 resources = builtins.toFile "cib-resources.xml" ''
53 <primitive id="cat" class="systemd" type="ha-cat">
55 <op id="stop-cat" name="start" interval="0" timeout="1s"/>
56 <op id="start-cat" name="start" interval="0" timeout="1s"/>
57 <op id="monitor-cat" name="monitor" interval="1s" timeout="1s"/>
68 ${lib.concatMapStrings (node: ''
69 ${node}.wait_until_succeeds("corosync-quorumtool")
70 ${node}.wait_for_unit("pacemaker.service")
71 '') (builtins.attrNames nodes)}
74 node1.succeed("crm_attribute -t crm_config -n stonith-enabled -v false")
75 # Configure the cat resource
76 node1.succeed("cibadmin --replace --scope resources --xml-file ${resources}")
78 # wait until the service is started
80 output = node1.succeed("crm_resource -r cat --locate")
81 match = re.search("is running on: (.+)", output)
83 for machine in machines:
84 if machine.name == match.group(1):
85 current_node = machine
89 current_node.log("Service running here!")
92 # pick another node that's still up
93 for machine in machines:
96 # find where the service has been started next
98 output = check_node.succeed("crm_resource -r cat --locate")
99 match = re.search("is running on: (.+)", output)
100 # output will remain the old current_node until the crash is detected by pacemaker
101 if match and match.group(1) != current_node.name:
102 for machine in machines:
103 if machine.name == match.group(1):
108 next_node.log("Service migrated here!")