Merge "Apply validation on designate zone prefix values"

This commit is contained in:
Zuul 2019-10-30 11:27:02 +00:00 committed by Gerrit Code Review
commit cba1418590
3 changed files with 57 additions and 0 deletions

View File

@ -737,6 +737,8 @@ options:
default: 24
description: |
The size in bits of the prefix for the IPv4 reverse lookup (PTR) zones.
Valid size has to be multiple of 8, with maximum value of 24 and minimum
value of 8.
.
NOTE: Use only when "reverse-dns-lookup" option is set to "True".
ipv6-ptr-zone-prefix-size:
@ -744,6 +746,8 @@ options:
default: 64
description: |
The size in bits of the prefix for the IPv6 reverse lookup (PTR) zones.
Valid size has to be multiple of 4, with maximum value of 124 and minimum
value of 4.
.
NOTE: Use only when "reverse-dns-lookup" option is set to "True".
dhcp-load-type:

View File

@ -838,6 +838,33 @@ def check_optional_relations(configs):
:param configs: an OSConfigRender() instance.
:return 2-tuple: (string, string) = (status, message)
"""
if relation_ids('external-dns'):
if config('designate_endpoint') is not None:
if config('reverse-dns-lookup'):
ipv4_prefix_size = config('ipv4-ptr-zone-prefix-size')
valid_ipv4_prefix_size = (
(8 <= ipv4_prefix_size <= 24) and
(ipv4_prefix_size % 8) == 0)
if not valid_ipv4_prefix_size:
log('Invalid ipv4-ptr-zone-prefix-size. Value of '
'ipv4-ptr-zone-prefix-size has to be multiple'
' of 8, with maximum value of 24 and minimum value '
'of 8.', level=DEBUG)
return ('blocked',
'Invalid configuration: '
'ipv4-ptr-zone-prefix-size')
ipv6_prefix_size = config('ipv6-ptr-zone-prefix-size')
valid_ipv6_prefix_size = (
(4 <= ipv6_prefix_size <= 124) and
(ipv6_prefix_size % 4) == 0)
if not valid_ipv6_prefix_size:
log('Invalid ipv6-ptr-zone-prefix-size. Value of '
'ipv6-ptr-zone-prefix-size has to be multiple'
' of 4, with maximum value of 124 and minimum value '
'of 4.', level=DEBUG)
return ('blocked',
'Invalid configuration: '
'ipv6-ptr-zone-prefix-size')
if relation_ids('ha'):
try:
get_hacluster_config()

View File

@ -871,3 +871,29 @@ class TestNeutronAPIUtils(CharmTestCase):
"pymysql+mysql://testuser:testpassword@testhost/testdatabase"
"?ssl_ca=foo&ssl_cert=bar&ssl_key=baz"
)
@patch.object(nutils, 'config')
@patch.object(nutils, 'relation_ids')
@patch.object(nutils, 'log')
def test_check_optional_relations_invalid_ipv4(self,
log,
relation_ids,
config):
relation_ids.return_value = True
config.side_effect = [True, True, 23]
self.assertEqual(
nutils.check_optional_relations(None),
('blocked', 'Invalid configuration: ipv4-ptr-zone-prefix-size'))
@patch.object(nutils, 'config')
@patch.object(nutils, 'relation_ids')
@patch.object(nutils, 'log')
def test_check_optional_relations_invalid_ipv6(self,
log,
relation_ids,
config):
relation_ids.return_value = True
config.side_effect = [True, True, 24, 63]
self.assertEqual(
nutils.check_optional_relations(None),
('blocked', 'Invalid configuration: ipv6-ptr-zone-prefix-size'))