Validate MX records during recordset create or update

If invalid MX record is provided during recordset create command or
valid record is updated to invalid record using recordset set command,
causes recordset creation/updation failure. This leads to zone enter
in ERROR state and all further recordset creation calls fail. Validate
the records within recordset during create or update call.

Closes-Bug: #1927304
Change-Id: I0ace4d6c4ad6a6ee236e3af23805b01345d60a42
This commit is contained in:
kpdev 2021-05-06 06:56:11 +02:00 committed by Erik Olof Gunnar Andersson
parent d27b006aac
commit 86a8cc5f52
2 changed files with 15 additions and 1 deletions

View File

@ -38,6 +38,9 @@ class MX(Record):
if repr(int(priority)) != priority: if repr(int(priority)) != priority:
raise ValueError('Value is not an integer') raise ValueError('Value is not an integer')
if not exchange.endswith('.'):
raise ValueError('Domain %s does not end with a dot' % exchange)
self.priority = int(priority) self.priority = int(priority)
self.exchange = exchange self.exchange = exchange

View File

@ -34,7 +34,18 @@ class MXRecordTest(oslotest.base.BaseTestCase):
record_set = objects.RecordSet( record_set = objects.RecordSet(
name='www.example.org.', type='MX', name='www.example.org.', type='MX',
records=objects.RecordList(objects=[ records=objects.RecordList(objects=[
objects.Record(data='-0 mail.example.org.', objects.Record(data='-0 mail.example.test.',
status='ACTIVE'),
])
)
self.assertRaises(InvalidObject, record_set.validate)
def test_validate_mx_not_fqdn(self):
record_set = objects.RecordSet(
name='www.example.org.', type='MX',
records=objects.RecordList(objects=[
objects.Record(data='10 mail.example.test',
status='ACTIVE'), status='ACTIVE'),
]) ])
) )