From 940096d719dd6c19899a89a23c532ce9161c65ea Mon Sep 17 00:00:00 2001 From: Florian Fuchs Date: Mon, 28 Aug 2017 11:57:53 +0200 Subject: [PATCH] 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 --- .../ip-range-validation-result-daddc8c015dd34c0.yaml | 6 ++++++ tripleo_validations/tests/test_ip_range.py | 8 ++++---- validations/library/ip_range.py | 12 ++++++------ 3 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 releasenotes/notes/ip-range-validation-result-daddc8c015dd34c0.yaml diff --git a/releasenotes/notes/ip-range-validation-result-daddc8c015dd34c0.yaml b/releasenotes/notes/ip-range-validation-result-daddc8c015dd34c0.yaml new file mode 100644 index 000000000..58a6a6b63 --- /dev/null +++ b/releasenotes/notes/ip-range-validation-result-daddc8c015dd34c0.yaml @@ -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) diff --git a/tripleo_validations/tests/test_ip_range.py b/tripleo_validations/tests/test_ip_range.py index c1c199099..c492b874b 100644 --- a/tripleo_validations/tests/test_ip_range.py +++ b/tripleo_validations/tests/test_ip_range.py @@ -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]) diff --git a/validations/library/ip_range.py b/validations/library/ip_range.py index 4a172a6a2..9b0375191 100644 --- a/validations/library/ip_range.py +++ b/validations/library/ip_range.py @@ -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')