-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a unit test for validating address pools
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...iddlewared/middlewared/pytest/unit/plugins/docker/test_docker_address_pools_validtaion.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,44 @@ | ||
import pytest | ||
|
||
from middlewared.plugins.docker.validation_utils import validate_address_pools | ||
from middlewared.service_exception import ValidationErrors | ||
|
||
|
||
IP_IN_USE = [ | ||
{ | ||
'type': 'INET', | ||
'address': '172.20.0.33', | ||
'netmask': 16, | ||
'broadcast': '172.20.0.63' | ||
} | ||
] | ||
|
||
|
||
@pytest.mark.parametrize('user_specified_networks,error_msg', ( | ||
( | ||
[], | ||
'At least one address pool must be specified'), | ||
( | ||
[{'base': '172.20.2.0/24', 'size': 27}], | ||
'Base network 172.20.2.0/24 overlaps with an existing system network'), | ||
( | ||
[{'base': '172.21.2.0/16', 'size': 10}], | ||
'Base network 172.21.2.0/16 cannot be smaller than the specified subnet size 10'), | ||
( | ||
[{'base': '172.21.2.0/16', 'size': 27}, {'base': '172.21.2.0/16', 'size': 27}], | ||
'Base network 172.21.2.0/16 is a duplicate of another specified network' | ||
), | ||
( | ||
[{'base': '172.21.0.0/16', 'size': 27}, {'base': '172.22.0.0/16', 'size': 27}], | ||
'' | ||
), | ||
)) | ||
@pytest.mark.asyncio | ||
async def test_address_pools_validation(user_specified_networks, error_msg): | ||
if error_msg: | ||
with pytest.raises(ValidationErrors) as ve: | ||
validate_address_pools(IP_IN_USE, user_specified_networks) | ||
|
||
assert ve.value.errors[0].errmsg == error_msg | ||
else: | ||
assert validate_address_pools(IP_IN_USE, user_specified_networks) is None |