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
from openshift_checks.memory_availability import MemoryAvailability
@pytest.mark.parametrize('group_names,is_active', [
(['masters'], True),
(['nodes'], True),
(['etcd'], True),
(['masters', 'nodes'], True),
(['masters', 'etcd'], True),
([], False),
(['lb'], False),
(['nfs'], False),
])
def test_is_active(group_names, is_active):
task_vars = dict(
group_names=group_names,
)
assert MemoryAvailability.is_active(task_vars=task_vars) == is_active
@pytest.mark.parametrize('group_names,ansible_memtotal_mb', [
(
['masters'],
17200,
),
(
['nodes'],
8200,
),
(
['etcd'],
22200,
),
(
['masters', 'nodes'],
17000,
),
])
def test_succeeds_with_recommended_memory(group_names, ansible_memtotal_mb):
task_vars = dict(
group_names=group_names,
ansible_memtotal_mb=ansible_memtotal_mb,
)
check = MemoryAvailability(execute_module=fake_execute_module)
result = check.run(tmp=None, task_vars=task_vars)
assert not result.get('failed', False)
@pytest.mark.parametrize('group_names,ansible_memtotal_mb,extra_words', [
(
['masters'],
0,
['0.0 GB'],
),
(
['nodes'],
100,
['0.1 GB'],
),
(
['etcd'],
-1,
['0.0 GB'],
),
(
['nodes', 'masters'],
# enough memory for a node, not enough for a master
11000,
['11.0 GB'],
),
])
def test_fails_with_insufficient_memory(group_names, ansible_memtotal_mb, extra_words):
task_vars = dict(
group_names=group_names,
ansible_memtotal_mb=ansible_memtotal_mb,
)
check = MemoryAvailability(execute_module=fake_execute_module)
result = check.run(tmp=None, task_vars=task_vars)
assert result['failed']
for word in 'below recommended'.split() + extra_words:
assert word in result['msg']
def fake_execute_module(*args):
raise AssertionError('this function should not be called')
|