Merge lp:~jtran/nova/lp810364 into lp:~hudson-openstack/nova/trunk

Proposed by John Tran
Status: Merged
Approved by: Rick Harris
Approved revision: 1329
Merged at revision: 1352
Proposed branch: lp:~jtran/nova/lp810364
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 31 lines (+7/-2)
2 files modified
nova/api/openstack/contrib/floating_ips.py (+2/-2)
nova/tests/api/openstack/contrib/test_floating_ips.py (+5/-0)
To merge this branch: bzr merge lp:~jtran/nova/lp810364
Reviewer Review Type Date Requested Status
Rick Harris (community) Approve
Jason Kölker (community) Approve
Brian Waldon (community) Approve
Review via email: mp+69396@code.launchpad.net

Commit message

code was checking for key in sqlalchemy instance and will ignore if value is None, but wasn't working if floating_ip was a non-sqlalchemy dict obj. Therefore, updated the error checking to work in both caes.

Description of the change

code was checking for key in sqlalchemy instance and will ignore if value is None, but wasn't working if floating_ip was a non-sqlalchemy dict obj. Therefore, updated the error checking to work in both caes.

To post a comment you must log in.
Revision history for this message
Brian Waldon (bcwaldon) wrote :

What do you think about this code, instead? It will handle floating_ip not being a dictionary and the 'address' key not existing:

   try:
       result['fixed_ip'] = floating_ip['fixed_ip']['address']
   except (TypeError, KeyError):
       result['fixed_ip'] = None

Revision history for this message
John Tran (jtran) wrote :

I like that much better. I've updated the branch. Thanks, Brian.

lp:~jtran/nova/lp810364 updated
1329. By John Tran

improved the code per peer review

Revision history for this message
Brian Waldon (bcwaldon) wrote :

Awesome.

review: Approve
Revision history for this message
Jason Kölker (jason-koelker) wrote :

Is bueno.

review: Approve
Revision history for this message
Rick Harris (rconradharris) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/api/openstack/contrib/floating_ips.py'
2--- nova/api/openstack/contrib/floating_ips.py 2011-07-06 20:28:10 +0000
3+++ nova/api/openstack/contrib/floating_ips.py 2011-07-27 17:36:42 +0000
4@@ -27,9 +27,9 @@
5 def _translate_floating_ip_view(floating_ip):
6 result = {'id': floating_ip['id'],
7 'ip': floating_ip['address']}
8- if 'fixed_ip' in floating_ip:
9+ try:
10 result['fixed_ip'] = floating_ip['fixed_ip']['address']
11- else:
12+ except (TypeError, KeyError):
13 result['fixed_ip'] = None
14 if 'instance' in floating_ip:
15 result['instance_id'] = floating_ip['instance']['id']
16
17=== modified file 'nova/tests/api/openstack/contrib/test_floating_ips.py'
18--- nova/tests/api/openstack/contrib/test_floating_ips.py 2011-07-06 20:28:10 +0000
19+++ nova/tests/api/openstack/contrib/test_floating_ips.py 2011-07-27 17:36:42 +0000
20@@ -111,6 +111,11 @@
21 self.assertEqual(view['floating_ip']['fixed_ip'], None)
22 self.assertEqual(view['floating_ip']['instance_id'], None)
23
24+ def test_translate_floating_ip_view_dict(self):
25+ floating_ip = {'id': 0, 'address': '10.0.0.10', 'fixed_ip': None}
26+ view = _translate_floating_ip_view(floating_ip)
27+ self.assertTrue('floating_ip' in view)
28+
29 def test_floating_ips_list(self):
30 req = webob.Request.blank('/v1.1/os-floating-ips')
31 res = req.get_response(fakes.wsgi_app())