summaryrefslogtreecommitdiffstats
path: root/nixos/tests/etcd.nix
diff options
context:
space:
mode:
authorJaka Hudoklin <jakahudoklin@gmail.com>2014-11-15 16:27:27 +0100
committerJaka Hudoklin <jakahudoklin@gmail.com>2014-11-21 13:54:45 +0100
commitb3bc157f7ff84a7ed0dc34901830c589d17a51e9 (patch)
treedbd8cdc3836e1a3611d0fbbf3b8c0424ddcbc726 /nixos/tests/etcd.nix
parentbcf9da32f74818beeaf3ca749a4ea2a56027e80d (diff)
nixos: add etcd module
Diffstat (limited to 'nixos/tests/etcd.nix')
-rw-r--r--nixos/tests/etcd.nix108
1 files changed, 108 insertions, 0 deletions
diff --git a/nixos/tests/etcd.nix b/nixos/tests/etcd.nix
new file mode 100644
index 000000000000..6c6dd84f558d
--- /dev/null
+++ b/nixos/tests/etcd.nix
@@ -0,0 +1,108 @@
+# This test runs etcd as single node, multy node and using discovery
+
+import ./make-test.nix {
+ name = "etcd";
+
+ nodes = {
+ simple =
+ { config, pkgs, nodes, ... }:
+ {
+ services.etcd.enable = true;
+ services.etcd.listenClientUrls = ["http://0.0.0.0:4001"];
+ environment.systemPackages = [ pkgs.curl ];
+ networking.firewall.allowedTCPPorts = [ 4001 ];
+ };
+
+
+ node1 =
+ { config, pkgs, nodes, ... }:
+ {
+ services = {
+ etcd = {
+ enable = true;
+ listenPeerUrls = ["http://0.0.0.0:7001"];
+ initialAdvertisePeerUrls = ["http://node1:7001"];
+ initialCluster = ["node1=http://node1:7001" "node2=http://node2:7001"];
+ };
+ };
+
+ networking.firewall.allowedTCPPorts = [ 7001 ];
+ };
+
+ node2 =
+ { config, pkgs, ... }:
+ {
+ services = {
+ etcd = {
+ enable = true;
+ listenPeerUrls = ["http://0.0.0.0:7001"];
+ initialAdvertisePeerUrls = ["http://node2:7001"];
+ initialCluster = ["node1=http://node1:7001" "node2=http://node2:7001"];
+ };
+ };
+
+ networking.firewall.allowedTCPPorts = [ 7001 ];
+ };
+
+ discovery1 =
+ { config, pkgs, nodes, ... }:
+ {
+ services = {
+ etcd = {
+ enable = true;
+ listenPeerUrls = ["http://0.0.0.0:7001"];
+ initialAdvertisePeerUrls = ["http://discovery1:7001"];
+ discovery = "http://simple:4001/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0fb83/";
+ };
+ };
+
+ networking.firewall.allowedTCPPorts = [ 7001 ];
+ };
+
+ discovery2 =
+ { config, pkgs, ... }:
+ {
+ services = {
+ etcd = {
+ enable = true;
+ listenPeerUrls = ["http://0.0.0.0:7001"];
+ initialAdvertisePeerUrls = ["http://discovery2:7001"];
+ discovery = "http://simple:4001/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0fb83/";
+ };
+ };
+
+ networking.firewall.allowedTCPPorts = [ 7001 ];
+ };
+ };
+
+ testScript = ''
+ subtest "single node", sub {
+ $simple->start();
+ $simple->waitForUnit("etcd.service");
+ $simple->succeed("etcdctl set /foo/bar 'Hello world'");
+ $simple->succeed("etcdctl get /foo/bar | grep 'Hello world'");
+ };
+
+ subtest "multy node", sub {
+ $node1->start();
+ $node2->start();
+ $node1->waitForUnit("etcd.service");
+ $node2->waitForUnit("etcd.service");
+ $node1->succeed("etcdctl set /foo/bar 'Hello world'");
+ $node2->succeed("etcdctl get /foo/bar | grep 'Hello world'");
+ $node1->shutdown();
+ $node2->shutdown();
+ };
+
+ subtest "discovery", sub {
+ $simple->succeed("curl -X PUT http://localhost:4001/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0fb83/_config/size -d value=2");
+
+ $discovery1->start();
+ $discovery2->start();
+ $discovery1->waitForUnit("etcd.service");
+ $discovery2->waitForUnit("etcd.service");
+ $discovery1->succeed("etcdctl set /foo/bar 'Hello world'");
+ $discovery2->succeed("etcdctl get /foo/bar | grep 'Hello world'");
+ };
+ '';
+}