aboutsummaryrefslogtreecommitdiffstats
path: root/build/plugins/tests/test_requirements.py
blob: 0c41fbaad0c692118c61bd0a43654a0da22db08e (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
import pytest

import build.plugins._requirements as requirements
import build.plugins.lib.test_const as consts


class TestRequirements(object):
    @pytest.mark.parametrize('test_size', consts.TestSize.sizes())
    def test_cpu(self, test_size):
        max_cpu = consts.TestSize.get_max_requirements(test_size).get(consts.TestRequirements.Cpu)
        min_cpu = consts.TestRequirementsConstants.MinCpu
        assert requirements.check_cpu(-1, test_size)
        assert requirements.check_cpu(min_cpu - 1, test_size)
        assert requirements.check_cpu("unknown", test_size)
        assert not requirements.check_cpu(1, test_size)
        assert not requirements.check_cpu(3, test_size)
        assert requirements.check_cpu(1000, test_size)
        if max_cpu != consts.TestRequirementsConstants.All:
            assert requirements.check_cpu(max_cpu + 1, test_size)
            assert requirements.check_cpu(max_cpu + 4, test_size)
            assert requirements.check_cpu(consts.TestRequirementsConstants.All, test_size)
        else:
            assert not requirements.check_cpu(consts.TestRequirementsConstants.All, test_size)

    @pytest.mark.parametrize('test_size', consts.TestSize.sizes())
    def test_ram(self, test_size):
        max_ram = consts.TestSize.get_max_requirements(test_size).get(consts.TestRequirements.Ram)
        min_ram = consts.TestRequirementsConstants.MinRam
        assert requirements.check_ram(-1, test_size)
        assert requirements.check_ram(min_ram - 1, test_size)
        assert requirements.check_ram(max_ram + 1, test_size)
        assert not requirements.check_ram(1, test_size)
        assert not requirements.check_ram(4, test_size)
        assert not requirements.check_ram(5, test_size)
        assert not requirements.check_ram(32, consts.TestSize.Large)
        assert requirements.check_ram(48, consts.TestSize.Large)

        assert not requirements.check_ram(1, test_size, is_kvm=True)
        assert not requirements.check_ram(4, test_size, is_kvm=True)
        assert not requirements.check_ram(16, test_size, is_kvm=True)
        assert requirements.check_ram(32, test_size, is_kvm=True)

    @pytest.mark.parametrize('test_size', consts.TestSize.sizes())
    def test_ram_disk(self, test_size):
        max_ram_disk = consts.TestSize.get_max_requirements(test_size).get(consts.TestRequirements.RamDisk)
        min_ram_disk = consts.TestRequirementsConstants.MinRamDisk
        assert requirements.check_ram_disk(-1, test_size)
        assert requirements.check_ram_disk(min_ram_disk - 1, test_size)
        assert requirements.check_ram_disk(max_ram_disk + 1, test_size)
        assert requirements.check_ram_disk(33, test_size)
        assert not requirements.check_ram_disk(32, test_size)
        assert not requirements.check_ram_disk(1, test_size)
        assert not requirements.check_ram_disk(4, test_size)
        assert not requirements.validate_ram_disk_requirement(
            'ram_disk', '0', test_size, False, True, False, False, False, 1
        )
        assert not requirements.validate_ram_disk_requirement(
            'ram_disk', '1', test_size, False, True, False, False, False, 1
        )
        assert not requirements.validate_ram_disk_requirement(
            'ram_disk', '1', test_size, True, True, False, False, False, 0
        )
        assert not requirements.validate_ram_disk_requirement(
            'ram_disk', '1', test_size, False, False, False, False, False, 0
        )
        if test_size != consts.TestSize.Large:
            assert requirements.validate_ram_disk_requirement(
                'ram_disk', '1', test_size, False, True, False, False, False, 0
            )
            assert requirements.validate_ram_disk_requirement(
                'ram_disk', '1', test_size, False, True, True, False, False, 0
            )
            assert requirements.validate_ram_disk_requirement(
                'ram_disk', '1', test_size, False, True, False, True, False, 0
            )
            assert requirements.validate_ram_disk_requirement(
                'ram_disk', '1', test_size, False, True, False, False, True, 0
            )
        else:
            assert not requirements.validate_ram_disk_requirement(
                'ram_disk', '1', test_size, False, True, False, False, False, 0
            )
            assert not requirements.validate_ram_disk_requirement(
                'ram_disk', '1', test_size, False, True, True, False, False, 0
            )
            assert not requirements.validate_ram_disk_requirement(
                'ram_disk', '1', test_size, False, True, False, True, False, 0
            )
            assert not requirements.validate_ram_disk_requirement(
                'ram_disk', '1', test_size, False, True, False, False, True, 0
            )