-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathvm.nix
98 lines (87 loc) · 3.1 KB
/
vm.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{ pkgs, system, hydra-cli }:
let
jobSuccess = pkgs.writeTextDir "job.nix" ''
{ success = builtins.derivation {
name = "success";
system = "x86_64-linux";
builder = "/bin/sh";
args = ["-c" "echo success > $out; exit 0"];
};
}
'';
jobFail = pkgs.writeTextDir "job.nix" ''
{ fail = builtins.derivation {
name = "fail";
system = "x86_64-linux";
builder = "/bin/sh";
args = ["-c" "sleep 5; echo fail > $out; exit 1"];
};
}
'';
mkJobset = description: path: pkgs.writeTextFile {
name = "jobset.json";
text = builtins.toJSON {
inherit description;
checkinterval = 60;
enabled = 1;
visible = true;
keepnr = 1;
nixexprinput = "expr";
nixexprpath = "job.nix";
inputs = {
expr = {
value = path;
type = "path";
};
};
};
};
jobsetSuccess = mkJobset "Success" jobSuccess;
jobsetFail = mkJobset "Fail" jobFail;
in
pkgs.nixosTest {
name = "hydra";
nodes.machine = { pkgs, ... }:
{
virtualisation.memorySize = 1024;
time.timeZone = "UTC";
networking.firewall.allowedTCPPorts = [ 3000 ];
environment.systemPackages = [ hydra-cli ];
services.hydra = {
enable = true;
package = pkgs.hydra-unstable;
#Hydra needs those settings to start up, so we add something not harmfull.
hydraURL = "example.com";
notificationSender = "[email protected]";
};
nix = {
buildMachines = [{
hostName = "localhost";
systems = [ "x86_64-linux" ];
}];
settings.substituters = pkgs.lib.mkForce [];
};
};
testScript = ''
# let the system boot up
machine.wait_for_unit("multi-user.target");
# test whether the database is running
machine.succeed("systemctl status postgresql.service");
# test whether the actual hydra daemons are running
machine.succeed("systemctl status hydra-queue-runner.service");
machine.succeed("systemctl status hydra-init.service");
machine.succeed("systemctl status hydra-evaluator.service");
machine.succeed("systemctl status hydra-send-stats.service");
machine.succeed("hydra-create-user admin --role admin --password admin");
# create a project with a trivial job
machine.wait_for_open_port(3000);
machine.succeed("hydra-cli -H http://localhost:3000 project-create test --password admin --user admin");
machine.succeed("hydra-cli -H http://localhost:3000 project-list | grep -q test");
machine.succeed("hydra-cli -H http://localhost:3000 jobset-create test success ${jobsetSuccess} --password admin --user admin ");
machine.succeed("hydra-cli -H http://localhost:3000 jobset-wait test success");
machine.succeed("hydra-cli -H http://localhost:3000 jobset-eval test success");
machine.succeed("hydra-cli -H http://localhost:3000 jobset-create test fail ${jobsetFail} --password admin --user admin");
machine.fail("hydra-cli -H http://localhost:3000 jobset-wait test fail");
machine.succeed("hydra-cli -H http://localhost:3000 jobset-eval test fail");
'';
}