From 8f06223e717e7063ead89f192b137465621ddd6c Mon Sep 17 00:00:00 2001 From: Endre Karlson Date: Fri, 27 Mar 2015 15:07:30 +0100 Subject: [PATCH] Sync up FIP behaviour to match latest PoolManager * Add action and status fields from Record or None if no Record for the FIP. * Change status code to 202 for async ops. Closes-Bug: #1433645 Change-Id: I8ee44f1a760bcd23c03acae8e722bb5db5017b93 --- designate/api/v2/controllers/floatingips.py | 4 +++ designate/central/service.py | 27 ++++++++++++------- .../objects/adapters/api_v2/floating_ip.py | 6 +++++ designate/objects/floating_ip.py | 13 +++++++++ .../resources/schemas/v2/floatingip.json | 14 +++++++++- .../test_api/test_v2/test_floatingips.py | 14 ++++++++-- 6 files changed, 65 insertions(+), 13 deletions(-) diff --git a/designate/api/v2/controllers/floatingips.py b/designate/api/v2/controllers/floatingips.py index ae2ababa7..400e76eb2 100644 --- a/designate/api/v2/controllers/floatingips.py +++ b/designate/api/v2/controllers/floatingips.py @@ -60,6 +60,8 @@ class FloatingIPController(rest.RestController): Set or unset a PTR """ request = pecan.request + response = pecan.response + context = request.environ['context'] body = request.body_dict @@ -74,6 +76,8 @@ class FloatingIPController(rest.RestController): id_, objects.FloatingIP().from_dict(body['floatingip'])) + response.status_int = 202 + if fip: return self._view.show(context, request, fip) diff --git a/designate/central/service.py b/designate/central/service.py index 39c79383f..f7febea72 100644 --- a/designate/central/service.py +++ b/designate/central/service.py @@ -1688,34 +1688,41 @@ class Service(service.RPCService, service.Service): fips = objects.FloatingIPList() for key, value in data.items(): + fip, record = value + fip_ptr = objects.FloatingIP().from_dict({ - 'address': value[0]['address'], - 'id': value[0]['id'], - 'region': value[0]['region'], + 'address': fip['address'], + 'id': fip['id'], + 'region': fip['region'], 'ptrdname': None, 'ttl': None, - 'description': None + 'description': None, + 'action': None, + 'status': 'ACTIVE' }) # TTL population requires a present record in order to find the # RS or Zone - if value[1]: + if record: + fip_ptr['action'] = record.action + fip_ptr['status'] = record.status + # We can have a recordset dict passed in if (recordsets is not None and - value[1]['recordset_id'] in recordsets): - recordset = recordsets[value[1]['recordset_id']] + record['recordset_id'] in recordsets): + recordset = recordsets[record['recordset_id']] else: recordset = self.storage.get_recordset( - elevated_context, value[1]['recordset_id']) + elevated_context, record['recordset_id']) if recordset['ttl'] is not None: fip_ptr['ttl'] = recordset['ttl'] else: zone = self.get_domain( - elevated_context, value[1]['domain_id']) + elevated_context, record['domain_id']) fip_ptr['ttl'] = zone['ttl'] - fip_ptr['ptrdname'] = value[1]['data'] + fip_ptr['ptrdname'] = record['data'] else: LOG.debug("No record information found for %s" % value[0]['id']) diff --git a/designate/objects/adapters/api_v2/floating_ip.py b/designate/objects/adapters/api_v2/floating_ip.py index d565b3ec5..f8f38d07d 100644 --- a/designate/objects/adapters/api_v2/floating_ip.py +++ b/designate/objects/adapters/api_v2/floating_ip.py @@ -37,6 +37,12 @@ class FloatingIPAPIv2Adapter(base.APIv2Adapter): "ttl": { 'read_only': False }, + "action": { + "read_only": True, + }, + "status": { + "read_only": True + } }, 'options': { 'links': True, diff --git a/designate/objects/floating_ip.py b/designate/objects/floating_ip.py index 3699e2404..d9c7c1e52 100644 --- a/designate/objects/floating_ip.py +++ b/designate/objects/floating_ip.py @@ -54,7 +54,20 @@ class FloatingIP(base.DictObjectMixin, base.PersistentObjectMixin, 'schema': { 'type': ['string', 'null'], } + }, + "action": { + 'schema': { + 'type': 'string', + 'enum': ['CREATE', 'DELETE', 'UPDATE', 'NONE'], + } + }, + "status": { + 'schema': { + 'type': 'string', + 'enum': ['ACTIVE', 'PENDING', 'ERROR'], + } } + } @property diff --git a/designate/resources/schemas/v2/floatingip.json b/designate/resources/schemas/v2/floatingip.json index be63a02f7..92978d5c7 100644 --- a/designate/resources/schemas/v2/floatingip.json +++ b/designate/resources/schemas/v2/floatingip.json @@ -37,7 +37,19 @@ "minimum": 0, "maximum": 2147483647 }, - "links": { + "status": { + "type": ["null", "string"], + "description": "Floating IP PTR Status", + "enum": ["ACTIVE", "PENDING", "ERROR"], + "readOnly": true + }, + "action": { + "type": ["null", "string"], + "description": "Floating IP PTR Action", + "enum": ["CREATE", "DELETE", "UPDATE", "NONE"], + "readOnly": true + }, + "links": { "type": "object", "additionalProperties": false, diff --git a/designate/tests/test_api/test_v2/test_floatingips.py b/designate/tests/test_api/test_v2/test_floatingips.py index b26233c7b..e52f8be62 100644 --- a/designate/tests/test_api/test_v2/test_floatingips.py +++ b/designate/tests/test_api/test_v2/test_floatingips.py @@ -42,6 +42,8 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase): self.assertEqual(fip['address'], fip_record['address']) self.assertEqual(None, fip_record['description']) self.assertEqual(None, fip_record['ptrdname']) + self.assertEqual(None, fip_record['action']) + self.assertEqual('ACTIVE', fip_record['status']) def test_get_floatingip_with_record(self): fixture = self.get_ptr_fixture() @@ -69,6 +71,8 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase): self.assertEqual(fip['address'], fip_record['address']) self.assertEqual(None, fip_record['description']) self.assertEqual(fixture['ptrdname'], fip_record['ptrdname']) + self.assertEqual('CREATE', fip_record['action']) + self.assertEqual('PENDING', fip_record['status']) def test_get_floatingip_not_allocated(self): url = '/reverse/floatingips/foo:04580c52-b253-4eb7-8791-fbb9de9f856f' @@ -106,6 +110,8 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase): fip_record['id']) self.assertEqual(fip['address'], fip_record['address']) self.assertEqual(None, fip_record['description']) + self.assertEqual(None, fip_record['action']) + self.assertEqual('ACTIVE', fip_record['status']) def test_list_floatingip_with_record(self): fixture = self.get_ptr_fixture() @@ -132,6 +138,8 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase): self.assertEqual(fip['address'], fip_record['address']) self.assertEqual(None, fip_record['description']) self.assertEqual(fixture['ptrdname'], fip_record['ptrdname']) + self.assertEqual('CREATE', fip_record['action']) + self.assertEqual('PENDING', fip_record['status']) def test_set_floatingip(self): fixture = self.get_ptr_fixture() @@ -143,7 +151,7 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase): {"floatingip": fixture.to_dict()}, headers={'X-Test-Tenant-Id': 'tenant'}) - self.assertEqual(200, response.status_int) + self.assertEqual(202, response.status_int) self.assertEqual('application/json', response.content_type) self.assertIn('floatingip', response.json) @@ -153,6 +161,8 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase): self.assertEqual(fip['address'], fip_record['address']) self.assertEqual(None, fip_record['description']) self.assertEqual(fixture['ptrdname'], fip_record['ptrdname']) + self.assertEqual('CREATE', fip_record['action']) + self.assertEqual('PENDING', fip_record['status']) def test_set_floatingip_not_allocated(self): fixture = self.get_ptr_fixture() @@ -209,7 +219,7 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase): {'floatingip': {'ptrdname': None}}, headers={'X-Test-Tenant-Id': context.tenant}) self.assertEqual(None, response.json) - self.assertEqual(200, response.status_int) + self.assertEqual(202, response.status_int) # Simulate the unset on the backend domain_serial = self.central_service.get_domain(