Minmum TTL value is zero

According to IETF https://tools.ietf.org/html/rfc2181#section-8 the
definition of the ttl value is unsigned and can have a minimum
value of 0. This path changes the minimum value of 1 to allow for
0 in recordset creats and updates. Unit test have also been modified
accordingly.

Closes-Bug: #1926429
Change-Id: I9b08e25a007bea598442da377dc227538f6e35f7
This commit is contained in:
dkehn 2022-07-07 10:58:04 +00:00
parent d05232fc07
commit cc660ca021
2 changed files with 41 additions and 17 deletions

View File

@ -89,7 +89,7 @@ class RecordSet(base.DesignateObject, base.DictObjectMixin,
'name': fields.HostField(maxLength=255, nullable=True),
'type': fields.StringFields(nullable=True, read_only=True),
'ttl': fields.IntegerFields(nullable=True,
minimum=1, maximum=2147483647),
minimum=0, maximum=2147483647),
'description': fields.StringFields(nullable=True, maxLength=160),
'records': fields.PolymorphicObjectField('RecordList', nullable=True),
}

View File

@ -56,6 +56,46 @@ class ApiV2RecordSetsTest(ApiV2TestCase):
self.assertEqual('NONE', response.json['action'])
self.assertEqual('ACTIVE', response.json['status'])
def test_create_recordset_with_zero_ttl(self):
fixture = self.get_recordset_fixture(self.zone['name'], fixture=0)
fixture['ttl'] = 0
response = self.client.post_json(
'/zones/%s/recordsets' % self.zone['id'], fixture)
# Check the headers are what we expect
self.assertEqual(201, response.status_int)
self.assertEqual('application/json', response.content_type)
def test_update_recordset_zero_ttl(self):
# Create a recordset
recordset = self.create_recordset(self.zone, records=[])
# Prepare an update body
body = {'ttl': 0}
url = '/zones/%s/recordsets/%s' % (recordset['zone_id'],
recordset['id'])
response = self.client.put_json(url, body, status=200)
# Check the headers are what we expect
self.assertEqual(200, response.status_int)
self.assertEqual('application/json', response.content_type)
# The action and status are NONE and ACTIVE as there are no records
self.assertEqual('NONE', response.json['action'])
self.assertEqual('ACTIVE', response.json['status'])
self.assertEqual(0, response.json['ttl'])
# Check the zone's status is as expected
response = self.client.get('/zones/%s/recordsets/%s' %
(recordset['zone_id'], recordset['id']),
headers=[('Accept', 'application/json')])
# Check the headers are what we expect
self.assertEqual(200, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertEqual(0, response.json['ttl'])
def test_create_recordset_with_records(self):
# Prepare a RecordSet fixture
fixture = self.get_recordset_fixture(
@ -172,14 +212,6 @@ class ApiV2RecordSetsTest(ApiV2TestCase):
self._assert_exception(
'invalid_object', 400, self.client.post_json, url, body)
def test_create_recordset_with_zero_ttl(self):
fixture = self.get_recordset_fixture(self.zone['name'], fixture=0)
fixture['ttl'] = 0
body = fixture
url = '/zones/%s/recordsets' % self.zone['id']
self._assert_exception(
'invalid_object', 400, self.client.post_json, url, body)
def test_create_recordset_with_ttl_greater_than_max(self):
fixture = self.get_recordset_fixture(self.zone['name'], fixture=0)
fixture['ttl'] = 2147483648
@ -708,14 +740,6 @@ class ApiV2RecordSetsTest(ApiV2TestCase):
self._assert_exception('invalid_object', 400,
self.client.put_json, url, body)
def test_update_recordset_zero_ttl(self):
recordset = self.create_recordset(self.zone)
body = {'ttl': 0}
url = '/zones/%s/recordsets/%s' % (recordset['zone_id'],
recordset['id'])
self._assert_exception('invalid_object', 400,
self.client.put_json, url, body)
def test_update_recordset_negative_ttl(self):
recordset = self.create_recordset(self.zone)
body = {'ttl': -1}