Merge lp:~bcwaldon/nova/osapi-flavors-1_1 into lp:~hudson-openstack/nova/trunk

Proposed by Brian Waldon
Status: Merged
Merged at revision: 839
Proposed branch: lp:~bcwaldon/nova/osapi-flavors-1_1
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 145 lines (+78/-9)
2 files modified
nova/api/openstack/flavors.py (+10/-5)
nova/tests/api/openstack/test_flavors.py (+68/-4)
To merge this branch: bzr merge lp:~bcwaldon/nova/osapi-flavors-1_1
Reviewer Review Type Date Requested Status
Paul Voccio (community) Approve
Rick Harris Pending
Dan Prince Pending
Review via email: mp+54248@code.launchpad.net

This proposal supersedes a proposal from 2011-03-16.

Description of the change

Openstack api 1.0 flavors resource now implemented to match the spec. This also addresses the instance_type.id != flavor_id issue in bug #736343.

Resubmitting w/ prereq removed

To post a comment you must log in.
Revision history for this message
Paul Voccio (pvo) wrote : Posted in a previous version of this proposal

lgtm

review: Approve
Revision history for this message
Rick Harris (rconradharris) wrote : Posted in a previous version of this proposal

Really nice job, Brian.

> 142 + "ram": "256",
> 143 + "disk": "10",

Looking at the CS API spec, it looks like JSON format uses ints for `ram` and `disk`. Is this correct?

Strangely, the XML format uses strings for all the attrs with no type qualifier.

review: Needs Information
Revision history for this message
Brian Waldon (bcwaldon) wrote : Posted in a previous version of this proposal

> Really nice job, Brian.
>
> > 142 + "ram": "256",
> > 143 + "disk": "10",
>
> Looking at the CS API spec, it looks like JSON format uses ints for `ram` and
> `disk`. Is this correct?
>
> Strangely, the XML format uses strings for all the attrs with no type
> qualifier.

So I have noticed this across the project; integer values are represented as strings in xml and ints in json. I decided to make everything a string for now until we have some actual xml schemas just for consistency across the formats. The other option would be to accept the misrepresentation in xml and use ints in json. Thoughts?

Revision history for this message
Rick Harris (rconradharris) wrote : Posted in a previous version of this proposal

> I have noticed this across the project

Gotcha, if it's that widespread, I like your go-for-consistency approach. If this turns out to be a legit problem, we can get clarification, make a bug, and fix it all at once.

Might be a good idea to add a TODO or a Wishlist-bug to investigate this down the road.

review: Approve
Revision history for this message
justinsb (justin-fathomdb) wrote : Posted in a previous version of this proposal

>
> > I have noticed this across the project
>
> Gotcha, if it's that widespread, I like your go-for-consistency approach.
> If this turns out to be a legit problem, we can get clarification, make a
> bug, and fix it all at once.
>
> Might be a good idea to add a TODO or a Wishlist-bug to investigate this
> down the road.

Ick... can I clarify which schema we're looking at? I'm looking at this
one:
http://docs.rackspacecloud.com/servers/api/v1.0/xsd/flavor.xsd

<http://docs.rackspacecloud.com/servers/api/v1.0/xsd/flavor.xsd>Where it
looks like ram is an xsd:int ?

Totally agree this is probably not best fixed in this particular patch given
it's cross-cutting. Am I looking at the right schema though? Do we have a
bug / blueprint?

Revision history for this message
Rick Harris (rconradharris) wrote : Posted in a previous version of this proposal

> Ick... can I clarify which schema we're looking at? I'm looking at this
one:

I wasn't looking at a particular schema, I was just looking in the `Flavors` section of

http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf

I noticed that the JSON version didn't quote the ram/disk whereas this patch does.

Revision history for this message
Brian Waldon (bcwaldon) wrote : Posted in a previous version of this proposal

> >
> > > I have noticed this across the project
> >
> > Gotcha, if it's that widespread, I like your go-for-consistency approach.
> > If this turns out to be a legit problem, we can get clarification, make a
> > bug, and fix it all at once.
> >
> > Might be a good idea to add a TODO or a Wishlist-bug to investigate this
> > down the road.
>
>
> Ick... can I clarify which schema we're looking at? I'm looking at this
> one:
> http://docs.rackspacecloud.com/servers/api/v1.0/xsd/flavor.xsd
>
> <http://docs.rackspacecloud.com/servers/api/v1.0/xsd/flavor.xsd>Where it
> looks like ram is an xsd:int ?

