Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 1 | import unittest2 as unittest |
| 2 | |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 3 | from nose.plugins.attrib import attr |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 4 | |
| 5 | from tempest import exceptions |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 6 | from tempest import openstack |
Daryl Walleck | f008703 | 2011-12-18 13:37:05 -0600 | [diff] [blame] | 7 | from tempest.common.utils.data_utils import rand_name |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 8 | |
| 9 | |
Daryl Walleck | f008703 | 2011-12-18 13:37:05 -0600 | [diff] [blame] | 10 | def _parse_image_id(image_ref): |
| 11 | temp = image_ref.rsplit('/') |
| 12 | return temp[len(temp) - 1] |
| 13 | |
| 14 | |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 15 | class ListImagesTest(unittest.TestCase): |
| 16 | |
| 17 | @classmethod |
| 18 | def setUpClass(cls): |
| 19 | cls.os = openstack.Manager() |
| 20 | cls.client = cls.os.images_client |
| 21 | cls.servers_client = cls.os.servers_client |
| 22 | cls.config = cls.os.config |
| 23 | cls.image_ref = cls.config.env.image_ref |
| 24 | cls.flavor_ref = cls.config.env.flavor_ref |
| 25 | |
Daryl Walleck | f008703 | 2011-12-18 13:37:05 -0600 | [diff] [blame] | 26 | name = rand_name('server') |
| 27 | resp, cls.server1 = cls.servers_client.create_server(name, |
Daryl Walleck | 2fbb9d1 | 2012-01-29 22:00:02 -0600 | [diff] [blame] | 28 | cls.image_ref, |
| 29 | cls.flavor_ref) |
Daryl Walleck | f008703 | 2011-12-18 13:37:05 -0600 | [diff] [blame] | 30 | name = rand_name('server') |
| 31 | resp, cls.server2 = cls.servers_client.create_server(name, |
Daryl Walleck | 2fbb9d1 | 2012-01-29 22:00:02 -0600 | [diff] [blame] | 32 | cls.image_ref, |
| 33 | cls.flavor_ref) |
| 34 | cls.servers_client.wait_for_server_status(cls.server1['id'], 'ACTIVE') |
Daryl Walleck | f008703 | 2011-12-18 13:37:05 -0600 | [diff] [blame] | 35 | cls.servers_client.wait_for_server_status(cls.server2['id'], 'ACTIVE') |
| 36 | |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 37 | # Create images to be used in the filter tests |
Daryl Walleck | f008703 | 2011-12-18 13:37:05 -0600 | [diff] [blame] | 38 | image1_name = rand_name('image') |
| 39 | resp, body = cls.client.create_image(cls.server1['id'], image1_name) |
| 40 | cls.image1_id = _parse_image_id(resp['location']) |
| 41 | cls.client.wait_for_image_resp_code(cls.image1_id, 200) |
| 42 | cls.client.wait_for_image_status(cls.image1_id, 'ACTIVE') |
| 43 | resp, cls.image1 = cls.client.get_image(cls.image1_id) |
| 44 | |
Daryl Walleck | 2fbb9d1 | 2012-01-29 22:00:02 -0600 | [diff] [blame] | 45 | # Servers have a hidden property for when they are being imaged |
| 46 | # Performing back-to-back create image calls on a single |
| 47 | # server will sometimes cause failures |
Daryl Walleck | f008703 | 2011-12-18 13:37:05 -0600 | [diff] [blame] | 48 | image3_name = rand_name('image') |
| 49 | resp, body = cls.client.create_image(cls.server2['id'], image3_name) |
| 50 | cls.image3_id = _parse_image_id(resp['location']) |
| 51 | cls.client.wait_for_image_resp_code(cls.image3_id, 200) |
| 52 | cls.client.wait_for_image_status(cls.image3_id, 'ACTIVE') |
| 53 | resp, cls.image3 = cls.client.get_image(cls.image3_id) |
| 54 | |
Daryl Walleck | 2fbb9d1 | 2012-01-29 22:00:02 -0600 | [diff] [blame] | 55 | image2_name = rand_name('image') |
| 56 | resp, body = cls.client.create_image(cls.server1['id'], image2_name) |
| 57 | cls.image2_id = _parse_image_id(resp['location']) |
| 58 | cls.client.wait_for_image_resp_code(cls.image2_id, 200) |
| 59 | cls.client.wait_for_image_status(cls.image2_id, 'ACTIVE') |
| 60 | resp, cls.image2 = cls.client.get_image(cls.image2_id) |
| 61 | |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 62 | @classmethod |
| 63 | def tearDownClass(cls): |
| 64 | cls.client.delete_image(cls.image1_id) |
| 65 | cls.client.delete_image(cls.image2_id) |
| 66 | cls.client.delete_image(cls.image3_id) |
| 67 | cls.servers_client.delete_server(cls.server1['id']) |
| 68 | cls.servers_client.delete_server(cls.server2['id']) |
| 69 | |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 70 | @attr(type='smoke') |
| 71 | def test_get_image(self): |
| 72 | """Returns the correct details for a single image""" |
| 73 | resp, image = self.client.get_image(self.image_ref) |
| 74 | self.assertEqual(self.image_ref, image['id']) |
| 75 | |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 76 | @attr(type='negative') |
| 77 | def test_get_image_not_existing(self): |
| 78 | """Check raises a NotFound""" |
| 79 | self.assertRaises(exceptions.NotFound, self.client.get_image, |
| 80 | "nonexistingimageid") |
| 81 | |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 82 | @attr(type='smoke') |
| 83 | def test_list_images(self): |
| 84 | """The list of all images should contain the image""" |
| 85 | resp, images = self.client.list_images() |
| 86 | found = any([i for i in images if i['id'] == self.image_ref]) |
| 87 | self.assertTrue(found) |
| 88 | |
Daryl Walleck | f008703 | 2011-12-18 13:37:05 -0600 | [diff] [blame] | 89 | @attr(type='positive') |
| 90 | def test_list_images_filter_by_status(self): |
| 91 | """ |
| 92 | The list of images should contain only images with the provided status |
| 93 | """ |
| 94 | params = {'status': 'ACTIVE'} |
| 95 | resp, images = self.client.list_images(params) |
| 96 | |
| 97 | self.assertTrue(any([i for i in images if i['id'] == self.image1_id])) |
| 98 | self.assertTrue(any([i for i in images if i['id'] == self.image2_id])) |
| 99 | self.assertTrue(any([i for i in images if i['id'] == self.image3_id])) |
| 100 | |
| 101 | @attr(type='positive') |
| 102 | def test_list_images_filter_by_name(self): |
| 103 | """ |
| 104 | List of all images should contain the expected images filtered by name |
| 105 | """ |
| 106 | params = {'name': self.image1['name']} |
| 107 | resp, images = self.client.list_images(params) |
| 108 | |
| 109 | self.assertTrue(any([i for i in images if i['id'] == self.image1_id])) |
| 110 | self.assertFalse(any([i for i in images if i['id'] == self.image2_id])) |
| 111 | self.assertFalse(any([i for i in images if i['id'] == self.image3_id])) |
| 112 | |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 113 | @unittest.skip('Skipping until Nova Bug 912837 is fixed') |
Daryl Walleck | f008703 | 2011-12-18 13:37:05 -0600 | [diff] [blame] | 114 | @attr(type='positive') |
| 115 | def test_list_images_filter_by_server_id(self): |
| 116 | """The images should contain images filtered by server id""" |
| 117 | params = {'server': self.server1['id']} |
| 118 | resp, images = self.client.list_images(params) |
| 119 | |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 120 | self.assertTrue(any([i for i in images if i['id'] == self.image1_id]), |
| 121 | "Failed to find image %s in images. Got images %s" % |
| 122 | (self.image1_id, images)) |
Daryl Walleck | f008703 | 2011-12-18 13:37:05 -0600 | [diff] [blame] | 123 | self.assertTrue(any([i for i in images if i['id'] == self.image2_id])) |
| 124 | self.assertFalse(any([i for i in images if i['id'] == self.image3_id])) |
| 125 | |
| 126 | @attr(type='positive') |
| 127 | def test_list_images_filter_by_server_ref(self): |
| 128 | """The list of servers should be filtered by server ref""" |
| 129 | params = {'server': self.image3['metadata']['instance_ref']} |
| 130 | resp, images = self.client.list_images(params) |
| 131 | |
| 132 | self.assertFalse(any([i for i in images if i['id'] == self.image1_id])) |
| 133 | self.assertFalse(any([i for i in images if i['id'] == self.image2_id])) |
| 134 | self.assertTrue(any([i for i in images if i['id'] == self.image3_id])) |
| 135 | |
| 136 | @attr(type='positive') |
| 137 | def test_list_images_filter_by_type(self): |
| 138 | """The list of servers should be filtered by image type""" |
| 139 | params = {'type': 'snapshot'} |
| 140 | resp, images = self.client.list_images(params) |
| 141 | |
| 142 | self.assertTrue(any([i for i in images if i['id'] == self.image1_id])) |
| 143 | self.assertTrue(any([i for i in images if i['id'] == self.image2_id])) |
| 144 | self.assertTrue(any([i for i in images if i['id'] == self.image3_id])) |
| 145 | self.assertFalse(any([i for i in images if i['id'] == self.image_ref])) |
| 146 | |
| 147 | @attr(type='positive') |
| 148 | def test_list_images_limit_results(self): |
| 149 | """Verify only the expected number of results are returned""" |
| 150 | params = {'limit': '1'} |
| 151 | resp, images = self.client.list_images(params) |
| 152 | self.assertEqual(1, len(images)) |
| 153 | |
| 154 | @attr(type='positive') |
| 155 | def test_list_images_filter_by_changes_since(self): |
| 156 | """Verify only updated images are returned in the detailed list""" |
| 157 | |
| 158 | #Becoming ACTIVE will modify the updated time |
| 159 | #Filter by the image's created time |
| 160 | params = {'changes-since': self.image3['created']} |
| 161 | resp, images = self.client.list_images(params) |
| 162 | found = any([i for i in images if i['id'] == self.image3_id]) |
| 163 | self.assertTrue(found) |
| 164 | |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 165 | @attr(type='smoke') |
| 166 | def test_list_images_with_detail(self): |
Daryl Walleck | f008703 | 2011-12-18 13:37:05 -0600 | [diff] [blame] | 167 | """Detailed list of all images should contain the expected images""" |
| 168 | resp, images = self.client.list_images_with_detail() |
| 169 | |
| 170 | self.assertTrue(any([i for i in images if i['id'] == self.image1_id])) |
| 171 | self.assertTrue(any([i for i in images if i['id'] == self.image2_id])) |
| 172 | self.assertTrue(any([i for i in images if i['id'] == self.image3_id])) |
| 173 | |
| 174 | @attr(type='positive') |
| 175 | def test_list_images_with_detail_filter_by_status(self): |
| 176 | """ |
| 177 | Detailed list of all images should only contain images |
| 178 | with the provided status |
| 179 | """ |
| 180 | params = {'status': 'ACTIVE'} |
| 181 | resp, images = self.client.list_images_with_detail(params) |
| 182 | |
| 183 | self.assertTrue(any([i for i in images if i['id'] == self.image1_id])) |
| 184 | self.assertTrue(any([i for i in images if i['id'] == self.image2_id])) |
| 185 | self.assertTrue(any([i for i in images if i['id'] == self.image3_id])) |
| 186 | |
| 187 | @attr(type='positive') |
| 188 | def test_list_images_with_detail_filter_by_name(self): |
| 189 | """ |
| 190 | Detailed list of all images should contain the expected |
| 191 | images filtered by name |
| 192 | """ |
| 193 | params = {'name': self.image1['name']} |
| 194 | resp, images = self.client.list_images_with_detail(params) |
| 195 | |
| 196 | self.assertTrue(any([i for i in images if i['id'] == self.image1_id])) |
| 197 | self.assertFalse(any([i for i in images if i['id'] == self.image2_id])) |
| 198 | self.assertFalse(any([i for i in images if i['id'] == self.image3_id])) |
| 199 | |
| 200 | @attr(type='positive') |
| 201 | def test_list_images_with_detail_limit_results(self): |
| 202 | """ |
| 203 | Verify only the expected number of results (with full details) |
| 204 | are returned |
| 205 | """ |
| 206 | params = {'limit': '1'} |
| 207 | resp, images = self.client.list_images_with_detail(params) |
| 208 | self.assertEqual(1, len(images)) |
| 209 | |
| 210 | @attr(type='positive') |
| 211 | def test_list_images_with_detail_filter_by_server_ref(self): |
| 212 | """Detailed list of servers should be filtered by server ref""" |
| 213 | params = {'server': self.image3['metadata']['instance_ref']} |
| 214 | resp, images = self.client.list_images_with_detail(params) |
| 215 | |
| 216 | self.assertFalse(any([i for i in images if i['id'] == self.image1_id])) |
| 217 | self.assertFalse(any([i for i in images if i['id'] == self.image2_id])) |
| 218 | self.assertTrue(any([i for i in images if i['id'] == self.image3_id])) |
| 219 | |
| 220 | @attr(type='positive') |
| 221 | def test_list_images_with_detail_filter_by_type(self): |
| 222 | """The detailed list of servers should be filtered by image type""" |
| 223 | params = {'type': 'snapshot'} |
| 224 | resp, images = self.client.list_images_with_detail(params) |
| 225 | resp, image4 = self.client.get_image(self.image_ref) |
| 226 | |
| 227 | self.assertTrue(any([i for i in images if i['id'] == self.image1_id])) |
| 228 | self.assertTrue(any([i for i in images if i['id'] == self.image2_id])) |
| 229 | self.assertTrue(any([i for i in images if i['id'] == self.image3_id])) |
| 230 | self.assertFalse(any([i for i in images if i['id'] == self.image_ref])) |
| 231 | |
| 232 | @attr(type='positive') |
| 233 | def test_list_images_with_detail_filter_by_changes_since(self): |
| 234 | """Verify an update image is returned""" |
| 235 | |
| 236 | #Becoming ACTIVE will modify the updated time |
| 237 | #Filter by the image's created time |
| 238 | params = {'changes-since': self.image1['created']} |
| 239 | resp, images = self.client.list_images_with_detail(params) |
| 240 | self.assertTrue(any([i for i in images if i['id'] == self.image1_id])) |
sapan-kona | 89422e7 | 2011-12-22 23:30:29 +0530 | [diff] [blame] | 241 | |
| 242 | @attr(type='negative') |
| 243 | def test_get_nonexistant_image(self): |
| 244 | """Negative test: GET on non existant image should fail""" |
| 245 | try: |
| 246 | resp, image = self.client.get_image(999) |
| 247 | except: |
| 248 | pass |
| 249 | else: |
| 250 | self.fail('GET on non existant image should fail') |