super(VolumeHostAttributeController, self).__init__(*args, **kwargs)
self.volume_api = volume.API()
- def _add_volume_host_attribute(self, context, resp_volume):
- try:
- db_volume = self.volume_api.get(context, resp_volume['id'])
- except Exception:
- return
- else:
- key = "%s:host" % Volume_host_attribute.alias
- resp_volume[key] = db_volume['host']
+ def _add_volume_host_attribute(self, context, req, resp_volume):
+ db_volume = req.cached_resource_by_id(resp_volume['id'])
+ key = "%s:host" % Volume_host_attribute.alias
+ resp_volume[key] = db_volume['host']
@wsgi.extends
def show(self, req, resp_obj, id):
context = req.environ['cinder.context']
if authorize(context):
resp_obj.attach(xml=VolumeHostAttributeTemplate())
- self._add_volume_host_attribute(context, resp_obj.obj['volume'])
+ volume = resp_obj.obj['volume']
+ self._add_volume_host_attribute(context, req, volume)
@wsgi.extends
def detail(self, req, resp_obj):
if authorize(context):
resp_obj.attach(xml=VolumeListHostAttributeTemplate())
for volume in list(resp_obj.obj['volumes']):
- self._add_volume_host_attribute(context, volume)
+ self._add_volume_host_attribute(context, req, volume)
class Volume_host_attribute(extensions.ExtensionDescriptor):
super(VolumeTenantAttributeController, self).__init__(*args, **kwargs)
self.volume_api = volume.API()
- def _add_volume_tenant_attribute(self, context, resp_volume):
- try:
- db_volume = self.volume_api.get(context, resp_volume['id'])
- except Exception:
- return
- else:
- key = "%s:tenant_id" % Volume_tenant_attribute.alias
- resp_volume[key] = db_volume['project_id']
+ def _add_volume_tenant_attribute(self, context, req, resp_volume):
+ db_volume = req.cached_resource_by_id(resp_volume['id'])
+ key = "%s:tenant_id" % Volume_tenant_attribute.alias
+ resp_volume[key] = db_volume['project_id']
@wsgi.extends
def show(self, req, resp_obj, id):
context = req.environ['cinder.context']
if authorize(context):
resp_obj.attach(xml=VolumeTenantAttributeTemplate())
- self._add_volume_tenant_attribute(context, resp_obj.obj['volume'])
+ volume = resp_obj.obj['volume']
+ self._add_volume_tenant_attribute(context, req, volume)
@wsgi.extends
def detail(self, req, resp_obj):
if authorize(context):
resp_obj.attach(xml=VolumeListTenantAttributeTemplate())
for volume in list(resp_obj.obj['volumes']):
- self._add_volume_tenant_attribute(context, volume)
+ self._add_volume_tenant_attribute(context, req, volume)
class Volume_tenant_attribute(extensions.ExtensionDescriptor):
try:
vol = self.volume_api.get(context, id)
+ req.cache_resource(vol)
except exception.NotFound:
raise exc.HTTPNotFound()
self._add_visible_admin_metadata(context, volume)
limited_list = common.limited(volumes, req)
+ req.cache_resource(limited_list)
res = [entity_maker(context, vol) for vol in limited_list]
return {'volumes': res}
try:
vol = self.volume_api.get(context, id)
+ req.cache_resource(vol)
except exception.NotFound:
msg = _("Volume could not be found")
raise exc.HTTPNotFound(explanation=msg)
volumes = self._view_builder.detail_list(req, limited_list)
else:
volumes = self._view_builder.summary_list(req, limited_list)
+ req.cache_resource(limited_list)
return volumes
def _image_uuid_from_href(self, image_href):
def blank(cls, *args, **kwargs):
kwargs['base_url'] = 'http://localhost/v1'
use_admin_context = kwargs.pop('use_admin_context', False)
- out = webob.Request.blank(*args, **kwargs)
+ out = os_wsgi.Request.blank(*args, **kwargs)
out.environ['cinder.context'] = FakeRequestContext(
'fake_user',
'fake',
1, 1, 1),
'size': 1}]}
self.assertEqual(res_dict, expected)
+ # Finally test that we cached the returned volumes
+ self.assertEqual(1, len(req.cached_resource()))
def test_volume_list_with_admin_metadata(self):
volume = stubs.stub_volume("1")
1, 1, 1),
'size': 1}]}
self.assertEqual(res_dict, expected)
+ # Finally test that we cached the returned volumes
+ self.assertEqual(1, len(req.cached_resource()))
def test_volume_list_detail_with_admin_metadata(self):
volume = stubs.stub_volume("1")
1, 1, 1),
'size': 1}}
self.assertEqual(res_dict, expected)
+ # Finally test that we cached the returned volume
+ self.assertIsNotNone(req.cached_resource_by_id('1'))
def test_volume_show_no_attachments(self):
def stub_volume_get(self, context, volume_id):
self.controller.show,
req,
1)
+ # Finally test that we did not cache anything
+ self.assertIsNone(req.cached_resource_by_id('1'))
def test_volume_detail_limit_offset(self):
def volume_detail_limit_offset(is_admin):
]
}
self.assertEqual(res_dict, expected)
+ # Finally test that we cached the returned volumes
+ self.assertEqual(1, len(req.cached_resource()))
def test_volume_list_detail(self):
self.stubs.Set(volume_api.API, 'get_all',
]
}
self.assertEqual(res_dict, expected)
+ # Finally test that we cached the returned volumes
+ self.assertEqual(1, len(req.cached_resource()))
def test_volume_list_detail_with_admin_metadata(self):
volume = stubs.stub_volume("1")
}
}
self.assertEqual(res_dict, expected)
+ # Finally test that we cached the returned volume
+ self.assertIsNotNone(req.cached_resource_by_id('1'))
def test_volume_show_no_attachments(self):
def stub_volume_get(self, context, volume_id):
req = fakes.HTTPRequest.blank('/v2/volumes/1')
self.assertRaises(webob.exc.HTTPNotFound, self.controller.show,
req, 1)
+ # Finally test that nothing was cached
+ self.assertIsNone(req.cached_resource_by_id('1'))
def test_volume_show_with_admin_metadata(self):
volume = stubs.stub_volume("1")