From 6ac659d241c65c245d8a090768ac7559c32a13f1 Mon Sep 17 00:00:00 2001 From: dekehn Date: Mon, 2 May 2022 23:03:49 +0000 Subject: [PATCH] Minimum TTL value allowed is zero According to ITEF https://tools.ietf.org/html/rfc2181#section-8 the definition of the ttl value is unsigned integer and can have a minimum value of 0. This patch changes the minimum value of 1 to allow for 0. Unit test have also been modified accordingly. Closes-Bug: #1926429 Change-Id: I7876b4c1e2c800b654ca750211ee2e58f3ea4309 --- designate/objects/zone.py | 2 +- designate/tests/test_api/test_v2/test_zones.py | 4 ++-- designate/tests/test_central/test_service.py | 8 ++++---- ...ug-1926429-allow-ttl-min-of-zero-688f7c2cf095d89d.yaml | 8 ++++++++ 4 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 releasenotes/notes/bug-1926429-allow-ttl-min-of-zero-688f7c2cf095d89d.yaml diff --git a/designate/objects/zone.py b/designate/objects/zone.py index fa09187d5..8370d7d0f 100644 --- a/designate/objects/zone.py +++ b/designate/objects/zone.py @@ -31,7 +31,7 @@ class Zone(base.DesignateObject, base.DictObjectMixin, 'tenant_id': fields.StringFields(nullable=True, read_only=False), 'name': fields.DomainField(maxLength=255), 'email': fields.EmailField(maxLength=255, nullable=True), - 'ttl': fields.IntegerFields(nullable=True, minimum=1, + 'ttl': fields.IntegerFields(nullable=True, minimum=0, maximum=2147483647), 'refresh': fields.IntegerFields(nullable=True, minimum=0, maximum=2147483647, read_only=False), diff --git a/designate/tests/test_api/test_v2/test_zones.py b/designate/tests/test_api/test_v2/test_zones.py index 24845ef74..45451d0d6 100644 --- a/designate/tests/test_api/test_v2/test_zones.py +++ b/designate/tests/test_api/test_v2/test_zones.py @@ -139,8 +139,8 @@ class ApiV2ZonesTest(ApiV2TestCase): fixture = self.get_zone_fixture(fixture=0) fixture['ttl'] = 0 body = fixture - self._assert_exception('invalid_object', 400, self.client.post_json, - '/zones', body) + response = self.client.post_json('/zones', body) + self.assertEqual(202, response.status_int) def test_create_zone_ttl_is_greater_than_max(self): fixture = self.get_zone_fixture(fixture=0) diff --git a/designate/tests/test_central/test_service.py b/designate/tests/test_central/test_service.py index 15c6a80de..7a6156cef 100644 --- a/designate/tests/test_central/test_service.py +++ b/designate/tests/test_central/test_service.py @@ -719,18 +719,18 @@ class CentralServiceTest(CentralTestCase): self.policy({'use_low_ttl': '!'}) self.config(min_ttl=100, group='service:central') - context = self.get_context() + context = self.get_context(project_id=1) values = self.get_zone_fixture(fixture=1) - values['ttl'] = 0 + values['ttl'] = 5 - with testtools.ExpectedException(ValueError): + with testtools.ExpectedException(exceptions.InvalidTTL): self.central_service.create_zone( context, objects.Zone.from_dict(values)) def test_create_zone_below_zero_ttl(self): self.policy({'use_low_ttl': '!'}) - self.config(min_ttl=1, + self.config(min_ttl=0, group='service:central') context = self.get_context() diff --git a/releasenotes/notes/bug-1926429-allow-ttl-min-of-zero-688f7c2cf095d89d.yaml b/releasenotes/notes/bug-1926429-allow-ttl-min-of-zero-688f7c2cf095d89d.yaml new file mode 100644 index 000000000..fc157bde3 --- /dev/null +++ b/releasenotes/notes/bug-1926429-allow-ttl-min-of-zero-688f7c2cf095d89d.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + Allows for a minimum TTL value of zero to be used instead of 1. As stated + in RFC https://datatracker.ietf.org/doc/html/rfc2181#section-8. + + .. _bug 1926429: https://bugs.launchpad.net/designate/+bug/1926429 +