Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 3 | # Copyright 2013 OpenStack Foundation |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 4 | # All Rights Reserved. |
Kurt Taylor | 6a6f5be | 2013-04-02 18:53:47 -0400 | [diff] [blame] | 5 | # Copyright 2013 IBM Corp. |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 6 | # |
| 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 | |
| 19 | import cStringIO as StringIO |
| 20 | import random |
| 21 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 22 | from tempest.api.image import base |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 23 | from tempest.common.utils import data_utils |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 24 | from tempest import exceptions |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 25 | from tempest.test import attr |
| 26 | |
| 27 | |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 28 | class CreateRegisterImagesTest(base.BaseV2ImageTest): |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 29 | |
| 30 | """ |
| 31 | Here we test the registration and creation of images |
| 32 | """ |
| 33 | |
Giampaolo Lauria | fd5f595 | 2013-05-15 09:44:24 -0400 | [diff] [blame] | 34 | @attr(type='gate') |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 35 | 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 Lauria | fd5f595 | 2013-05-15 09:44:24 -0400 | [diff] [blame] | 40 | @attr(type='gate') |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 41 | def test_register_with_invalid_disk_format(self): |
| 42 | self.assertRaises(exceptions.BadRequest, self.client.create_image, |
| 43 | 'test', 'bare', 'wrong') |
| 44 | |
Giampaolo Lauria | fd5f595 | 2013-05-15 09:44:24 -0400 | [diff] [blame] | 45 | @attr(type='gate') |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 46 | 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 Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 55 | container_format='bare', |
| 56 | disk_format='raw', |
| 57 | visibility='public') |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 58 | self.assertIn('id', body) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 59 | image_id = body.get('id') |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 60 | self.assertIn('name', body) |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 61 | self.assertEqual(image_name, body['name']) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 62 | self.assertIn('visibility', body) |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 63 | self.assertEqual('public', body['visibility']) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 64 | self.assertIn('status', body) |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 65 | self.assertEqual('queued', body['status']) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 66 | |
| 67 | # Now try uploading an image file |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 68 | file_content = '*' * 1024 |
| 69 | image_file = StringIO.StringIO(file_content) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 70 | resp, body = self.client.store_image(image_id, image_file) |
| 71 | self.assertEqual(resp.status, 204) |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 72 | |
| 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 Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 78 | self.assertIn('size', body) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 79 | self.assertEqual(1024, body.get('size')) |
| 80 | |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 81 | # 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 Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 86 | |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 87 | class ListImagesTest(base.BaseV2ImageTest): |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 88 | |
| 89 | """ |
| 90 | Here we test the listing of image information |
| 91 | """ |
| 92 | |
| 93 | @classmethod |
| 94 | def setUpClass(cls): |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 95 | super(ListImagesTest, cls).setUpClass() |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 96 | # We add a few images here to test the listing functionality of |
| 97 | # the images API |
| 98 | for x in xrange(0, 10): |
Matthew Treinish | 390ce11 | 2013-06-04 16:23:38 -0400 | [diff] [blame] | 99 | cls._create_standard_image(x) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 100 | |
| 101 | @classmethod |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 102 | 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 Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 110 | resp, body = cls.create_image(name=name, container_format='bare', |
| 111 | disk_format='raw', |
| 112 | visibility='public') |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 113 | image_id = body['id'] |
| 114 | resp, body = cls.client.store_image(image_id, data=image_file) |
| 115 | |
| 116 | return image_id |
| 117 | |
Giampaolo Lauria | fd5f595 | 2013-05-15 09:44:24 -0400 | [diff] [blame] | 118 | @attr(type='gate') |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 119 | 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 Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 125 | self.assertIn(image, image_list) |