git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #11870 from lancelotsix/improve_slurm_service

Improve slurm service configuration

commit7e14e28a80c2de6af7c338e8d4651cf222fbb69e authorArseniy Seroka <jagajaga@users.noreply.github.com> dateFri 25 Dec 2015, 18:36 (11 years ago) parent230c4684994f0f
2 files changed+128−8
nixos/modules/services/computing/slurm/slurm.nix+48−8 nixos/tests/slurm.nix+80
nixos/modules/services/computing/slurm/slurm.nix+48−8
@@ -34,6 +34,15 @@ in
3434
3535 };
3636
37+ package = mkOption {
38+ type = types.package;
39+ default = pkgs.slurm-llnl;
40+ example = literalExample "pkgs.slurm-llnl-full";
41+ description = ''
42+ The packge to use for slurm binaries.
43+ '';
44+ };
45+
3746 controlMachine = mkOption {
3847 type = types.nullOr types.str;
3948 default = null;
@@ -91,38 +100,69 @@ in
91100
92101 ###### implementation
93102
94− config = mkIf (cfg.client.enable || cfg.server.enable) {
103+ config =
104+ let
105+ wrappedSlurm = pkgs.stdenv.mkDerivation {
106+ name = "wrappedSlurm";
107+
108+ propagatedBuildInputs = [ cfg.package configFile ];
109+
110+ builder = pkgs.writeText "builder.sh" ''
111+ source $stdenv/setup
112+ mkdir -p $out/bin
113+ find ${cfg.package}/bin -type f -executable | while read EXE
114+ do
115+ exename="$(basename $EXE)"
116+ wrappername="$out/bin/$exename"
117+ cat > "$wrappername" <<EOT
118+ #!/bin/sh
119+ if [ -z "$SLURM_CONF" ]
120+ then
121+ SLURM_CONF="${configFile}" "$EXE" "\$@"
122+ else
123+ "$EXE" "\$0"
124+ fi
125+ EOT
126+ chmod +x "$wrappername"
127+ done
128+ '';
129+ };
95130
96− environment.systemPackages = [ pkgs.slurm-llnl ];
131+ in mkIf (cfg.client.enable || cfg.server.enable) {
132+
133+ environment.systemPackages = [ wrappedSlurm ];
97134
98135 systemd.services.slurmd = mkIf (cfg.client.enable) {
99− path = with pkgs; [ slurm-llnl coreutils ];
136+ path = with pkgs; [ wrappedSlurm coreutils ];
100137
101138 wantedBy = [ "multi-user.target" ];
102139 after = [ "systemd-tmpfiles-clean.service" ];
103140
104141 serviceConfig = {
105142 Type = "forking";
106− ExecStart = "${pkgs.slurm-llnl}/bin/slurmd -f ${configFile}";
143+ ExecStart = "${wrappedSlurm}/bin/slurmd";
107144 PIDFile = "/run/slurmd.pid";
108145 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
109146 };
147+
148+ preStart = ''
149+ mkdir -p /var/spool
150+ '';
110151 };
111152
112153 systemd.services.slurmctld = mkIf (cfg.server.enable) {
113− path = with pkgs; [ slurm-llnl munge coreutils ];
154+ path = with pkgs; [ wrappedSlurm munge coreutils ];
114155
115156 wantedBy = [ "multi-user.target" ];
116− after = [ "network.target" "auditd.service" "munged.service" "slurmdbd.service" ];
157+ after = [ "network.target" "munged.service" ];
117158 requires = [ "munged.service" ];
118159
119160 serviceConfig = {
120161 Type = "forking";
121− ExecStart = "${pkgs.slurm-llnl}/bin/slurmctld";
162+ ExecStart = "${wrappedSlurm}/bin/slurmctld";
122163 PIDFile = "/run/slurmctld.pid";
123164 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
124165 };
125− environment = { SLURM_CONF = "${configFile}"; };
126166 };
127167
128168 };
nixos/tests/slurm.nixnew file+80
@@ -0,0 +1,80 @@
1+import ./make-test.nix ({ pkgs, ... }:
2+let mungekey = "mungeverryweakkeybuteasytointegratoinatest";
3+ slurmconfig = {
4+ client.enable = true;
5+ controlMachine = "control";
6+ nodeName = ''
7+ control
8+ NodeName=node[1-3] CPUs=1 State=UNKNOWN
9+ '';
10+ partitionName = "debug Nodes=node[1-3] Default=YES MaxTime=INFINITE State=UP";
11+ };
12+in {
13+ name = "slurm";
14+
15+ nodes =
16+ let
17+ computeNode =
18+ { config, pkgs, ...}:
19+ {
20+ # TODO slrumd port and slurmctld port should be configurations and
21+ # automatically allowed by the firewall.
22+ networking.firewall.enable = false;
23+ services.munge.enable = true;
24+ services.slurm = slurmconfig;
25+ };
26+ in {
27+ control =
28+ { config, pkgs, ...}:
29+ {
30+ networking.firewall.enable = false;
31+ services.munge.enable = true;
32+ services.slurm = {
33+ server.enable = true;
34+ } // slurmconfig;
35+ };
36+ node1 = computeNode;
37+ node2 = computeNode;
38+ node3 = computeNode;
39+ };
40+
41+ testScript =
42+ ''
43+ startAll;
44+
45+ # Set up authentification across the cluster
46+ foreach my $node (($control,$node1,$node2,$node3))
47+ {
48+ $node->waitForUnit("default.target");
49+
50+ $node->succeed("mkdir /etc/munge");
51+ $node->succeed("echo '${mungekey}' > /etc/munge/munge.key");
52+ $node->succeed("chmod 0400 /etc/munge/munge.key");
53+ $node->succeed("systemctl restart munged");
54+ }
55+
56+ # Restart the services since they have probably failed due to the munge init
57+ # failure
58+
59+ subtest "can_start_slurmctld", sub {
60+ $control->succeed("systemctl restart slurmctld");
61+ $control->waitForUnit("slurmctld.service");
62+ };
63+
64+ subtest "can_start_slurmd", sub {
65+ foreach my $node (($control,$node1,$node2,$node3))
66+ {
67+ $node->succeed("systemctl restart slurmd.service");
68+ $node->waitForUnit("slurmd");
69+ }
70+ };
71+
72+ # Test that the cluster work and can distribute jobs;
73+
74+ subtest "run_distributed_command", sub {
75+ # Run `hostname` on 3 nodes of the partition (so on all the 3 nodes).
76+ # The output must contain the 3 different names
77+ $control->succeed("srun -N 3 hostname | sort | uniq | wc -l | xargs test 3 -eq");
78+ };
79+ '';
80+})