forked from openshift/openshift-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add disk and memory availability check tests
- Loading branch information
1 parent
d295518
commit 58fdef2
Showing
3 changed files
with
194 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
roles/openshift_health_checker/test/disk_availability_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import pytest | ||
|
||
from openshift_checks.disk_availability import DiskAvailability, OpenShiftCheckException | ||
|
||
|
||
def test_exception_raised_on_empty_ansible_mounts(): | ||
with pytest.raises(OpenShiftCheckException) as excinfo: | ||
DiskAvailability(execute_module=NotImplementedError).get_openshift_disk_availability([]) | ||
|
||
assert "existing volume mounts from ansible_mounts" in str(excinfo.value) | ||
|
||
|
||
@pytest.mark.parametrize("group_name,size_available", [ | ||
( | ||
"masters", | ||
41110980608, | ||
), | ||
( | ||
"nodes", | ||
21110980608, | ||
), | ||
( | ||
"etcd", | ||
21110980608, | ||
), | ||
]) | ||
def test_volume_check_with_recommended_diskspace(group_name, size_available): | ||
result = DiskAvailability(execute_module=NotImplementedError).run(tmp=None, task_vars=dict( | ||
openshift=dict(common=dict( | ||
service_type='origin', | ||
is_containerized=False, | ||
)), | ||
group_names=[group_name], | ||
ansible_mounts=[{ | ||
"mount": "/", | ||
"size_available": size_available, | ||
}] | ||
)) | ||
|
||
assert not result['failed'] | ||
assert not result['msg'] | ||
|
||
|
||
@pytest.mark.parametrize("group_name,size_available", [ | ||
( | ||
"masters", | ||
21110980608, | ||
), | ||
( | ||
"nodes", | ||
1110980608, | ||
), | ||
( | ||
"etcd", | ||
1110980608, | ||
), | ||
]) | ||
def test_volume_check_with_insufficient_diskspace(group_name, size_available): | ||
result = DiskAvailability(execute_module=NotImplementedError).run(tmp=None, task_vars=dict( | ||
openshift=dict(common=dict( | ||
service_type='origin', | ||
is_containerized=False, | ||
)), | ||
group_names=[group_name], | ||
ansible_mounts=[{ | ||
"mount": "/", | ||
"size_available": size_available, | ||
}] | ||
)) | ||
|
||
assert result['failed'] | ||
assert "is below recommended storage" in result['msg'] | ||
|
||
|
||
def test_volume_check_with_unsupported_mountpaths(): | ||
result = DiskAvailability(execute_module=NotImplementedError).run(tmp=None, task_vars=dict( | ||
openshift=dict(common=dict( | ||
service_type='origin', | ||
is_containerized=False, | ||
)), | ||
group_names=["masters", "nodes"], | ||
ansible_mounts=[{ | ||
"mount": "/unsupported", | ||
"size_available": 12345, | ||
}] | ||
)) | ||
|
||
assert result['failed'] | ||
assert "0 GB" in result['msg'] | ||
|
||
|
||
def test_volume_check_with_invalid_groupname(): | ||
with pytest.raises(OpenShiftCheckException) as excinfo: | ||
result = DiskAvailability(execute_module=NotImplementedError).run(tmp=None, task_vars=dict( | ||
openshift=dict(common=dict( | ||
service_type='origin', | ||
is_containerized=False, | ||
)), | ||
group_names=["invalid"], | ||
ansible_mounts=[{ | ||
"mount": "/unsupported", | ||
"size_available": 12345, | ||
}] | ||
)) | ||
|
||
assert "'invalid'" in str(excinfo.value) |
84 changes: 84 additions & 0 deletions
84
roles/openshift_health_checker/test/memory_availability_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import pytest | ||
|
||
from openshift_checks.memory_availability import MemoryAvailability, OpenShiftCheckException | ||
|
||
|
||
@pytest.mark.parametrize('group_names,is_containerized,is_active', [ | ||
(['masters'], False, True), | ||
# ensure check is skipped on containerized installs | ||
(['masters'], True, True), | ||
(['nodes'], True, True), | ||
(['etcd'], False, True), | ||
(['masters', 'nodes'], False, True), | ||
(['masters', 'etcd'], False, True), | ||
([], False, False), | ||
(['lb'], False, False), | ||
(['nfs'], False, False), | ||
]) | ||
def test_is_active(group_names, is_containerized, is_active): | ||
task_vars = dict( | ||
group_names=group_names, | ||
openshift=dict(common=dict(is_containerized=is_containerized)), | ||
) | ||
assert MemoryAvailability.is_active(task_vars=task_vars) == is_active | ||
|
||
|
||
@pytest.mark.parametrize("group_name,size_available", [ | ||
( | ||
"masters", | ||
17200, | ||
), | ||
( | ||
"nodes", | ||
8200, | ||
), | ||
( | ||
"etcd", | ||
12200, | ||
), | ||
]) | ||
def test_mem_check_with_recommended_memtotal(group_name, size_available): | ||
result = MemoryAvailability(execute_module=NotImplementedError).run(tmp=None, task_vars=dict( | ||
group_names=[group_name], | ||
ansible_memtotal_mb=size_available, | ||
)) | ||
|
||
assert not result.get('failed', False) | ||
|
||
|
||
@pytest.mark.parametrize("group_name,size_available", [ | ||
( | ||
"masters", | ||
1, | ||
), | ||
( | ||
"nodes", | ||
2, | ||
), | ||
( | ||
"etcd", | ||
3, | ||
), | ||
]) | ||
def test_mem_check_with_insufficient_memtotal(group_name, size_available): | ||
result = MemoryAvailability(execute_module=NotImplementedError).run(tmp=None, task_vars=dict( | ||
group_names=[group_name], | ||
ansible_memtotal_mb=size_available, | ||
)) | ||
|
||
assert result['failed'] | ||
assert "below recommended storage" in result['msg'] | ||
|
||
|
||
def test_mem_check_with_invalid_groupname(): | ||
with pytest.raises(OpenShiftCheckException) as excinfo: | ||
result = MemoryAvailability(execute_module=NotImplementedError).run(tmp=None, task_vars=dict( | ||
openshift=dict(common=dict( | ||
service_type='origin', | ||
is_containerized=False, | ||
)), | ||
group_names=["invalid"], | ||
ansible_memtotal_mb=1234567, | ||
)) | ||
|
||
assert "'invalid'" in str(excinfo.value) |