Let the IP range validation fail on low IP range

The validation that checks the number of available IPs on the ctlplane
currently succeeds with warnings if the number is too low.

This patch makes the validation fail if the IP range is below the
recommended minimum.

Change-Id: I40b8a34631086cfe8481b8f2acee84461ad3dafe
Closes-Bug: #1713483
This commit is contained in:
Florian Fuchs 2017-08-28 11:57:53 +02:00
parent ddc025d472
commit 940096d719
3 changed files with 16 additions and 10 deletions

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Instead of only outputting a warning, the IP range validation now fails if
the number of available addresses is lower than the recommended minimum.
(Fixes https://bugs.launchpad.net/tripleo/+bug/1713483)

View File

@ -57,9 +57,9 @@ class TestIPRange(base.TestCase):
def test_check_IP_range_too_small(self):
'''Test ip_range when range is less than minimal'''
warnings = validation.check_IP_range('192.168.0.1', '192.168.0.5', 6)
self.assertEqual(len(warnings), 2)
errors = validation.check_IP_range('192.168.0.1', '192.168.0.5', 6)
self.assertEqual(len(errors), 2)
self.assertEqual('The IP range 192.168.0.1 - 192.168.0.5 ' +
'contains 5 addresses.', warnings[0])
'contains 5 addresses.', errors[0])
self.assertEqual('This might not be enough for the deployment ' +
'or later scaling.', warnings[1])
'or later scaling.', errors[1])

View File

@ -48,17 +48,17 @@ def check_arguments(start, end, min_size):
def check_IP_range(start, end, min_size):
'''Compare IP range with minimum size'''
warnings = []
errors = []
iprange = netaddr.IPRange(start, end)
if len(iprange) < min_size:
warnings = [
errors = [
'The IP range {} - {} contains {} addresses.'.format(
start, end, len(iprange)),
'This might not be enough for the deployment or later scaling.'
]
return warnings
return errors
def main():
@ -78,10 +78,10 @@ def main():
module.fail_json(msg='\n'.join(errors))
else:
# Check IP range
warnings = check_IP_range(start, end, min_size)
range_errors = check_IP_range(start, end, min_size)
if warnings:
module.exit_json(changed=True, warnings=warnings)
if range_errors:
module.fail_json(msg='\n'.join(range_errors))
else:
module.exit_json(msg='success')