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