blob: d8a47210f115259fa1d1cfc619a041763604fbab [file] [log] [blame]
Soren Hansenbc1d3a02011-09-08 13:33:17 +02001import json
2import os
Aaron Lee35b8c922011-10-18 17:07:19 -05003import re
Soren Hansenbc1d3a02011-09-08 13:33:17 +02004
Soren Hansenbc1d3a02011-09-08 13:33:17 +02005from kong import openstack
Soren Hansen6adacc82011-09-09 13:34:35 +02006from kong import tests
Soren Hansenbc1d3a02011-09-08 13:33:17 +02007
8
Soren Hansen6adacc82011-09-09 13:34:35 +02009class ImagesTest(tests.FunctionalTest):
Soren Hansenbc1d3a02011-09-08 13:33:17 +020010
11 def setUp(self):
Soren Hansen6adacc82011-09-09 13:34:35 +020012 super(ImagesTest, self).setUp()
Soren Hansend6b047a2011-09-09 13:39:32 +020013 self.os = openstack.Manager(self.nova)
Soren Hansenbc1d3a02011-09-08 13:33:17 +020014
Soren Hansenbc1d3a02011-09-08 13:33:17 +020015 def _assert_image_links(self, image):
16 image_id = str(image['id'])
17
Soren Hansen5f4ad832011-09-09 14:08:19 +020018 mgmt_url = self.os.nova.management_url
Aaron Lee35b8c922011-10-18 17:07:19 -050019 mgmt_url = re.sub(r'1//', r'1/', mgmt_url) # TODO: is this a bug in Nova?
Soren Hansen5f4ad832011-09-09 14:08:19 +020020 bmk_url = re.sub(r'v1.1\/', r'', mgmt_url)
Aaron Lee35b8c922011-10-18 17:07:19 -050021 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 Hansen5f4ad832011-09-09 14:08:19 +020025
Aaron Lee35b8c922011-10-18 17:07:19 -050026 self.assertIn(bookmark_link, image['links'])
27 self.assertIn(self_link, image['links'])
Soren Hansenbc1d3a02011-09-08 13:33:17 +020028
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 Lee35b8c922011-10-18 17:07:19 -050046 'created',
Soren Hansenbc1d3a02011-09-08 13:33:17 +020047 'id',
Aaron Lee35b8c922011-10-18 17:07:19 -050048 'links',
49 'metadata',
50 'minDisk',
51 'minRam',
Soren Hansenbc1d3a02011-09-08 13:33:17 +020052 'name',
53 'progress',
Soren Hansenbc1d3a02011-09-08 13:33:17 +020054 'status',
Aaron Lee35b8c922011-10-18 17:07:19 -050055 'updated',
Soren Hansenbc1d3a02011-09-08 13:33:17 +020056 ))
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 Hansenfce58c52011-09-09 16:07:13 +020072 test_index.tags = ['nova', 'glance']
Soren Hansenbc1d3a02011-09-08 13:33:17 +020073
74 def test_detail(self):
75 """List all images in detail"""
76
77 response, body = self.os.nova.request('GET', '/images/detail')
Soren Hansenbc1d3a02011-09-08 13:33:17 +020078 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 Hansenfce58c52011-09-09 16:07:13 +020084 test_detail.tags = ['nova', 'glance']