Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 1 | import json |
| 2 | import os |
Aaron Lee | 35b8c92 | 2011-10-18 17:07:19 -0500 | [diff] [blame^] | 3 | import re |
Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 4 | |
Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 5 | from kong import openstack |
Soren Hansen | 6adacc8 | 2011-09-09 13:34:35 +0200 | [diff] [blame] | 6 | from kong import tests |
Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 7 | |
| 8 | |
Soren Hansen | 6adacc8 | 2011-09-09 13:34:35 +0200 | [diff] [blame] | 9 | class ImagesTest(tests.FunctionalTest): |
Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 10 | |
| 11 | def setUp(self): |
Soren Hansen | 6adacc8 | 2011-09-09 13:34:35 +0200 | [diff] [blame] | 12 | super(ImagesTest, self).setUp() |
Soren Hansen | d6b047a | 2011-09-09 13:39:32 +0200 | [diff] [blame] | 13 | self.os = openstack.Manager(self.nova) |
Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 14 | |
Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 15 | def _assert_image_links(self, image): |
| 16 | image_id = str(image['id']) |
| 17 | |
Soren Hansen | 5f4ad83 | 2011-09-09 14:08:19 +0200 | [diff] [blame] | 18 | mgmt_url = self.os.nova.management_url |
Aaron Lee | 35b8c92 | 2011-10-18 17:07:19 -0500 | [diff] [blame^] | 19 | mgmt_url = re.sub(r'1//', r'1/', mgmt_url) # TODO: is this a bug in Nova? |
Soren Hansen | 5f4ad83 | 2011-09-09 14:08:19 +0200 | [diff] [blame] | 20 | bmk_url = re.sub(r'v1.1\/', r'', mgmt_url) |
Aaron Lee | 35b8c92 | 2011-10-18 17:07:19 -0500 | [diff] [blame^] | 21 | self_link = {'rel': 'self', |
| 22 | 'href': os.path.join(mgmt_url, 'images', image_id)} |
| 23 | bookmark_link = {'rel': 'bookmark', |
| 24 | 'href': os.path.join(bmk_url, 'images', image_id)} |
Soren Hansen | 5f4ad83 | 2011-09-09 14:08:19 +0200 | [diff] [blame] | 25 | |
Aaron Lee | 35b8c92 | 2011-10-18 17:07:19 -0500 | [diff] [blame^] | 26 | self.assertIn(bookmark_link, image['links']) |
| 27 | self.assertIn(self_link, image['links']) |
Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 28 | |
| 29 | def _assert_image_entity_basic(self, image): |
| 30 | actual_keys = set(image.keys()) |
| 31 | expected_keys = set(( |
| 32 | 'id', |
| 33 | 'name', |
| 34 | 'links', |
| 35 | )) |
| 36 | self.assertEqual(actual_keys, expected_keys) |
| 37 | |
| 38 | self._assert_image_links(image) |
| 39 | |
| 40 | def _assert_image_entity_detailed(self, image): |
| 41 | keys = image.keys() |
| 42 | if 'server' in keys: |
| 43 | keys.remove('server') |
| 44 | actual_keys = set(keys) |
| 45 | expected_keys = set(( |
Aaron Lee | 35b8c92 | 2011-10-18 17:07:19 -0500 | [diff] [blame^] | 46 | 'created', |
Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 47 | 'id', |
Aaron Lee | 35b8c92 | 2011-10-18 17:07:19 -0500 | [diff] [blame^] | 48 | 'links', |
| 49 | 'metadata', |
| 50 | 'minDisk', |
| 51 | 'minRam', |
Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 52 | 'name', |
| 53 | 'progress', |
Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 54 | 'status', |
Aaron Lee | 35b8c92 | 2011-10-18 17:07:19 -0500 | [diff] [blame^] | 55 | 'updated', |
Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 56 | )) |
| 57 | self.assertEqual(actual_keys, expected_keys) |
| 58 | |
| 59 | self._assert_image_links(image) |
| 60 | |
| 61 | def test_index(self): |
| 62 | """List all images""" |
| 63 | |
| 64 | response, body = self.os.nova.request('GET', '/images') |
| 65 | |
| 66 | self.assertEqual(response['status'], '200') |
| 67 | resp_body = json.loads(body) |
| 68 | self.assertEqual(resp_body.keys(), ['images']) |
| 69 | |
| 70 | for image in resp_body['images']: |
| 71 | self._assert_image_entity_basic(image) |
Soren Hansen | fce58c5 | 2011-09-09 16:07:13 +0200 | [diff] [blame] | 72 | test_index.tags = ['nova', 'glance'] |
Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 73 | |
| 74 | def test_detail(self): |
| 75 | """List all images in detail""" |
| 76 | |
| 77 | response, body = self.os.nova.request('GET', '/images/detail') |
Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 78 | self.assertEqual(response['status'], '200') |
| 79 | resp_body = json.loads(body) |
| 80 | self.assertEqual(resp_body.keys(), ['images']) |
| 81 | |
| 82 | for image in resp_body['images']: |
| 83 | self._assert_image_entity_detailed(image) |
Soren Hansen | fce58c5 | 2011-09-09 16:07:13 +0200 | [diff] [blame] | 84 | test_detail.tags = ['nova', 'glance'] |