I hadn't even looked at that schema. You're definitely right. Is there a v1.1 schema somewhere?

>
> Totally agree this is probably not best fixed in this particular patch given
> it's cross-cutting. Am I looking at the right schema though? Do we have a
> bug / blueprint?

Like I said earlier, I think there is some inconsistency across the project as a whole between xml/json integers. I do hate feeling like I am contributing to the problem. Would you like me to file a bug and address this very soon?

Revision history for this message
justinsb (justin-fathomdb) wrote : Posted in a previous version of this proposal

>
> Like I said earlier, I think there is some inconsistency across the project
> as a whole between xml/json integers. I do hate feeling like I am
> contributing to the problem. Would you like me to file a bug and address
> this very soon?
>

I don't know if there's a 1.1 schema yet. I think filing the bug is
definitely the right place to start, probably also the ML - I'm guessing
there will need to be some discussion around the possible approaches.

I wouldn't worry about contributing to the problem - I think you've brought
it to our collective attention. I'm thinking the right way to solve this
will be with a dedicated cleanup patch / patch series, rather than a
patch-by-patch, call-by-call approach. It might even be best to do this
once all the Cactus feature branches have been merged. I don't want XML to
block this or other important patches from merging.

Revision history for this message
Brian Waldon (bcwaldon) wrote : Posted in a previous version of this proposal

> It might even be best to do this
> once all the Cactus feature branches have been merged. I don't want XML to
> block this or other important patches from merging.

Definitely. I'll be sure to keep this in mind next week.

Revision history for this message
Rick Harris (rconradharris) wrote : Posted in a previous version of this proposal

> I don't want XML to block this or other important patches from merging.

+1

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Posted in a previous version of this proposal
Revision history for this message
Rick Harris (rconradharris) wrote : Posted in a previous version of this proposal

> No proposals found for merge of lp:~rackspace-titan/nova/openstack-api-version-split into lp:nova.

Uh, the pre-req was merged in at rev821.

Revision history for this message
Brian Waldon (bcwaldon) wrote : Posted in a previous version of this proposal

> > No proposals found for merge of lp:~rackspace-titan/nova/openstack-api-
> version-split into lp:nova.
>
> Uh, the pre-req was merged in at rev821.

That prereq was valid when I filed this merge prop. Do I need to manually remove it now that it has been resolved?

Revision history for this message
Paul Voccio (pvo) wrote :

lgtm. Was previously approved as well.

review: Approve
Revision history for this message
Rick Harris (rconradharris) wrote : Posted in a previous version of this proposal

>That prereq was valid when I filed this merge prop. Do I need to manually remove it now that it has been resolved?

