Merge pull request #64810 from WilliButz/grafana-extend-test

nixos/tests: extend grafana test, nixos/grafana: use group grafana instead of nogroup
This commit is contained in:
Aaron Andersen 2019-07-15 20:43:36 -04:00 committed by GitHub
commit ee1231890d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 80 additions and 12 deletions

View file

@ -552,6 +552,8 @@ in {
description = "Grafana user";
home = cfg.dataDir;
createHome = true;
group = "grafana";
};
users.groups.grafana = {};
};
}

View file

@ -1,25 +1,91 @@
import ./make-test.nix ({ lib, ... }:
{
name = "grafana";
import ./make-test.nix ({ lib, pkgs, ... }:
meta = with lib.maintainers; {
maintainers = [ willibutz ];
};
let
inherit (lib) mkMerge nameValuePair maintainers;
machine = { ... }: {
baseGrafanaConf = {
services.grafana = {
enable = true;
addr = "localhost";
analytics.reporting.enable = false;
domain = "localhost";
security.adminUser = "testusername";
security = {
adminUser = "testadmin";
adminPassword = "snakeoilpwd";
};
};
};
extraNodeConfs = {
postgresql = {
services.grafana.database = {
host = "127.0.0.1:5432";
user = "grafana";
};
services.postgresql = {
enable = true;
ensureDatabases = [ "grafana" ];
ensureUsers = [{
name = "grafana";
ensurePermissions."DATABASE grafana" = "ALL PRIVILEGES";
}];
};
systemd.services.grafana.after = [ "postgresql.service" ];
};
mysql = {
services.grafana.database.user = "grafana";
services.mysql = {
enable = true;
ensureDatabases = [ "grafana" ];
ensureUsers = [{
name = "grafana";
ensurePermissions."grafana.*" = "ALL PRIVILEGES";
}];
package = pkgs.mariadb;
};
systemd.services.grafana.after = [ "mysql.service" ];
};
};
nodes = builtins.listToAttrs (map (dbName:
nameValuePair dbName (mkMerge [
baseGrafanaConf
(extraNodeConfs.${dbName} or {})
])) [ "sqlite" "postgresql" "mysql" ]);
in {
name = "grafana";
meta = with maintainers; {
maintainers = [ willibutz ];
};
inherit nodes;
testScript = ''
$machine->start;
$machine->waitForUnit("grafana.service");
$machine->waitForOpenPort(3000);
$machine->succeed("curl -sSfL http://127.0.0.1:3000/");
startAll();
subtest "Grafana sqlite", sub {
$sqlite->waitForUnit("grafana.service");
$sqlite->waitForOpenPort(3000);
$sqlite->succeed("curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/org/users | grep -q testadmin\@localhost");
};
subtest "Grafana postgresql", sub {
$postgresql->waitForUnit("grafana.service");
$postgresql->waitForUnit("postgresql.service");
$postgresql->waitForOpenPort(3000);
$postgresql->waitForOpenPort(5432);
$postgresql->succeed("curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/org/users | grep -q testadmin\@localhost");
};
subtest "Grafana mysql", sub {
$mysql->waitForUnit("grafana.service");
$mysql->waitForUnit("mysql.service");
$mysql->waitForOpenPort(3000);
$mysql->waitForOpenPort(3306);
$mysql->succeed("curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/org/users | grep -q testadmin\@localhost");
};
'';
})