blob: 133bae03ad3127f2dd63ebf00b4b44c4827c1b51 [file] [log] [blame]
Matthew Treinisha62347f2013-03-01 16:37:30 -05001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2013 OpenStack Foundation
Matthew Treinisha62347f2013-03-01 16:37:30 -05004# All Rights Reserved.
Kurt Taylor6a6f5be2013-04-02 18:53:47 -04005# Copyright 2013 IBM Corp.
Matthew Treinisha62347f2013-03-01 16:37:30 -05006#
7# Licensed under the Apache License, Version 2.0 (the "License"); you may
8# not use this file except in compliance with the License. You may obtain
9# a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16# License for the specific language governing permissions and limitations
17# under the License.
18
19import cStringIO as StringIO
20import random
21
Sean Dague1937d092013-05-17 16:36:38 -040022from tempest.api.image import base
Hoisaleshwara Madan V Se50a6f12013-10-23 18:01:01 +053023from tempest.common.utils import data_utils
Matthew Treinisha62347f2013-03-01 16:37:30 -050024from tempest import exceptions
Matthew Treinisha62347f2013-03-01 16:37:30 -050025from tempest.test import attr
26
27
Matthew Treinishce3ef922013-03-11 14:02:46 -040028class CreateRegisterImagesTest(base.BaseV2ImageTest):
Matthew Treinisha62347f2013-03-01 16:37:30 -050029
30 """
31 Here we test the registration and creation of images
32 """
33
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040034 @attr(type='gate')
Matthew Treinisha62347f2013-03-01 16:37:30 -050035 def test_register_with_invalid_container_format(self):
36 # Negative tests for invalid data supplied to POST /images
37 self.assertRaises(exceptions.BadRequest, self.client.create_image,
38 'test', 'wrong', 'vhd')
39
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040040 @attr(type='gate')
Matthew Treinisha62347f2013-03-01 16:37:30 -050041 def test_register_with_invalid_disk_format(self):
42 self.assertRaises(exceptions.BadRequest, self.client.create_image,
43 'test', 'bare', 'wrong')
44
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040045 @attr(type='gate')
Hoisaleshwara Madan V Se50a6f12013-10-23 18:01:01 +053046 def test_register_upload_get_image_file(self):
47
48 """
49 Here we test these functionalities - Register image,
50 upload the image file, get image and get image file api's
51 """
52
53 image_name = data_utils.rand_name('image')
54 resp, body = self.create_image(name=image_name,
Matthew Treinishce3ef922013-03-11 14:02:46 -040055 container_format='bare',
56 disk_format='raw',
57 visibility='public')
Attila Fazekase191cb12013-07-29 06:41:52 +020058 self.assertIn('id', body)
Matthew Treinisha62347f2013-03-01 16:37:30 -050059 image_id = body.get('id')
Attila Fazekase191cb12013-07-29 06:41:52 +020060 self.assertIn('name', body)
Hoisaleshwara Madan V Se50a6f12013-10-23 18:01:01 +053061 self.assertEqual(image_name, body['name'])
Attila Fazekase191cb12013-07-29 06:41:52 +020062 self.assertIn('visibility', body)
Hoisaleshwara Madan V Se50a6f12013-10-23 18:01:01 +053063 self.assertEqual('public', body['visibility'])
Attila Fazekase191cb12013-07-29 06:41:52 +020064 self.assertIn('status', body)
Hoisaleshwara Madan V Se50a6f12013-10-23 18:01:01 +053065 self.assertEqual('queued', body['status'])
Matthew Treinisha62347f2013-03-01 16:37:30 -050066
67 # Now try uploading an image file
Hoisaleshwara Madan V Se50a6f12013-10-23 18:01:01 +053068 file_content = '*' * 1024
69 image_file = StringIO.StringIO(file_content)
Matthew Treinisha62347f2013-03-01 16:37:30 -050070 resp, body = self.client.store_image(image_id, image_file)
71 self.assertEqual(resp.status, 204)
Hoisaleshwara Madan V Se50a6f12013-10-23 18:01:01 +053072
73 # Now try to get image details
74 resp, body = self.client.get_image(image_id)
75 self.assertEqual(200, resp.status)
76 self.assertEqual(image_id, body['id'])
77 self.assertEqual(image_name, body['name'])
Attila Fazekase191cb12013-07-29 06:41:52 +020078 self.assertIn('size', body)
Matthew Treinisha62347f2013-03-01 16:37:30 -050079 self.assertEqual(1024, body.get('size'))
80
Hoisaleshwara Madan V Se50a6f12013-10-23 18:01:01 +053081 # Now try get image file
82 resp, body = self.client.get_image_file(image_id)
83 self.assertEqual(200, resp.status)
84 self.assertEqual(file_content, body)
85
Matthew Treinisha62347f2013-03-01 16:37:30 -050086
Matthew Treinishce3ef922013-03-11 14:02:46 -040087class ListImagesTest(base.BaseV2ImageTest):
Matthew Treinisha62347f2013-03-01 16:37:30 -050088
89 """
90 Here we test the listing of image information
91 """
92
93 @classmethod
94 def setUpClass(cls):
Matthew Treinishce3ef922013-03-11 14:02:46 -040095 super(ListImagesTest, cls).setUpClass()
Matthew Treinisha62347f2013-03-01 16:37:30 -050096 # We add a few images here to test the listing functionality of
97 # the images API
98 for x in xrange(0, 10):
Matthew Treinish390ce112013-06-04 16:23:38 -040099 cls._create_standard_image(x)
Matthew Treinisha62347f2013-03-01 16:37:30 -0500100
101 @classmethod
Matthew Treinisha62347f2013-03-01 16:37:30 -0500102 def _create_standard_image(cls, number):
103 """
104 Create a new standard image and return the ID of the newly-registered
105 image. Note that the size of the new image is a random number between
106 1024 and 4096
107 """
108 image_file = StringIO.StringIO('*' * random.randint(1024, 4096))
109 name = 'New Standard Image %s' % number
Matthew Treinishce3ef922013-03-11 14:02:46 -0400110 resp, body = cls.create_image(name=name, container_format='bare',
111 disk_format='raw',
112 visibility='public')
Matthew Treinisha62347f2013-03-01 16:37:30 -0500113 image_id = body['id']
114 resp, body = cls.client.store_image(image_id, data=image_file)
115
116 return image_id
117
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -0400118 @attr(type='gate')
Matthew Treinisha62347f2013-03-01 16:37:30 -0500119 def test_index_no_params(self):
120 # Simple test to see all fixture images returned
121 resp, images_list = self.client.image_list()
122 self.assertEqual(resp['status'], '200')
123 image_list = map(lambda x: x['id'], images_list)
124 for image in self.created_images:
Attila Fazekase191cb12013-07-29 06:41:52 +0200125 self.assertIn(image, image_list)