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 |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 23 | from tempest import exceptions |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 24 | from tempest.test import attr |
| 25 | |
| 26 | |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 27 | class CreateRegisterImagesTest(base.BaseV2ImageTest): |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 28 | |
| 29 | """ |
| 30 | Here we test the registration and creation of images |
| 31 | """ |
| 32 | |
Giampaolo Lauria | fd5f595 | 2013-05-15 09:44:24 -0400 | [diff] [blame] | 33 | @attr(type='gate') |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 34 | def test_register_with_invalid_container_format(self): |
| 35 | # Negative tests for invalid data supplied to POST /images |
| 36 | self.assertRaises(exceptions.BadRequest, self.client.create_image, |
| 37 | 'test', 'wrong', 'vhd') |
| 38 | |
Giampaolo Lauria | fd5f595 | 2013-05-15 09:44:24 -0400 | [diff] [blame] | 39 | @attr(type='gate') |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 40 | def test_register_with_invalid_disk_format(self): |
| 41 | self.assertRaises(exceptions.BadRequest, self.client.create_image, |
| 42 | 'test', 'bare', 'wrong') |
| 43 | |
Giampaolo Lauria | fd5f595 | 2013-05-15 09:44:24 -0400 | [diff] [blame] | 44 | @attr(type='gate') |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 45 | def test_register_then_upload(self): |
| 46 | # Register, then upload an image |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 47 | resp, body = self.create_image(name='New Name', |
| 48 | container_format='bare', |
| 49 | disk_format='raw', |
| 50 | visibility='public') |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 51 | self.assertIn('id', body) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 52 | image_id = body.get('id') |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 53 | self.assertIn('name', body) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 54 | self.assertEqual('New Name', body.get('name')) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 55 | self.assertIn('visibility', body) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 56 | self.assertTrue(body.get('visibility') == 'public') |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 57 | self.assertIn('status', body) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 58 | self.assertEqual('queued', body.get('status')) |
| 59 | |
| 60 | # Now try uploading an image file |
| 61 | image_file = StringIO.StringIO(('*' * 1024)) |
| 62 | resp, body = self.client.store_image(image_id, image_file) |
| 63 | self.assertEqual(resp.status, 204) |
| 64 | resp, body = self.client.get_image_metadata(image_id) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 65 | self.assertIn('size', body) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 66 | self.assertEqual(1024, body.get('size')) |
| 67 | |
| 68 | |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 69 | class ListImagesTest(base.BaseV2ImageTest): |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 70 | |
| 71 | """ |
| 72 | Here we test the listing of image information |
| 73 | """ |
| 74 | |
| 75 | @classmethod |
| 76 | def setUpClass(cls): |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 77 | super(ListImagesTest, cls).setUpClass() |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 78 | # We add a few images here to test the listing functionality of |
| 79 | # the images API |
| 80 | for x in xrange(0, 10): |
Matthew Treinish | 390ce11 | 2013-06-04 16:23:38 -0400 | [diff] [blame] | 81 | cls._create_standard_image(x) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 82 | |
| 83 | @classmethod |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 84 | def _create_standard_image(cls, number): |
| 85 | """ |
| 86 | Create a new standard image and return the ID of the newly-registered |
| 87 | image. Note that the size of the new image is a random number between |
| 88 | 1024 and 4096 |
| 89 | """ |
| 90 | image_file = StringIO.StringIO('*' * random.randint(1024, 4096)) |
| 91 | name = 'New Standard Image %s' % number |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 92 | resp, body = cls.create_image(name=name, container_format='bare', |
| 93 | disk_format='raw', |
| 94 | visibility='public') |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 95 | image_id = body['id'] |
| 96 | resp, body = cls.client.store_image(image_id, data=image_file) |
| 97 | |
| 98 | return image_id |
| 99 | |
Giampaolo Lauria | fd5f595 | 2013-05-15 09:44:24 -0400 | [diff] [blame] | 100 | @attr(type='gate') |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 101 | def test_index_no_params(self): |
| 102 | # Simple test to see all fixture images returned |
| 103 | resp, images_list = self.client.image_list() |
| 104 | self.assertEqual(resp['status'], '200') |
| 105 | image_list = map(lambda x: x['id'], images_list) |
| 106 | for image in self.created_images: |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 107 | self.assertIn(image, image_list) |
Zhi kun Liu | 682c7da | 2013-07-30 13:21:14 +0800 | [diff] [blame] | 108 | |
| 109 | @attr(type=['negative', 'gate']) |
| 110 | def test_get_image_meta_by_null_id(self): |
| 111 | self.assertRaises(exceptions.NotFound, |
| 112 | self.client.get_image_metadata, '') |