summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wolf <throughnothing@gmail.com>2011-08-10 01:44:15 -0400
committerWilliam Wolf <throughnothing@gmail.com>2011-08-10 01:44:15 -0400
commite68ace1d6f7cb6db842aae69faa89cb4679016e7 (patch)
tree52bdc0ca92792a722882b3a27180fc54b5eecb41
parentc8a4a55437a332c49c7c1afc52a9c1c8bf93e593 (diff)
downloadnova-e68ace1d6f7cb6db842aae69faa89cb4679016e7.tar.gz
nova-e68ace1d6f7cb6db842aae69faa89cb4679016e7.tar.xz
nova-e68ace1d6f7cb6db842aae69faa89cb4679016e7.zip
added project_id for images requests
-rw-r--r--nova/api/openstack/images.py3
-rw-r--r--nova/tests/api/openstack/test_images.py92
2 files changed, 52 insertions, 43 deletions
diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py
index 0aabb9e56..ea4209e16 100644
--- a/nova/api/openstack/images.py
+++ b/nova/api/openstack/images.py
@@ -169,7 +169,8 @@ class ControllerV11(Controller):
def get_builder(self, request):
"""Property to get the ViewBuilder class we need to use."""
base_url = request.application_url
- return images_view.ViewBuilderV11(base_url)
+ project_id = request.environ['nova.context'].project_id
+ return images_view.ViewBuilderV11(base_url, project_id)
def index(self, req):
"""Return an index listing of images available to the request.
diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py
index 5e979aba4..882b0aafd 100644
--- a/nova/tests/api/openstack/test_images.py
+++ b/nova/tests/api/openstack/test_images.py
@@ -339,6 +339,11 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
self.stubs.UnsetAll()
super(ImageControllerWithGlanceServiceTest, self).tearDown()
+ def _get_fake_context(self):
+ class Context(object):
+ project_id = 'fake'
+ return Context()
+
def _applicable_fixture(self, fixture, user_id):
"""Determine if this fixture is applicable for given user id."""
is_public = fixture["is_public"]
@@ -389,10 +394,12 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
request = webob.Request.blank('/v1.1/123/images/124')
response = request.get_response(fakes.wsgi_app())
+ print response.body
+
actual_image = json.loads(response.body)
- href = "http://localhost/v1.1/images/124"
- bookmark = "http://localhost/images/124"
+ href = "http://localhost/v1.1/fake/images/124"
+ bookmark = "http://localhost/fake/images/124"
server_href = "http://localhost/v1.1/servers/42"
server_bookmark = "http://localhost/servers/42"
@@ -558,8 +565,8 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
fixtures.remove(image)
continue
- href = "http://localhost/v1.1/images/%s" % image["id"]
- bookmark = "http://localhost/images/%s" % image["id"]
+ href = "http://localhost/v1.1/fake/images/%s" % image["id"]
+ bookmark = "http://localhost/fake/images/%s" % image["id"]
test_image = {
"id": image["id"],
"name": image["name"],
@@ -655,11 +662,11 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
'progress': 100,
"links": [{
"rel": "self",
- "href": "http://localhost/v1.1/images/123",
+ "href": "http://localhost/v1.1/fake/images/123",
},
{
"rel": "bookmark",
- "href": "http://localhost/images/123",
+ "href": "http://localhost/fake/images/123",
}],
},
{
@@ -686,11 +693,11 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
},
"links": [{
"rel": "self",
- "href": "http://localhost/v1.1/images/124",
+ "href": "http://localhost/v1.1/fake/images/124",
},
{
"rel": "bookmark",
- "href": "http://localhost/images/124",
+ "href": "http://localhost/fake/images/124",
}],
},
{
@@ -717,11 +724,11 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
},
"links": [{
"rel": "self",
- "href": "http://localhost/v1.1/images/125",
+ "href": "http://localhost/v1.1/fake/images/125",
},
{
"rel": "bookmark",
- "href": "http://localhost/images/125",
+ "href": "http://localhost/fake/images/125",
}],
},
{
@@ -748,11 +755,11 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
},
"links": [{
"rel": "self",
- "href": "http://localhost/v1.1/images/126",
+ "href": "http://localhost/v1.1/fake/images/126",
},
{
"rel": "bookmark",
- "href": "http://localhost/images/126",
+ "href": "http://localhost/fake/images/126",
}],
},
{
@@ -779,11 +786,11 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
},
"links": [{
"rel": "self",
- "href": "http://localhost/v1.1/images/127",
+ "href": "http://localhost/v1.1/fake/images/127",
},
{
"rel": "bookmark",
- "href": "http://localhost/images/127",
+ "href": "http://localhost/fake/images/127",
}],
},
{
@@ -796,11 +803,11 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
'progress': 100,
"links": [{
"rel": "self",
- "href": "http://localhost/v1.1/images/129",
+ "href": "http://localhost/v1.1/fake/images/129",
},
{
"rel": "bookmark",
- "href": "http://localhost/images/129",
+ "href": "http://localhost/fake/images/129",
}],
},
]
@@ -809,7 +816,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
def test_image_filter_with_name(self):
image_service = self.mox.CreateMockAnything()
- context = object()
+ context = self._get_fake_context()
filters = {'name': 'testname'}
image_service.index(context, filters=filters).AndReturn([])
self.mox.ReplayAll()
@@ -821,7 +828,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
def test_image_filter_with_status(self):
image_service = self.mox.CreateMockAnything()
- context = object()
+ context = self._get_fake_context()
filters = {'status': 'ACTIVE'}
image_service.index(context, filters=filters).AndReturn([])
self.mox.ReplayAll()
@@ -833,7 +840,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
def test_image_filter_with_property(self):
image_service = self.mox.CreateMockAnything()
- context = object()
+ context = self._get_fake_context()
filters = {'property-test': '3'}
image_service.index(context, filters=filters).AndReturn([])
self.mox.ReplayAll()
@@ -845,7 +852,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
def test_image_filter_server(self):
image_service = self.mox.CreateMockAnything()
- context = object()
+ context = self._get_fake_context()
# 'server' should be converted to 'property-instance_ref'
filters = {'property-instance_ref': 'http://localhost:8774/servers/12'}
image_service.index(context, filters=filters).AndReturn([])
@@ -859,7 +866,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
def test_image_filter_changes_since(self):
image_service = self.mox.CreateMockAnything()
- context = object()
+ context = self._get_fake_context()
filters = {'changes-since': '2011-01-24T17:08Z'}
image_service.index(context, filters=filters).AndReturn([])
self.mox.ReplayAll()
@@ -872,7 +879,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
def test_image_filter_with_type(self):
image_service = self.mox.CreateMockAnything()
- context = object()
+ context = self._get_fake_context()
filters = {'property-image_type': 'BASE'}
image_service.index(context, filters=filters).AndReturn([])
self.mox.ReplayAll()
@@ -884,7 +891,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
def test_image_filter_not_supported(self):
image_service = self.mox.CreateMockAnything()
- context = object()
+ context = self._get_fake_context()
filters = {'status': 'ACTIVE'}
image_service.detail(context, filters=filters).AndReturn([])
self.mox.ReplayAll()
@@ -897,7 +904,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
def test_image_no_filters(self):
image_service = self.mox.CreateMockAnything()
- context = object()
+ context = self._get_fake_context()
filters = {}
image_service.index(
context, filters=filters).AndReturn([])
@@ -911,11 +918,11 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
def test_image_detail_filter_with_name(self):
image_service = self.mox.CreateMockAnything()
- context = object()
+ context = self._get_fake_context()
filters = {'name': 'testname'}
image_service.detail(context, filters=filters).AndReturn([])
self.mox.ReplayAll()
- request = webob.Request.blank('/v1.1/images/detail?name=testname')
+ request = webob.Request.blank('/v1.1/123/images/detail?name=testname')
request.environ['nova.context'] = context
controller = images.ControllerV11(image_service=image_service)
controller.detail(request)
@@ -923,11 +930,11 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
def test_image_detail_filter_with_status(self):
image_service = self.mox.CreateMockAnything()
- context = object()
+ context = self._get_fake_context()
filters = {'status': 'ACTIVE'}
image_service.detail(context, filters=filters).AndReturn([])
self.mox.ReplayAll()
- request = webob.Request.blank('/v1.1/images/detail?status=ACTIVE')
+ request = webob.Request.blank('/v1.1/123/images/detail?status=ACTIVE')
request.environ['nova.context'] = context
controller = images.ControllerV11(image_service=image_service)
controller.detail(request)
@@ -935,11 +942,12 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
def test_image_detail_filter_with_property(self):
image_service = self.mox.CreateMockAnything()
- context = object()
+ context = self._get_fake_context()
filters = {'property-test': '3'}
image_service.detail(context, filters=filters).AndReturn([])
self.mox.ReplayAll()
- request = webob.Request.blank('/v1.1/images/detail?property-test=3')
+ request = webob.Request.blank(
+ '/v1.1/123/images/detail?property-test=3')
request.environ['nova.context'] = context
controller = images.ControllerV11(image_service=image_service)
controller.detail(request)
@@ -947,12 +955,12 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
def test_image_detail_filter_server(self):
image_service = self.mox.CreateMockAnything()
- context = object()
+ context = self._get_fake_context()
# 'server' should be converted to 'property-instance_ref'
filters = {'property-instance_ref': 'http://localhost:8774/servers/12'}
image_service.index(context, filters=filters).AndReturn([])
self.mox.ReplayAll()
- request = webob.Request.blank('/v1.1/images/detail?server='
+ request = webob.Request.blank('/v1.1/123/images/detail?server='
'http://localhost:8774/servers/12')
request.environ['nova.context'] = context
controller = images.ControllerV11(image_service=image_service)
@@ -961,11 +969,11 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
def test_image_detail_filter_changes_since(self):
image_service = self.mox.CreateMockAnything()
- context = object()
+ context = self._get_fake_context()
filters = {'changes-since': '2011-01-24T17:08Z'}
image_service.index(context, filters=filters).AndReturn([])
self.mox.ReplayAll()
- request = webob.Request.blank('/v1.1/images/detail?changes-since='
+ request = webob.Request.blank('/v1.1/123/images/detail?changes-since='
'2011-01-24T17:08Z')
request.environ['nova.context'] = context
controller = images.ControllerV11(image_service=image_service)
@@ -974,11 +982,11 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
def test_image_detail_filter_with_type(self):
image_service = self.mox.CreateMockAnything()
- context = object()
+ context = self._get_fake_context()
filters = {'property-image_type': 'BASE'}
image_service.index(context, filters=filters).AndReturn([])
self.mox.ReplayAll()
- request = webob.Request.blank('/v1.1/images/detail?type=BASE')
+ request = webob.Request.blank('/v1.1/123/images/detail?type=BASE')
request.environ['nova.context'] = context
controller = images.ControllerV11(image_service=image_service)
controller.index(request)
@@ -986,11 +994,11 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
def test_image_detail_filter_not_supported(self):
image_service = self.mox.CreateMockAnything()
- context = object()
+ context = self._get_fake_context()
filters = {'status': 'ACTIVE'}
image_service.detail(context, filters=filters).AndReturn([])
self.mox.ReplayAll()
- request = webob.Request.blank('/v1.1/images/detail?status=ACTIVE&'
+ request = webob.Request.blank('/v1.1/123/images/detail?status=ACTIVE&'
'UNSUPPORTEDFILTER=testname')
request.environ['nova.context'] = context
controller = images.ControllerV11(image_service=image_service)
@@ -999,11 +1007,11 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
def test_image_detail_no_filters(self):
image_service = self.mox.CreateMockAnything()
- context = object()
+ context = self._get_fake_context()
filters = {}
image_service.detail(context, filters=filters).AndReturn([])
self.mox.ReplayAll()
- request = webob.Request.blank('/v1.1/images/detail')
+ request = webob.Request.blank('/v1.1/123/images/detail')
request.environ['nova.context'] = context
controller = images.ControllerV11(image_service=image_service)
controller.detail(request)
@@ -1123,8 +1131,8 @@ class ImageXMLSerializationTest(test.TestCase):
TIMESTAMP = "2010-10-11T10:30:22Z"
SERVER_HREF = 'http://localhost/v1.1/servers/123'
SERVER_BOOKMARK = 'http://localhost/servers/123'
- IMAGE_HREF = 'http://localhost/v1.1/images/%s'
- IMAGE_BOOKMARK = 'http://localhost/images/%s'
+ IMAGE_HREF = 'http://localhost/v1.1/fake/images/%s'
+ IMAGE_BOOKMARK = 'http://localhost/fake/images/%s'
def test_show(self):
serializer = images.ImageXMLSerializer()