From b55a253e154160d2fde0db1e05ea3a16b46bcb18 Mon Sep 17 00:00:00 2001 From: Guillaume Girol Date: Wed, 22 Dec 2021 12:00:00 +0000 Subject: [PATCH] nixos/collectd: add nixos test --- nixos/tests/all-tests.nix | 1 + nixos/tests/collectd.nix | 33 ++++++++++++++++++++++++++ pkgs/tools/system/collectd/default.nix | 5 ++++ 3 files changed, 39 insertions(+) create mode 100644 nixos/tests/collectd.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 8f4d800abbfd..8ac2cb7fe790 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -70,6 +70,7 @@ in cloud-init = handleTest ./cloud-init.nix {}; cntr = handleTest ./cntr.nix {}; cockroachdb = handleTestOn ["x86_64-linux"] ./cockroachdb.nix {}; + collectd = handleTest ./collectd.nix {}; consul = handleTest ./consul.nix {}; containers-bridge = handleTest ./containers-bridge.nix {}; containers-custom-pkgs.nix = handleTest ./containers-custom-pkgs.nix {}; diff --git a/nixos/tests/collectd.nix b/nixos/tests/collectd.nix new file mode 100644 index 000000000000..cb196224a231 --- /dev/null +++ b/nixos/tests/collectd.nix @@ -0,0 +1,33 @@ +import ./make-test-python.nix ({ pkgs, ... }: { + name = "collectd"; + meta = { }; + + machine = + { pkgs, ... }: + + { + services.collectd = { + enable = true; + plugins = { + rrdtool = '' + DataDir "/var/lib/collectd/rrd" + ''; + load = ""; + }; + }; + environment.systemPackages = [ pkgs.rrdtool ]; + }; + + testScript = '' + machine.wait_for_unit("collectd.service") + hostname = machine.succeed("hostname").strip() + file = f"/var/lib/collectd/rrd/{hostname}/load/load.rrd" + machine.wait_for_file(file); + machine.succeed(f"rrdinfo {file} | logger") + # check that this file contains a shortterm metric + machine.succeed(f"rrdinfo {file} | grep -F 'ds[shortterm].min = '") + # check that there are frequent updates + machine.succeed(f"cp {file} before") + machine.wait_until_fails(f"cmp before {file}") + ''; +}) diff --git a/pkgs/tools/system/collectd/default.nix b/pkgs/tools/system/collectd/default.nix index 600c5cbfecd3..cdd51aa9fa3e 100644 --- a/pkgs/tools/system/collectd/default.nix +++ b/pkgs/tools/system/collectd/default.nix @@ -2,6 +2,7 @@ , autoreconfHook , pkg-config , libtool +, nixosTests , ... }@args: let @@ -41,6 +42,10 @@ stdenv.mkDerivation rec { enableParallelBuilding = true; + passthru.tests = { + inherit (nixosTests) collectd; + }; + meta = with lib; { description = "Daemon which collects system performance statistics periodically"; homepage = "https://collectd.org";