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 Kiran Pawar
parent 63563a5098
commit 536315e38c
2 changed files with 15 additions and 1 deletions

View File

@ -35,6 +35,9 @@ class MX(Record):
if repr(int(priority)) != priority:
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.exchange = exchange

View File

@ -34,7 +34,18 @@ class RRDataMXTest(oslotest.base.BaseTestCase):
record_set = objects.RecordSet(
name='www.example.org.', type='MX',
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'),
])
)