summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordkehn <dekehn@gmail.com>2022-07-07 10:58:04 +0000
committerDon Kehn <dekehn@gmail.com>2022-07-12 15:10:24 +0000
commit2dc40a15894d2c2010b7176ff6f1dff0c8621503 (patch)
treeb5882095e6526b70cd7e3f2c8ea08aead9060854
parent3808102790ca8ccb559c865ddea15876b5a19939 (diff)
downloaddesignate-2dc40a15894d2c2010b7176ff6f1dff0c8621503.tar.gz
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
-rwxr-xr-xdesignate/objects/recordset.py2
-rw-r--r--designate/tests/test_api/test_v2/test_recordsets.py56
2 files changed, 41 insertions, 17 deletions
diff --git a/designate/objects/recordset.py b/designate/objects/recordset.py
index 1fe0c687..e2f1ffbc 100755
--- a/designate/objects/recordset.py
+++ b/designate/objects/recordset.py
@@ -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),
}
diff --git a/designate/tests/test_api/test_v2/test_recordsets.py b/designate/tests/test_api/test_v2/test_recordsets.py
index d69bc044..a2fdd7c3 100644
--- a/designate/tests/test_api/test_v2/test_recordsets.py
+++ b/designate/tests/test_api/test_v2/test_recordsets.py
@@ -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}