about summary refs log tree commit diff
path: root/nixos/tests/mesos.nix
blob: 34671df047c8ce228948842d9c89d6f03da8f65e (plain) (blame)
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
import ./make-test.nix ({ pkgs, ...} : rec {
  name = "mesos";
  meta = with pkgs.stdenv.lib.maintainers; {
    maintainers = [ offline kamilchm cstrahan ];
  };

  nodes = {
    master = { config, pkgs, ... }: {
      networking.firewall.enable = false;
      services.zookeeper.enable = true;
      services.mesos.master = {
          enable = true;
          zk = "zk://master:2181/mesos";
      };
    };

    slave = { config, pkgs, ... }: {
      networking.firewall.enable = false;
      networking.nat.enable = true;
      virtualisation.docker.enable = true;
      services.mesos = {
        slave = {
          enable = true;
          master = "master:5050";
          dockerRegistry = registry;
          executorEnvironmentVariables = {
            PATH = "/run/current-system/sw/bin";
          };
        };
      };
    };
  };

  simpleDocker = pkgs.dockerTools.buildImage {
    name = "echo";
    contents = [ pkgs.stdenv.shellPackage pkgs.coreutils ];
    config = {
      Env = [
        # When shell=true, mesos invokes "sh -c '<cmd>'", so make sure "sh" is
        # on the PATH.
        "PATH=${pkgs.stdenv.shellPackage}/bin:${pkgs.coreutils}/bin"
      ];
      Entrypoint = [ "echo" ];
    };
  };

  registry = pkgs.runCommand "registry" { } ''
    mkdir -p $out
    cp ${simpleDocker} $out/echo:latest.tar
  '';

  testFramework = pkgs.pythonPackages.buildPythonPackage {
    name = "mesos-tests";
    propagatedBuildInputs = [ pkgs.mesos ];
    catchConflicts = false;
    src = ./mesos_test.py;
    phases = [ "installPhase" "fixupPhase" ];
    installPhase = ''
      install -Dvm 0755 $src $out/bin/mesos_test.py

      echo "done" > test.result
      tar czf $out/test.tar.gz test.result
    '';
  };

  testScript =
    ''
      startAll;
      $master->waitForUnit("mesos-master.service");
      $slave->waitForUnit("mesos-slave.service");

      $master->waitForOpenPort(5050);
      $slave->waitForOpenPort(5051);

      # is slave registered?
      $master->waitUntilSucceeds("curl -s --fail http://master:5050/master/slaves".
                                 " | grep -q \"\\\"hostname\\\":\\\"slave\\\"\"");

      # try to run docker image
      $master->succeed("${pkgs.mesos}/bin/mesos-execute --master=master:5050".
                       " --resources=\"cpus:0.1;mem:32\" --name=simple-docker".
                       " --containerizer=mesos --docker_image=echo:latest".
                       " --shell=true --command=\"echo done\" | grep -q TASK_FINISHED");

      # simple command with .tar.gz uri
      $master->succeed("${testFramework}/bin/mesos_test.py master ".
                       "${testFramework}/test.tar.gz");
    '';
})