Hmm I would have thought LP was smart enough to handle that. But, just in case, guess we could remove the pre-req.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/api/openstack/flavors.py'
2--- nova/api/openstack/flavors.py 2011-03-16 19:43:57 +0000
3+++ nova/api/openstack/flavors.py 2011-03-21 18:06:07 +0000
4@@ -22,6 +22,7 @@
5 from nova.api.openstack import faults
6 from nova.api.openstack import common
7 from nova.compute import instance_types
8+from nova.api.openstack.views import flavors as flavors_views
9 from nova import wsgi
10 import nova.api.openstack
11
12@@ -36,7 +37,7 @@
13
14 def index(self, req):
15 """Return all flavors in brief."""
16- return dict(flavors=[dict(id=flavor['flavorid'], name=flavor['name'])
17+ return dict(flavors=[dict(id=flavor['id'], name=flavor['name'])
18 for flavor in self.detail(req)['flavors']])
19
20 def detail(self, req):
21@@ -47,14 +48,18 @@
22 def show(self, req, id):
23 """Return data about the given flavor id."""
24 ctxt = req.environ['nova.context']
25- values = db.instance_type_get_by_flavor_id(ctxt, id)
26- values['id'] = values['flavorid']
27+ flavor = db.api.instance_type_get_by_flavor_id(ctxt, id)
28+ values = {
29+ "id": flavor["flavorid"],
30+ "name": flavor["name"],
31+ "ram": flavor["memory_mb"],
32+ "disk": flavor["local_gb"],
33+ }
34 return dict(flavor=values)
35- raise faults.Fault(exc.HTTPNotFound())
36
37 def _all_ids(self, req):
38 """Return the list of all flavorids."""
39 ctxt = req.environ['nova.context']
40- inst_types = db.instance_type_get_all(ctxt)
41+ inst_types = db.api.instance_type_get_all(ctxt)
42 flavor_ids = [inst_types[i]['flavorid'] for i in inst_types.keys()]
43 return sorted(flavor_ids)
44
45=== modified file 'nova/tests/api/openstack/test_flavors.py'
46--- nova/tests/api/openstack/test_flavors.py 2011-03-16 19:40:16 +0000
47+++ nova/tests/api/openstack/test_flavors.py 2011-03-21 18:06:07 +0000
48@@ -22,11 +22,32 @@
49 from nova import test
50 import nova.api
51 from nova import context
52+from nova.api.openstack import flavors
53 from nova import db
54-from nova.api.openstack import flavors
55 from nova.tests.api.openstack import fakes
56
57
58+def stub_flavor(flavorid, name, memory_mb="256", local_gb="10"):
59+ return {
60+ "flavorid": str(flavorid),
61+ "name": name,
62+ "memory_mb": memory_mb,
63+ "local_gb": local_gb,
64+ }
65+
66+
67+def return_instance_type_by_flavor_id(context, flavorid):
68+ return stub_flavor(flavorid, "flavor %s" % (flavorid,))
69+
70+
71+def return_instance_types(context, num=2):
72+ instance_types = {}
73+ for i in xrange(1, num + 1):
74+ name = "flavor %s" % (i,)
75+ instance_types[name] = stub_flavor(i, name)
76+ return instance_types
77+
78+
79 class FlavorsTest(test.TestCase):
80 def setUp(self):
81 super(FlavorsTest, self).setUp()
82@@ -36,6 +57,10 @@
83 fakes.stub_out_networking(self.stubs)
84 fakes.stub_out_rate_limiting(self.stubs)
85 fakes.stub_out_auth(self.stubs)
86+ self.stubs.Set(nova.db.api, "instance_type_get_all",
87+ return_instance_types)
88+ self.stubs.Set(nova.db.api, "instance_type_get_by_flavor_id",
89+ return_instance_type_by_flavor_id)
90 self.context = context.get_admin_context()
91
92 def tearDown(self):
93@@ -46,10 +71,49 @@
94 req = webob.Request.blank('/v1.0/flavors')
95 res = req.get_response(fakes.wsgi_app())
96 self.assertEqual(res.status_int, 200)
97+ flavors = json.loads(res.body)["flavors"]
98+ expected = [
99+ {
100+ "id": "1",
101+ "name": "flavor 1",
102+ },
103+ {
104+ "id": "2",
105+ "name": "flavor 2",
106+ },
107+ ]
108+ self.assertEqual(flavors, expected)
109+
110+ def test_get_flavor_list_detail(self):
111+ req = webob.Request.blank('/v1.0/flavors/detail')
112+ res = req.get_response(fakes.wsgi_app())
113+ self.assertEqual(res.status_int, 200)
114+ flavors = json.loads(res.body)["flavors"]
115+ expected = [
116+ {
117+ "id": "1",
118+ "name": "flavor 1",
119+ "ram": "256",
120+ "disk": "10",
121+ },
122+ {
123+ "id": "2",
124+ "name": "flavor 2",
125+ "ram": "256",
126+ "disk": "10",
127+ },
128+ ]
129+ self.assertEqual(flavors, expected)
130
131 def test_get_flavor_by_id(self):
132- req = webob.Request.blank('/v1.0/flavors/1')
133+ req = webob.Request.blank('/v1.0/flavors/12')
134 res = req.get_response(fakes.wsgi_app())
135 self.assertEqual(res.status_int, 200)
136- body = json.loads(res.body)
137- self.assertEqual(body['flavor']['id'], 1)
138+ flavor = json.loads(res.body)["flavor"]
139+ expected = {
140+ "id": "12",
141+ "name": "flavor 12",
142+ "ram": "256",
143+ "disk": "10",
144+ }
145+ self.assertEqual(flavor, expected)