summary refs log tree commit diff
path: root/nixos/tests/blivet.nix
blob: 2adc2ee1eeea3fba543ee4c4925b9cdc4e67508d (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
import ./make-test.nix ({ pkgs, ... }: with pkgs.python2Packages; rec {
  name = "blivet";
  meta = with pkgs.stdenv.lib.maintainers; {
    maintainers = [ aszlig ];
  };

  machine = {
    environment.systemPackages = [ pkgs.python blivet mock ];
    boot.supportedFilesystems = [ "btrfs" "jfs" "reiserfs" "xfs" ];
    virtualisation.memorySize = 768;
  };

  debugBlivet       = false;
  debugProgramCalls = false;

  pythonTestRunner = pkgs.writeText "run-blivet-tests.py" ''
    import sys
    import logging

    from unittest import TestLoader
    from unittest.runner import TextTestRunner

    ${pkgs.lib.optionalString debugProgramCalls ''
      blivet_program_log = logging.getLogger("program")
      blivet_program_log.setLevel(logging.DEBUG)
      blivet_program_log.addHandler(logging.StreamHandler(sys.stderr))
    ''}

    ${pkgs.lib.optionalString debugBlivet ''
      blivet_log = logging.getLogger("blivet")
      blivet_log.setLevel(logging.DEBUG)
      blivet_log.addHandler(logging.StreamHandler(sys.stderr))
    ''}

    runner = TextTestRunner(verbosity=2, failfast=False, buffer=False)
    result = runner.run(TestLoader().discover('tests/', pattern='*_test.py'))
    sys.exit(not result.wasSuccessful())
  '';

  blivetTest = pkgs.writeScript "blivet-test.sh" ''
    #!${pkgs.stdenv.shell} -e

    # Use the hosts temporary directory, because we have a tmpfs within the VM
    # and we don't want to increase the memory size of the VM for no reason.
    mkdir -p /tmp/xchg/bigtmp
    TMPDIR=/tmp/xchg/bigtmp
    export TMPDIR

    cp -Rd "${blivet.src}/tests" .

    # Skip SELinux tests
    rm -f tests/formats_test/selinux_test.py

    # Race conditions in growing/shrinking during resync
    rm -f tests/devicelibs_test/mdraid_*

    # Deactivate small BTRFS device test, because it fails with newer btrfsprogs
    sed -i -e '/^class *BTRFSAsRootTestCase3(/,/^[^ ]/ {
      /^class *BTRFSAsRootTestCase3(/d
      /^$/d
      /^ /d
    }' tests/devicelibs_test/btrfs_test.py

    # How on earth can these tests ever work even upstream? O_o
    sed -i -e '/def testDiskChunk[12]/,/^ *[^ ]/{n; s/^ */&return # /}' \
      tests/partitioning_test.py

    # fix hardcoded temporary directory
    sed -i \
      -e '1i import tempfile' \
      -e 's|_STORE_FILE_PATH = .*|_STORE_FILE_PATH = tempfile.gettempdir()|' \
      -e 's|DEFAULT_STORE_SIZE = .*|DEFAULT_STORE_SIZE = 409600|' \
      tests/loopbackedtestcase.py

    PYTHONPATH=".:$(< "${pkgs.stdenv.mkDerivation {
      name = "blivet-pythonpath";
      buildInputs = [ blivet mock ];
      buildCommand = "echo \"$PYTHONPATH\" > \"$out\"";
    }}")" python "${pythonTestRunner}"
  '';

  testScript = ''
    $machine->waitForUnit("multi-user.target");
    $machine->succeed("${blivetTest}");
    $machine->execute("rm -rf /tmp/xchg/bigtmp");
  '';
})