about summary refs log tree commit diff
path: root/nixos/tests/buildbot.nix
blob: 977c728835f0312d9f86dcb907dca3e96223bfa8 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Test ensures buildbot master comes up correctly and workers can connect

{ system ? builtins.currentSystem,
  config ? {},
  pkgs ? import ../.. { inherit system config; }
}:

import ./make-test-python.nix {
  name = "buildbot";

  nodes = {
    bbmaster = { pkgs, ... }: {
      services.buildbot-master = {
        enable = true;

        # NOTE: use fake repo due to no internet in hydra ci
        factorySteps = [
          "steps.Git(repourl='git://gitrepo/fakerepo.git', mode='incremental')"
          "steps.ShellCommand(command=['bash', 'fakerepo.sh'])"
        ];
        changeSource = [
          "changes.GitPoller('git://gitrepo/fakerepo.git', workdir='gitpoller-workdir', branch='master', pollinterval=300)"
        ];
      };
      networking.firewall.allowedTCPPorts = [ 8010 8011 9989 ];
      environment.systemPackages = with pkgs; [ git python3Packages.buildbot-full ];
    };

    bbworker = { pkgs, ... }: {
      services.buildbot-worker = {
        enable = true;
        masterUrl = "bbmaster:9989";
      };
      environment.systemPackages = with pkgs; [ git python3Packages.buildbot-worker ];
    };

    gitrepo = { pkgs, ... }: {
      services.openssh.enable = true;
      networking.firewall.allowedTCPPorts = [ 22 9418 ];
      environment.systemPackages = with pkgs; [ git ];
      systemd.services.git-daemon = {
        description   = "Git daemon for the test";
        wantedBy      = [ "multi-user.target" ];
        after         = [ "network.target" "sshd.service" ];

        serviceConfig.Restart = "always";
        path = with pkgs; [ coreutils git openssh ];
        environment = { HOME = "/root"; };
        preStart = ''
          git config --global user.name 'Nobody Fakeuser'
          git config --global user.email 'nobody\@fakerepo.com'
          rm -rvf /srv/repos/fakerepo.git /tmp/fakerepo
          mkdir -pv /srv/repos/fakerepo ~/.ssh
          ssh-keyscan -H gitrepo > ~/.ssh/known_hosts
          cat ~/.ssh/known_hosts

          mkdir -p /src/repos/fakerepo
          cd /srv/repos/fakerepo
          rm -rf *
          git init
          echo -e '#!/bin/sh\necho fakerepo' > fakerepo.sh
          cat fakerepo.sh
          touch .git/git-daemon-export-ok
          git add fakerepo.sh .git/git-daemon-export-ok
          git commit -m fakerepo
        '';
        script = ''
          git daemon --verbose --export-all --base-path=/srv/repos --reuseaddr
        '';
      };
    };
  };

  testScript = ''
    gitrepo.wait_for_unit("git-daemon.service")
    gitrepo.wait_for_unit("multi-user.target")

    with subtest("Repo is accessible via git daemon"):
        bbmaster.wait_for_unit("network-online.target")
        bbmaster.succeed("rm -rfv /tmp/fakerepo")
        bbmaster.succeed("git clone git://gitrepo/fakerepo /tmp/fakerepo")

    with subtest("Master service and worker successfully connect"):
        bbmaster.wait_for_unit("buildbot-master.service")
        bbmaster.wait_until_succeeds("curl --fail -s --head http://bbmaster:8010")
        bbworker.wait_for_unit("network-online.target")
        bbworker.succeed("nc -z bbmaster 8010")
        bbworker.succeed("nc -z bbmaster 9989")
        bbworker.wait_for_unit("buildbot-worker.service")

    with subtest("Stop buildbot worker"):
        bbmaster.succeed("systemctl -l --no-pager status buildbot-master")
        bbmaster.succeed("systemctl stop buildbot-master")
        bbworker.fail("nc -z bbmaster 8010")
        bbworker.fail("nc -z bbmaster 9989")
        bbworker.succeed("systemctl -l --no-pager status buildbot-worker")
        bbworker.succeed("systemctl stop buildbot-worker")

    with subtest("Buildbot daemon mode works"):
        bbmaster.succeed(
            "buildbot create-master /tmp",
            "mv -fv /tmp/master.cfg.sample /tmp/master.cfg",
            "sed -i 's/8010/8011/' /tmp/master.cfg",
            "buildbot start /tmp",
            "nc -z bbmaster 8011",
        )
        bbworker.wait_until_succeeds("curl --fail -s --head http://bbmaster:8011")
        bbmaster.wait_until_succeeds("buildbot stop /tmp")
        bbworker.fail("nc -z bbmaster 8011")
  '';

  meta.maintainers = with pkgs.lib.maintainers; [ ];
} {}