Fix for ttl values

Fixing ttl values validation at api level when used during
domain and record creation or updation

Also contains api test cases for zero ttl values.

Partial-Bug: #1220354

Change-Id: I4461ab92d5ff85eec700aca84304b7368847a98f
This commit is contained in:
sonu.kumar 2015-07-09 10:15:13 +05:30
parent 233726639a
commit 1993c74386
6 changed files with 42 additions and 5 deletions

View File

@ -59,7 +59,7 @@ class Domain(base.DictObjectMixin, base.SoftDeleteObjectMixin,
'ttl': { 'ttl': {
'schema': { 'schema': {
'type': ['integer', 'null'], 'type': ['integer', 'null'],
'minimum': 0, 'minimum': 1,
'maximum': 2147483647 'maximum': 2147483647
}, },
}, },

View File

@ -112,7 +112,7 @@ class RecordSet(base.DictObjectMixin, base.PersistentObjectMixin,
'schema': { 'schema': {
'type': ['integer', 'null'], 'type': ['integer', 'null'],
'description': 'Default time to live', 'description': 'Default time to live',
'minimum': 0, 'minimum': 1,
'maximum': 2147483647 'maximum': 2147483647
}, },
}, },

View File

@ -32,7 +32,7 @@
"ttl": { "ttl": {
"type": "integer", "type": "integer",
"description": "Time to live", "description": "Time to live",
"minimum": 0, "minimum": 1,
"maximum": 2147483647 "maximum": 2147483647
}, },
"serial": { "serial": {

View File

@ -48,7 +48,7 @@
"ttl": { "ttl": {
"type": ["integer", "null"], "type": ["integer", "null"],
"description": "Time to live", "description": "Time to live",
"minimum": 0, "minimum": 1,
"maximum": 2147483647 "maximum": 2147483647
}, },
"description": { "description": {

View File

@ -87,6 +87,12 @@ class ApiV1DomainsTest(ApiV1Test):
fixture['ttl'] = -1 fixture['ttl'] = -1
self.post('domains', data=fixture, status_code=400) self.post('domains', data=fixture, status_code=400)
def test_create_domain_zero_ttl(self):
# Create a domain
fixture = self.get_domain_fixture(0)
fixture['ttl'] = 0
self.post('domains', data=fixture, status_code=400)
def test_create_domain_invalid_ttl(self): def test_create_domain_invalid_ttl(self):
# Create a domain # Create a domain
fixture = self.get_domain_fixture(0) fixture = self.get_domain_fixture(0)
@ -278,6 +284,14 @@ class ApiV1DomainsTest(ApiV1Test):
self.put('domains/%s' % domain['id'], data=data, status_code=400) self.put('domains/%s' % domain['id'], data=data, status_code=400)
def test_update_domain_zero_ttl(self):
# Create a domain
domain = self.create_domain()
data = {'ttl': 0}
self.put('domains/%s' % domain['id'], data=data, status_code=400)
@patch.object(central_service.Service, 'update_domain', @patch.object(central_service.Service, 'update_domain',
side_effect=messaging.MessagingTimeout()) side_effect=messaging.MessagingTimeout())
def test_update_domain_timeout(self, _): def test_update_domain_timeout(self, _):

View File

@ -96,7 +96,7 @@ class ApiV1RecordsTest(ApiV1Test):
# Get the record 2 to ensure recordset did not get deleted # Get the record 2 to ensure recordset did not get deleted
rec_2_get_response = self.get('domains/%s/records/%s' % rec_2_get_response = self.get('domains/%s/records/%s' %
(self.domain['id'], record_2.json['id'])) (self.domain['id'], record_2.json['id']))
self.assertIn('id', rec_2_get_response.json) self.assertIn('id', rec_2_get_response.json)
self.assertIn('name', rec_2_get_response.json) self.assertIn('name', rec_2_get_response.json)
@ -210,6 +210,20 @@ class ApiV1RecordsTest(ApiV1Test):
self.post('domains/%s/records' % self.domain['id'], data=fixture, self.post('domains/%s/records' % self.domain['id'], data=fixture,
status_code=400) status_code=400)
def test_create_record_zero_ttl(self):
fixture = self.get_record_fixture(self.recordset['type'])
fixture.update({
'name': self.recordset['name'],
'type': self.recordset['type'],
})
# Set the TTL to a value zero
fixture['ttl'] = 0
# Create a record, Ensuring it Fails with a 400
self.post('domains/%s/records' % self.domain['id'], data=fixture,
status_code=400)
def test_create_record_invalid_ttl(self): def test_create_record_invalid_ttl(self):
fixture = self.get_record_fixture(self.recordset['type']) fixture = self.get_record_fixture(self.recordset['type'])
fixture.update({ fixture.update({
@ -466,6 +480,15 @@ class ApiV1RecordsTest(ApiV1Test):
self.put('domains/%s/records/%s' % (self.domain['id'], record['id']), self.put('domains/%s/records/%s' % (self.domain['id'], record['id']),
data=data, status_code=400) data=data, status_code=400)
def test_update_record_zero_ttl(self):
# Create a record
record = self.create_record(self.domain, self.recordset)
data = {'ttl': 0}
self.put('domains/%s/records/%s' % (self.domain['id'], record['id']),
data=data, status_code=400)
def test_update_record_invalid_ttl(self): def test_update_record_invalid_ttl(self):
# Create a record # Create a record
record = self.create_record(self.domain, self.recordset) record = self.create_record(self.domain, self.recordset)