Skip to content

Commit

Permalink
Add a unit test for validating address pools
Browse files Browse the repository at this point in the history
  • Loading branch information
sonicaj committed Sep 3, 2024
1 parent 52919c6 commit 1c41b42
Showing 1 changed file with 44 additions and 0 deletions.
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

0 comments on commit 1c41b42

Please sign in to comment.