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
This commit is contained in:
Endre Karlson 2015-03-27 15:07:30 +01:00
parent 19c574989b
commit 8f06223e71
6 changed files with 65 additions and 13 deletions

View File

@ -60,6 +60,8 @@ class FloatingIPController(rest.RestController):
Set or unset a PTR Set or unset a PTR
""" """
request = pecan.request request = pecan.request
response = pecan.response
context = request.environ['context'] context = request.environ['context']
body = request.body_dict body = request.body_dict
@ -74,6 +76,8 @@ class FloatingIPController(rest.RestController):
id_, id_,
objects.FloatingIP().from_dict(body['floatingip'])) objects.FloatingIP().from_dict(body['floatingip']))
response.status_int = 202
if fip: if fip:
return self._view.show(context, request, fip) return self._view.show(context, request, fip)

View File

@ -1688,34 +1688,41 @@ class Service(service.RPCService, service.Service):
fips = objects.FloatingIPList() fips = objects.FloatingIPList()
for key, value in data.items(): for key, value in data.items():
fip, record = value
fip_ptr = objects.FloatingIP().from_dict({ fip_ptr = objects.FloatingIP().from_dict({
'address': value[0]['address'], 'address': fip['address'],
'id': value[0]['id'], 'id': fip['id'],
'region': value[0]['region'], 'region': fip['region'],
'ptrdname': None, 'ptrdname': None,
'ttl': None, 'ttl': None,
'description': None 'description': None,
'action': None,
'status': 'ACTIVE'
}) })
# TTL population requires a present record in order to find the # TTL population requires a present record in order to find the
# RS or Zone # 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 # We can have a recordset dict passed in
if (recordsets is not None and if (recordsets is not None and
value[1]['recordset_id'] in recordsets): record['recordset_id'] in recordsets):
recordset = recordsets[value[1]['recordset_id']] recordset = recordsets[record['recordset_id']]
else: else:
recordset = self.storage.get_recordset( recordset = self.storage.get_recordset(
elevated_context, value[1]['recordset_id']) elevated_context, record['recordset_id'])
if recordset['ttl'] is not None: if recordset['ttl'] is not None:
fip_ptr['ttl'] = recordset['ttl'] fip_ptr['ttl'] = recordset['ttl']
else: else:
zone = self.get_domain( zone = self.get_domain(
elevated_context, value[1]['domain_id']) elevated_context, record['domain_id'])
fip_ptr['ttl'] = zone['ttl'] fip_ptr['ttl'] = zone['ttl']
fip_ptr['ptrdname'] = value[1]['data'] fip_ptr['ptrdname'] = record['data']
else: else:
LOG.debug("No record information found for %s" % LOG.debug("No record information found for %s" %
value[0]['id']) value[0]['id'])

View File

@ -37,6 +37,12 @@ class FloatingIPAPIv2Adapter(base.APIv2Adapter):
"ttl": { "ttl": {
'read_only': False 'read_only': False
}, },
"action": {
"read_only": True,
},
"status": {
"read_only": True
}
}, },
'options': { 'options': {
'links': True, 'links': True,

View File

@ -54,7 +54,20 @@ class FloatingIP(base.DictObjectMixin, base.PersistentObjectMixin,
'schema': { 'schema': {
'type': ['string', 'null'], 'type': ['string', 'null'],
} }
},
"action": {
'schema': {
'type': 'string',
'enum': ['CREATE', 'DELETE', 'UPDATE', 'NONE'],
}
},
"status": {
'schema': {
'type': 'string',
'enum': ['ACTIVE', 'PENDING', 'ERROR'],
}
} }
} }
@property @property

View File

@ -37,7 +37,19 @@
"minimum": 0, "minimum": 0,
"maximum": 2147483647 "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", "type": "object",
"additionalProperties": false, "additionalProperties": false,

View File

@ -42,6 +42,8 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase):
self.assertEqual(fip['address'], fip_record['address']) self.assertEqual(fip['address'], fip_record['address'])
self.assertEqual(None, fip_record['description']) self.assertEqual(None, fip_record['description'])
self.assertEqual(None, fip_record['ptrdname']) 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): def test_get_floatingip_with_record(self):
fixture = self.get_ptr_fixture() fixture = self.get_ptr_fixture()
@ -69,6 +71,8 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase):
self.assertEqual(fip['address'], fip_record['address']) self.assertEqual(fip['address'], fip_record['address'])
self.assertEqual(None, fip_record['description']) self.assertEqual(None, fip_record['description'])
self.assertEqual(fixture['ptrdname'], fip_record['ptrdname']) 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): def test_get_floatingip_not_allocated(self):
url = '/reverse/floatingips/foo:04580c52-b253-4eb7-8791-fbb9de9f856f' url = '/reverse/floatingips/foo:04580c52-b253-4eb7-8791-fbb9de9f856f'
@ -106,6 +110,8 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase):
fip_record['id']) fip_record['id'])
self.assertEqual(fip['address'], fip_record['address']) self.assertEqual(fip['address'], fip_record['address'])
self.assertEqual(None, fip_record['description']) 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): def test_list_floatingip_with_record(self):
fixture = self.get_ptr_fixture() fixture = self.get_ptr_fixture()
@ -132,6 +138,8 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase):
self.assertEqual(fip['address'], fip_record['address']) self.assertEqual(fip['address'], fip_record['address'])
self.assertEqual(None, fip_record['description']) self.assertEqual(None, fip_record['description'])
self.assertEqual(fixture['ptrdname'], fip_record['ptrdname']) self.assertEqual(fixture['ptrdname'], fip_record['ptrdname'])
self.assertEqual('CREATE', fip_record['action'])
self.assertEqual('PENDING', fip_record['status'])
def test_set_floatingip(self): def test_set_floatingip(self):
fixture = self.get_ptr_fixture() fixture = self.get_ptr_fixture()
@ -143,7 +151,7 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase):
{"floatingip": fixture.to_dict()}, {"floatingip": fixture.to_dict()},
headers={'X-Test-Tenant-Id': 'tenant'}) 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.assertEqual('application/json', response.content_type)
self.assertIn('floatingip', response.json) self.assertIn('floatingip', response.json)
@ -153,6 +161,8 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase):
self.assertEqual(fip['address'], fip_record['address']) self.assertEqual(fip['address'], fip_record['address'])
self.assertEqual(None, fip_record['description']) self.assertEqual(None, fip_record['description'])
self.assertEqual(fixture['ptrdname'], fip_record['ptrdname']) 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): def test_set_floatingip_not_allocated(self):
fixture = self.get_ptr_fixture() fixture = self.get_ptr_fixture()
@ -209,7 +219,7 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase):
{'floatingip': {'ptrdname': None}}, {'floatingip': {'ptrdname': None}},
headers={'X-Test-Tenant-Id': context.tenant}) headers={'X-Test-Tenant-Id': context.tenant})
self.assertEqual(None, response.json) self.assertEqual(None, response.json)
self.assertEqual(200, response.status_int) self.assertEqual(202, response.status_int)
# Simulate the unset on the backend # Simulate the unset on the backend
domain_serial = self.central_service.get_domain( domain_serial = self.central_service.get_domain(