Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 1 | from nose.plugins.attrib import attr |
| 2 | from storm import openstack |
| 3 | from storm.common.utils.data_utils import rand_name |
| 4 | import unittest2 as unittest |
| 5 | import storm.config |
| 6 | |
Jay Pipes | 7f75763 | 2011-12-02 15:53:32 -0500 | [diff] [blame^] | 7 | # Some module-level skip conditions |
| 8 | create_image_enabled = False |
| 9 | |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 10 | |
| 11 | class ImagesTest(unittest.TestCase): |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 12 | |
| 13 | @classmethod |
| 14 | def setUpClass(cls): |
| 15 | cls.os = openstack.Manager() |
| 16 | cls.client = cls.os.images_client |
| 17 | cls.servers_client = cls.os.servers_client |
Jay Pipes | 7f75763 | 2011-12-02 15:53:32 -0500 | [diff] [blame^] | 18 | cls.config = cls.os.config |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 19 | cls.image_ref = cls.config.env.image_ref |
| 20 | cls.flavor_ref = cls.config.env.flavor_ref |
Jay Pipes | 7f75763 | 2011-12-02 15:53:32 -0500 | [diff] [blame^] | 21 | create_image_enabled = cls.config.env.create_image_enabled |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 22 | |
| 23 | def _parse_image_id(self, image_ref): |
| 24 | temp = image_ref.rsplit('/') |
| 25 | return temp[6] |
| 26 | |
| 27 | @unittest.skipIf(not create_image_enabled, |
| 28 | 'Environment unable to create images.') |
| 29 | def test_create_delete_image(self): |
| 30 | """An image for the provided server should be created""" |
| 31 | server_name = rand_name('server') |
| 32 | resp, server = self.servers_client.create_server(server_name, |
| 33 | self.image_ref, |
| 34 | self.flavor_ref) |
| 35 | self.servers_client.wait_for_server_status(server['id'], 'ACTIVE') |
| 36 | |
| 37 | #Create a new image |
| 38 | name = rand_name('image') |
| 39 | resp, body = self.client.create_image(server['id'], name) |
| 40 | image_id = self._parse_image_id(resp['location']) |
Daryl Walleck | 416af92 | 2011-11-22 22:28:33 -0600 | [diff] [blame] | 41 | self.client.wait_for_image_resp_code(image_id, 200) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 42 | self.client.wait_for_image_status(image_id, 'ACTIVE') |
| 43 | |
| 44 | #Verify the image was created correctly |
| 45 | resp, image = self.client.get_image(image_id) |
| 46 | self.assertEqual(name, image['name']) |
| 47 | |
| 48 | #Teardown |
| 49 | self.client.delete_image(image['id']) |
| 50 | self.servers_client.delete_server(server['id']) |
| 51 | |
| 52 | @attr(type='smoke') |
| 53 | def test_get_image(self): |
| 54 | """Returns the correct details for a single image""" |
| 55 | resp, image = self.client.get_image(self.image_ref) |
| 56 | self.assertEqual(self.image_ref, image['id']) |
| 57 | |
| 58 | @attr(type='smoke') |
| 59 | def test_list_images(self): |
| 60 | """The list of all images should contain the image flavor""" |
| 61 | resp, images = self.client.list_images() |
| 62 | found = any([i for i in images if i['id'] == self.image_ref]) |
| 63 | self.assertTrue(found) |
| 64 | |
| 65 | @attr(type='smoke') |
| 66 | def test_list_images_with_detail(self): |
| 67 | """Detailed list of all images should contain the expected image""" |
| 68 | resp, images = self.client.list_images_with_detail() |
| 69 | found = any([i for i in images if i['id'] == self.image_ref]) |
| 70 | self.assertTrue(found) |