try:
# NOTE(dosaboy): the v2 api separates update from upload
if data and CONF.glance_api_version > 1:
- image_meta = self._client.call(context, 'upload', image_id,
- image_meta['data'])
+ self._client.call(context, 'upload', image_id, data)
+ image_meta = self._client.call(context, 'get', image_id)
else:
image_meta = self._client.call(context, 'update', image_id,
**image_meta)
# NOTE(bcwaldon): HACK to get client.images.* to work
self.images = lambda: None
- for fn in ('list', 'get', 'data', 'create', 'update', 'delete'):
+ for fn in ('list', 'get', 'data', 'create', 'update', 'upload',
+ 'delete'):
setattr(self.images, fn, getattr(self, fn))
+ self.schemas = lambda: None
+ setattr(self.schemas, 'get', getattr(self, 'schemas_get'))
+
# TODO(bcwaldon): implement filters
def list(self, filters=None, marker=None, limit=30):
if marker is None:
raise glanceclient.exc.NotFound(image_id)
def data(self, image_id):
- self.get(image_id)
- return []
+ image = self.get(image_id)
+ if getattr(image, 'size', 0):
+ return ['*' * image.size]
+ else:
+ return []
def create(self, **metadata):
metadata['created_at'] = NOW_GLANCE_FORMAT
for i, image in enumerate(self._images):
if image.id == str(image_id):
for k, v in metadata.items():
- setattr(self._images[i], k, v)
+ if k == 'data':
+ setattr(self._images[i], 'size', len(v))
+ else:
+ setattr(self._images[i], k, v)
return self._images[i]
raise glanceclient.exc.NotFound(image_id)
return
raise glanceclient.exc.NotFound(image_id)
+ def upload(self, image_id, data):
+ for i, image in enumerate(self._images):
+ if image.id == image_id:
+ setattr(self._images[i], 'size', len(data))
+ return
+ raise glanceclient.exc.NotFound(image_id)
+
+ def schemas_get(self, schema_name):
+ if schema_name != 'image':
+ raise glanceclient.exc.NotFound()
+ return FakeSchema()
+
class FakeImage(object):
def __init__(self, metadata):
new_image_data = self.service.show(self.context, image_id)
self.assertEqual('new image name', new_image_data['name'])
+ def test_update_v2(self):
+ self.flags(glance_api_version=2)
+ self.test_update()
+
+ def test_update_with_data(self):
+ fixture = self._make_fixture(name='test image')
+ image = self.service.create(self.context, fixture)
+ image_id = image['id']
+ data = '*' * 256
+ self.service.update(self.context, image_id, fixture, data=data)
+
+ new_image_data = self.service.show(self.context, image_id)
+ self.assertEqual(256, new_image_data['size'])
+
+ def test_update_with_data_v2(self):
+ self.flags(glance_api_version=2)
+ self.test_update_with_data()
+
def test_delete(self):
fixture1 = self._make_fixture(name='test image 1')
fixture2 = self._make_fixture(name='test image 2')