Apply validation on designate zone prefix values

This patch applies validation on values ipv4-ptr-zone-prefix-size and
ipv6-ptr-zone-prefix-size to prevent users from choosing values not
supported by Neutron's Designate driver.

Change-Id: I6f2d5c9d1a3f16242263f11b1f999ab7ec3a4266
Signed-off-by: Stamatis Katsaounis <katsaouniss@gmail.com>
This commit is contained in:
Stamatis Katsaounis 2019-06-30 20:09:23 +03:00
parent fc2a172b9b
commit 1967d7794d
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'))