Merge lp:~bcwaldon/nova/lp713144 into lp:~hudson-openstack/nova/trunk

Proposed by Dan Prince
Status: Merged
Approved by: Matt Dietz
Approved revision: 659
Merged at revision: 692
Proposed branch: lp:~bcwaldon/nova/lp713144
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 136 lines (+80/-3)
3 files modified
Authors (+1/-0)
nova/api/openstack/servers.py (+16/-0)
nova/tests/api/openstack/test_servers.py (+63/-3)
To merge this branch: bzr merge lp:~bcwaldon/nova/lp713144
Reviewer Review Type Date Requested Status
Matt Dietz (community) Approve
Devin Carlen (community) Approve
Review via email: mp+49135@code.launchpad.net

Description of the change

Update the Openstack API so that it returns 'addresses'.

This branch should resolve nova bug #713144 (https://bugs.launchpad.net/nova/+bug/713144).

To post a comment you must log in.
Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve
lp:~bcwaldon/nova/lp713144 updated
657. By Brian Waldon

adding myself to Authors file

658. By Brian Waldon

merging trunk back in; updating Authors conflict

Revision history for this message
Matt Dietz (cerberus) wrote :

Hi Brian!

The passes on lines 28 and 36 seem superfluous.

The list comprehension on 32-33 is pretty odd and a bit unreadable IMO. Perhaps even ruby-ish ;-) Additionally, you're effectively building a list of stuff that you're immediately throwing away, in addition to the list you're actually appending to. I'd like to see this refactored to something a bit cleaner.

Also datetime should be alphabetically listed before json in test_servers.py

review: Needs Fixing
lp:~bcwaldon/nova/lp713144 updated
659. By Brian Waldon

removing superfluous pass statements; replacing list comprehension with for loop; alphabetizing imports

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

Thanks for the feedback. Here's what I did:

1) I removed the pass statements. I guess I had them there before I added the log lines, and didn't think about it when I committed. Does it make sense to log on KeyError in the private ip section of my code? I know an instance won't have a private ip immediately when the api returns successfully, and I'm just not sure what the state of that dict will be coming up from the db api code.

2) The list comprehension has been replaced with a for loop. The code is essentially just reversed, but now it doesn't build an unnecessary list.

3) I reordered the datetime import. I hadn't realized they were supposed to be in alphabetical order.

Brian Waldon

-----Original Message-----
From: "Matthew Dietz" <email address hidden>
Sent: Wednesday, February 16, 2011 3:08pm
To: "Dan Prince" <email address hidden>
Subject: Re: [Merge] lp:~bcwaldon/nova/lp713144 into lp:nova

Review: Needs Fixing
Hi Brian!

The passes on lines 28 and 36 seem superfluous.

The list comprehension on 32-33 is pretty odd and a bit unreadable IMO. Perhaps even ruby-ish ;-) Additionally, you're effectively building a list of stuff that you're immediately throwing away, in addition to the list you're actually appending to. I'd like to see this refactored to something a bit cleaner.

Also datetime should be alphabetically listed before json in test_servers.py

--
https://code.launchpad.net/~bcwaldon/nova/lp713144/+merge/49135
You are the owner of lp:~bcwaldon/nova/lp713144.

Revision history for this message
Matt Dietz (cerberus) wrote :

Thanks for making those changes!

1) If you know it will *never* have an IP it's probably not worth logging. If it might, but not having one breaks something, then we definitely want to log it.

Revision history for this message
Matt Dietz (cerberus) wrote :

