if self['update']:
self.client.reregister(location, name, params, properties)
else:
- self.client.register(name, location, params, properties)
+ r = self.client.register(name, location, params, properties)
+ print_dict(r)
def main(self, name, location):
super(self.__class__, self)._run()
# or implied, of GRNET S.A.
from kamaki.clients import Client, ClientError
-from kamaki.clients.utils import path4url
+from kamaki.clients.utils import path4url, filter_in
class ImageClient(Client):
disc_format, container_format, size, checksum, is_public, owner
:param properties: (dict) image properties (X-Image-Meta-Property)
+
+ :returns: (dict) details of the created image
"""
path = path4url('images') + '/'
self.set_header('X-Image-Meta-Name', name)
for key, val in properties.items():
async_headers['x-image-meta-property-%s' % key] = val
- self.post(path, success=200, async_headers=async_headers)
+ r = self.post(path, success=200, async_headers=async_headers)
+ return filter_in(r.headers, 'X-Image-')
def list_members(self, image_id):
"""
from unittest import TestCase
from itertools import product
+example_image_headers = {
+ 'x-image-meta-id': '3edd4d15-41b4-4a39-9601-015ef56b3bb3',
+ 'x-image-meta-checksum': 'df23837c30889252c0aed80b6f770a53a86',
+ 'x-image-meta-container-format': 'bare',
+ 'x-image-meta-location': 'pithos://a13528163db/con/obj_13.0',
+ 'x-image-meta-disk-format': 'diskdump',
+ 'x-image-meta-is-public': 'True',
+ 'x-image-meta-status': 'available',
+ 'x-image-meta-deleted-at': '',
+ 'x-image-meta-updated-at': '2013-04-11 15:22:39',
+ 'x-image-meta-created-at': '2013-04-11 15:22:37',
+ 'x-image-meta-owner': 'a13529bb3c3db',
+ 'x-image-meta-size': '1073741824',
+ 'x-image-meta-name': 'img_1365686546.0',
+ 'extraheaders': 'should be ignored'
+}
example_images = [
{
"status": "available",
@patch('%s.post' % image_pkg, return_value=FR())
def test_register(self, post, SH):
img0 = example_images_detailed[0]
+ FR.headers = example_image_headers
img0_location = img0['location']
img0_name = 'A new img0 name'
prfx = 'x-image-meta-'
async_headers['%s%s' % (prfx, k)] = args[i]
props['%s%s' % (proprfx, args[i])] = k
async_headers.update(props)
- self.client.register(
+ r = self.client.register(
img0_name, img0_location,
params=params, properties=props)
+ expectedict = dict(example_image_headers)
+ expectedict.pop('extraheaders')
+ self.assert_dicts_are_equal(expectedict, r)
self.assertEqual(
post.mock_calls[-1],
call('/images/', async_headers=async_headers, success=200))
from kamaki.clients import ClientError
+IMGMETA = set([
+ 'id', 'name', 'checksum', 'container-format', 'location', 'disk-format',
+ 'is-public', 'status', 'deleted-at', 'updated-at', 'created-at', 'owner',
+ 'size'])
+
+
class Image(livetest.Generic):
def setUp(self):
self.now = time.mktime(time.gmtime())
cyclades_url = self['compute', 'url']
self.cyclades = CycladesClient(cyclades_url, self['token'])
self._imglist = {}
+ self._imgdetails = {}
def test_000(self):
self._prepare_img()
print('\t- ok')
f.close()
- self.client.register(
+ r = self.client.register(
self.imgname,
self.location,
params=dict(is_public=True))
- img = self._get_img_by_name(self.imgname)
- self._imglist[self.imgname] = img
+ self._imglist[self.imgname] = dict(
+ name=r['x-image-meta-name'], id=r['x-image-meta-id'])
+ self._imgdetails[self.imgname] = r
def tearDown(self):
for img in self._imglist.values():
self.assertTrue(self._imglist)
for img in self._imglist.values():
self.assertTrue(img is not None)
+ r = set(self._imgdetails[img['name']].keys())
+ self.assertTrue(
+ r.issubset(['x-image-meta-%s' % k for k in IMGMETA]))
def test_set_members(self):
"""Test set_members"""