summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Young <sleepsonthefloor@gmail.com>2011-09-01 05:37:27 +0000
committerTarmac <>2011-09-01 05:37:27 +0000
commit17de95f0c2b6431a4ae5bf39beb4d3cee2f843b2 (patch)
tree71c189eb64e48d445e7f546ae8d4ade6d7082401
parentab00393da6ab61db1952b6826ea806b66ca6cc29 (diff)
parentfdf076a04e001b897d01b2a8c4a9e3c980ea8f94 (diff)
downloadnova-17de95f0c2b6431a4ae5bf39beb4d3cee2f843b2.tar.gz
nova-17de95f0c2b6431a4ae5bf39beb4d3cee2f843b2.tar.xz
nova-17de95f0c2b6431a4ae5bf39beb4d3cee2f843b2.zip
fix for lp838583 - fixes bug in os-floating-ips view code that prevents instance_id from being returned for associated addresses.
-rw-r--r--nova/api/openstack/contrib/floating_ips.py6
-rw-r--r--nova/tests/api/openstack/contrib/test_floating_ips.py21
2 files changed, 20 insertions, 7 deletions
diff --git a/nova/api/openstack/contrib/floating_ips.py b/nova/api/openstack/contrib/floating_ips.py
index 6ce531c8f..d1add8f83 100644
--- a/nova/api/openstack/contrib/floating_ips.py
+++ b/nova/api/openstack/contrib/floating_ips.py
@@ -36,9 +36,9 @@ def _translate_floating_ip_view(floating_ip):
result['fixed_ip'] = floating_ip['fixed_ip']['address']
except (TypeError, KeyError):
result['fixed_ip'] = None
- if 'instance' in floating_ip:
- result['instance_id'] = floating_ip['instance']['id']
- else:
+ try:
+ result['instance_id'] = floating_ip['fixed_ip']['instance_id']
+ except (TypeError, KeyError):
result['instance_id'] = None
return {'floating_ip': result}
diff --git a/nova/tests/api/openstack/contrib/test_floating_ips.py b/nova/tests/api/openstack/contrib/test_floating_ips.py
index fc10f2f6c..642f2b841 100644
--- a/nova/tests/api/openstack/contrib/test_floating_ips.py
+++ b/nova/tests/api/openstack/contrib/test_floating_ips.py
@@ -38,14 +38,13 @@ def network_api_get_floating_ip(self, context, id):
def network_api_get_floating_ip_by_ip(self, context, address):
return {'id': 1, 'address': '10.10.10.10',
- 'fixed_ip': {'address': '11.0.0.1'}}
+ 'fixed_ip': {'address': '10.0.0.1', 'instance_id': 1}},
def network_api_list_floating_ips(self, context):
return [{'id': 1,
'address': '10.10.10.10',
- 'instance': {'id': 11},
- 'fixed_ip': {'address': '10.0.0.1'}},
+ 'fixed_ip': {'address': '10.0.0.1', 'instance_id': 1}},
{'id': 2,
'address': '10.10.10.11'}]
@@ -152,7 +151,7 @@ class FloatingIpTest(test.TestCase):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
res_dict = json.loads(res.body)
- response = {'floating_ips': [{'instance_id': 11,
+ response = {'floating_ips': [{'instance_id': 1,
'ip': '10.10.10.10',
'fixed_ip': '10.0.0.1',
'id': 1},
@@ -171,6 +170,20 @@ class FloatingIpTest(test.TestCase):
self.assertEqual(res_dict['floating_ip']['ip'], '10.10.10.10')
self.assertEqual(res_dict['floating_ip']['instance_id'], None)
+ def test_show_associated_floating_ip(self):
+ def get_floating_ip(self, context, id):
+ return {'id': 1, 'address': '10.10.10.10',
+ 'fixed_ip': {'address': '10.0.0.1', 'instance_id': 1}}
+ self.stubs.Set(network.api.API, "get_floating_ip", get_floating_ip)
+
+ req = webob.Request.blank('/v1.1/123/os-floating-ips/1')
+ res = req.get_response(fakes.wsgi_app())
+ self.assertEqual(res.status_int, 200)
+ res_dict = json.loads(res.body)
+ self.assertEqual(res_dict['floating_ip']['id'], 1)
+ self.assertEqual(res_dict['floating_ip']['ip'], '10.10.10.10')
+ self.assertEqual(res_dict['floating_ip']['instance_id'], 1)
+
def test_floating_ip_allocate_no_free_ips(self):
def fake_call(*args, **kwargs):
raise(rpc.RemoteError('NoMoreFloatingIps', '', ''))