Merge "Adds new test case to validate min_ttl equal to Zero"
diff --git a/designate_tempest_plugin/config.py b/designate_tempest_plugin/config.py
index c244b12..f4ca708 100644
--- a/designate_tempest_plugin/config.py
+++ b/designate_tempest_plugin/config.py
@@ -41,7 +41,7 @@
                default=360,
                help="Timeout in seconds to wait for an resource to build."),
     cfg.IntOpt('min_ttl',
-               default=1,
+               default=0,
                help="The minimum value to respect when generating ttls"),
     cfg.ListOpt('nameservers',
                 default=[],
diff --git a/designate_tempest_plugin/data_utils.py b/designate_tempest_plugin/data_utils.py
index d4df276..d148685 100644
--- a/designate_tempest_plugin/data_utils.py
+++ b/designate_tempest_plugin/data_utils.py
@@ -58,7 +58,7 @@
     return 'example@%s' % domain.rstrip('.')
 
 
-def rand_ttl(start=1, end=86400):
+def rand_ttl(start=0, end=86400):
     """Generate a random TTL value
     :return: a random ttl e.g. 165
     :rtype: string
diff --git a/designate_tempest_plugin/tests/api/v2/test_zones.py b/designate_tempest_plugin/tests/api/v2/test_zones.py
index 3555c51..3ab2601 100644
--- a/designate_tempest_plugin/tests/api/v2/test_zones.py
+++ b/designate_tempest_plugin/tests/api/v2/test_zones.py
@@ -182,18 +182,6 @@
             'ZonesClient', 'show_zone', expected_allowed, False, zone['id'],
             headers={'x-auth-sudo-project-id': self.client.project_id})
 
-    @decorators.idempotent_id('49268b24-92de-11eb-9d02-74e5f9e2a801')
-    def test_show_not_existing_zone(self):
-        LOG.info('Fetch non existing zone')
-        self.assertRaises(lib_exc.NotFound,
-            lambda: self.client.show_zone(uuid.uuid1()))
-
-    @decorators.idempotent_id('736e3b50-92e0-11eb-9d02-74e5f9e2a801')
-    def test_use_invalid_id_to_show_zone(self):
-        LOG.info('Fetch the zone using invalid zone ID')
-        with self.assertRaisesDns(lib_exc.BadRequest, 'invalid_uuid', 400):
-            self.client.show_zone(uuid='zahlabut')
-
     @decorators.attr(type='smoke')
     @decorators.idempotent_id('a4791906-6cd6-4d27-9f15-32273db8bb3d')
     def test_delete_zone(self):
@@ -231,12 +219,6 @@
         self.assertEqual(const.DELETE, body['action'])
         self.assertEqual(const.PENDING, body['status'])
 
-    @decorators.idempotent_id('79921370-92e1-11eb-9d02-74e5f9e2a801')
-    def test_delete_non_existing_zone(self):
-        LOG.info('Delete non existing zone')
-        self.assertRaises(lib_exc.NotFound,
-            lambda: self.client.delete_zone(uuid.uuid1()))
-
     @decorators.idempotent_id('5bfa3cfe-5bc8-443b-bf48-cfba44cbb247')
     def test_list_zones(self):
         LOG.info('Create a zone')
@@ -246,7 +228,7 @@
         self.addCleanup(self.wait_zone_delete, self.client, zone['id'])
 
         LOG.info('List zones')
-        _, body = self.client.list_zones()
+        body = self.client.list_zones()[1]
 
         # TODO(kiall): We really want to assert that out newly created zone is
         #              present in the response.
@@ -374,20 +356,6 @@
             "Failed, expect the Serial to not change "
             "when the Description is updated")
 
-    @decorators.idempotent_id('e391e30a-92e0-11eb-9d02-74e5f9e2a801')
-    def test_update_non_existing_zone(self):
-        LOG.info('Update non existing zone')
-        self.assertRaises(lib_exc.NotFound,
-            lambda: self.client.update_zone(
-                uuid.uuid1(), description=data_utils.rand_name()))
-
-    @decorators.idempotent_id('925192f2-0ed8-4591-8fe7-a9fa028f90a0')
-    def test_list_zones_dot_json_fails(self):
-        uri = self.client.get_uri('zones.json')
-
-        self.assertRaises(lib_exc.NotFound,
-            lambda: self.client.get(uri))
-
     @decorators.idempotent_id('d4ce813e-64a5-11eb-9f43-74e5f9e2a801')
     def test_get_primary_zone_nameservers(self):
         # Create a zone and get the associated "pool_id"
@@ -439,6 +407,25 @@
             False, zone['id'],
             headers={'x-auth-sudo-project-id': self.client.project_id})
 
+    @decorators.idempotent_id('9970b632-f2db-11ec-a757-201e8823901f')
+    def test_create_zone_ttl_zero(self):
+        LOG.info('Create a PRIMARY zone')
+        zone_name = dns_data_utils.rand_zone_name(
+            name="test_create_zone_ttl_zero", suffix=self.tld_name)
+        zone = self.client.create_zone(name=zone_name, ttl=0)[1]
+        self.addCleanup(self.wait_zone_delete, self.client, zone['id'])
+
+        LOG.info('Ensure we respond with CREATE+PENDING')
+        self.assertEqual(const.CREATE, zone['action'])
+        self.assertEqual(const.PENDING, zone['status'])
+
+        LOG.info('Fetch the zone, ensure TTL is Zero')
+        body = self.client.show_zone(zone['id'])[1]
+        self.assertEqual(
+            0, body['ttl'],
+            "Failed, actual Zone's TTL:{} "
+            "is not Zero".format(body['ttl']))
+
 
 class ZonesAdminTest(BaseZonesTest):
     credentials = ["primary", "admin", "system_admin", "alt"]
@@ -657,3 +644,35 @@
             lib_exc.BadRequest, 'invalid_object', 400,
             self.client.create_zone,
             description=dns_data_utils.rand_zone_name() * 10000)
+
+    @decorators.idempotent_id('49268b24-92de-11eb-9d02-74e5f9e2a801')
+    def test_show_not_existing_zone(self):
+        LOG.info('Fetch non existing zone')
+        self.assertRaises(lib_exc.NotFound,
+            lambda: self.client.show_zone(uuid.uuid1()))
+
+    @decorators.idempotent_id('736e3b50-92e0-11eb-9d02-74e5f9e2a801')
+    def test_use_invalid_id_to_show_zone(self):
+        LOG.info('Fetch the zone using invalid zone ID')
+        with self.assertRaisesDns(lib_exc.BadRequest, 'invalid_uuid', 400):
+            self.client.show_zone(uuid='zahlabut')
+
+    @decorators.idempotent_id('79921370-92e1-11eb-9d02-74e5f9e2a801')
+    def test_delete_non_existing_zone(self):
+        LOG.info('Delete non existing zone')
+        self.assertRaises(lib_exc.NotFound,
+            lambda: self.client.delete_zone(uuid.uuid1()))
+
+    @decorators.idempotent_id('e391e30a-92e0-11eb-9d02-74e5f9e2a801')
+    def test_update_non_existing_zone(self):
+        LOG.info('Update non existing zone')
+        self.assertRaises(lib_exc.NotFound,
+            lambda: self.client.update_zone(
+                uuid.uuid1(), description=data_utils.rand_name()))
+
+    @decorators.idempotent_id('925192f2-0ed8-4591-8fe7-a9fa028f90a0')
+    def test_list_zones_dot_json_fails(self):
+        uri = self.client.get_uri('zones.json')
+
+        self.assertRaises(lib_exc.NotFound,
+            lambda: self.client.get(uri))