Skip to content

Commit

Permalink
Fix marker behavior for flavors
Browse files Browse the repository at this point in the history
Fixes Bug #956096

Change-Id: Ifa94a70f2aec3b9527c291e27d4710336a1d1834
  • Loading branch information
Phlip Knouff committed Mar 28, 2012
1 parent 930be36 commit 497502c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
6 changes: 5 additions & 1 deletion nova/api/openstack/common.py
Expand Up @@ -192,7 +192,11 @@ def limited_by_marker(items, request, max_limit=FLAGS.osapi_max_limit):
if marker:
start_index = -1
for i, item in enumerate(items):
if item['id'] == marker or item.get('uuid') == marker:
if 'flavorid' in item:
if item['flavorid'] == marker:
start_index = i + 1
break
elif item['id'] == marker or item.get('uuid') == marker:
start_index = i + 1
break
if start_index < 0:
Expand Down
13 changes: 8 additions & 5 deletions nova/api/openstack/compute/flavors.py
Expand Up @@ -73,15 +73,13 @@ class Controller(wsgi.Controller):
def index(self, req):
"""Return all flavors in brief."""
flavors = self._get_flavors(req)
limited_flavors = common.limited_by_marker(flavors.values(), req)
return self._view_builder.index(req, limited_flavors)
return self._view_builder.index(req, flavors)

@wsgi.serializers(xml=FlavorsTemplate)
def detail(self, req):
"""Return all flavors in detail."""
flavors = self._get_flavors(req)
limited_flavors = common.limited_by_marker(flavors.values(), req)
return self._view_builder.detail(req, limited_flavors)
return self._view_builder.detail(req, flavors)

@wsgi.serializers(xml=FlavorTemplate)
def show(self, req, id):
Expand All @@ -108,7 +106,12 @@ def _get_flavors(self, req):
except ValueError:
pass # ignore bogus values per spec

return instance_types.get_all_types(filters=filters)
flavors = instance_types.get_all_types(filters=filters)
flavors_list = flavors.values()
sorted_flavors = sorted(flavors_list,
key=lambda item: item['flavorid'])
limited_flavors = common.limited_by_marker(sorted_flavors, req)
return limited_flavors


def create_resource():
Expand Down
28 changes: 28 additions & 0 deletions nova/tests/api/openstack/compute/test_flavors.py
Expand Up @@ -195,6 +195,34 @@ def test_get_flavor_list(self):
}
self.assertEqual(flavor, expected)

def test_get_flavor_list_with_marker(self):
self.maxDiff = None
req = fakes.HTTPRequest.blank('/v2/fake/flavors?limit=1&marker=1')
flavor = self.controller.index(req)
expected = {
"flavors": [
{
"id": "2",
"name": "flavor 2",
"links": [
{
"rel": "self",
"href": "http://localhost/v2/fake/flavors/2",
},
{
"rel": "bookmark",
"href": "http://localhost/fake/flavors/2",
},
],
},
],
'flavors_links': [
{'href': 'http://localhost/v2/fake/flavors?limit=1&marker=2',
'rel': 'next'}
]
}
self.assertDictMatch(flavor, expected)

def test_get_flavor_detail_with_limit(self):
req = fakes.HTTPRequest.blank('/v2/fake/flavors/detail?limit=1')
response = self.controller.index(req)
Expand Down

0 comments on commit 497502c

Please sign in to comment.