^^

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Authors'
2--- Authors 2011-02-16 21:29:52 +0000
3+++ Authors 2011-02-17 14:52:19 +0000
4@@ -3,6 +3,7 @@
5 Anthony Young <sleepsonthefloor@gmail.com>
6 Antony Messerli <ant@openstack.org>
7 Armando Migliaccio <Armando.Migliaccio@eu.citrix.com>
8+Brian Waldon <brian.waldon@rackspace.com>
9 Bilal Akhtar <bilalakhtar@ubuntu.com>
10 Brian Schott <bschott@isi.edu> <bfschott@gmail.com>
11 Chiradeep Vittal <chiradeep@cloud.com>
12
13=== modified file 'nova/api/openstack/servers.py'
14--- nova/api/openstack/servers.py 2011-01-26 16:16:16 +0000
15+++ nova/api/openstack/servers.py 2011-02-17 14:52:19 +0000
16@@ -64,6 +64,22 @@
17
18 inst_dict['status'] = power_mapping[inst_dict['status']]
19 inst_dict['addresses'] = dict(public=[], private=[])
20+
21+ # grab single private fixed ip
22+ try:
23+ private_ip = inst['fixed_ip']['address']
24+ if private_ip:
25+ inst_dict['addresses']['private'].append(private_ip)
26+ except KeyError:
27+ LOG.debug(_("Failed to read private ip"))
28+
29+ # grab all public floating ips
30+ try:
31+ for floating in inst['fixed_ip']['floating_ips']:
32+ inst_dict['addresses']['public'].append(floating['address'])
33+ except KeyError:
34+ LOG.debug(_("Failed to read public ip(s)"))
35+
36 inst_dict['metadata'] = {}
37 inst_dict['hostId'] = ''
38
39
40=== modified file 'nova/tests/api/openstack/test_servers.py'
41--- nova/tests/api/openstack/test_servers.py 2011-01-27 18:48:00 +0000
42+++ nova/tests/api/openstack/test_servers.py 2011-02-17 14:52:19 +0000
43@@ -15,6 +15,7 @@
44 # License for the specific language governing permissions and limitations
45 # under the License.
46
47+import datetime
48 import json
49 import unittest
50
51@@ -39,6 +40,13 @@
52 return stub_instance(id)
53
54
55+def return_server_with_addresses(private, public):
56+ def _return_server(context, id):
57+ return stub_instance(id, private_address=private,
58+ public_addresses=public)
59+ return _return_server
60+
61+
62 def return_servers(context, user_id=1):
63 return [stub_instance(i, user_id) for i in xrange(5)]
64
65@@ -55,9 +63,45 @@
66 return None
67
68
69-def stub_instance(id, user_id=1):
70- return Instance(id=id, state=0, image_id=10, user_id=user_id,
71- display_name='server%s' % id)
72+def stub_instance(id, user_id=1, private_address=None, public_addresses=None):
73+ if public_addresses == None:
74+ public_addresses = list()
75+
76+ instance = {
77+ "id": id,
78+ "admin_pass": "",
79+ "user_id": user_id,
80+ "project_id": "",
81+ "image_id": 10,
82+ "kernel_id": "",
83+ "ramdisk_id": "",
84+ "launch_index": 0,
85+ "key_name": "",
86+ "key_data": "",
87+ "state": 0,
88+ "state_description": "",
89+ "memory_mb": 0,
90+ "vcpus": 0,
91+ "local_gb": 0,
92+ "hostname": "",
93+ "host": "",
94+ "instance_type": "",
95+ "user_data": "",
96+ "reservation_id": "",
97+ "mac_address": "",
98+ "scheduled_at": datetime.datetime.now(),
99+ "launched_at": datetime.datetime.now(),
100+ "terminated_at": datetime.datetime.now(),
101+ "availability_zone": "",
102+ "display_name": "server%s" % id,
103+ "display_description": "",
104+ "locked": False}
105+
106+ instance["fixed_ip"] = {
107+ "address": private_address,
108+ "floating_ips": [{"address":ip} for ip in public_addresses]}
109+
110+ return instance
111
112
113 def fake_compute_api(cls, req, id):
114@@ -105,6 +149,22 @@
115 self.assertEqual(res_dict['server']['id'], '1')
116 self.assertEqual(res_dict['server']['name'], 'server1')
117
118+ def test_get_server_by_id_with_addresses(self):
119+ private = "192.168.0.3"
120+ public = ["1.2.3.4"]
121+ new_return_server = return_server_with_addresses(private, public)
122+ self.stubs.Set(nova.db.api, 'instance_get', new_return_server)
123+ req = webob.Request.blank('/v1.0/servers/1')
124+ res = req.get_response(fakes.wsgi_app())
125+ res_dict = json.loads(res.body)
126+ self.assertEqual(res_dict['server']['id'], '1')
127+ self.assertEqual(res_dict['server']['name'], 'server1')
128+ addresses = res_dict['server']['addresses']
129+ self.assertEqual(len(addresses["public"]), len(public))
130+ self.assertEqual(addresses["public"][0], public[0])
131+ self.assertEqual(len(addresses["private"]), 1)
132+ self.assertEqual(addresses["private"][0], private)
133+
134 def test_get_server_list(self):
135 req = webob.Request.blank('/v1.0/servers')
136 res = req.get_response(fakes.wsgi_app())