blob: 7d2c9cee845a3a9cac8086da8243d1be11206d5b [file] [log] [blame]
Soren Hansenbc1d3a02011-09-08 13:33:17 +02001import json
2import os
3
Soren Hansenbc1d3a02011-09-08 13:33:17 +02004from kong import openstack
Soren Hansen6adacc82011-09-09 13:34:35 +02005from kong import tests
Soren Hansenbc1d3a02011-09-08 13:33:17 +02006
7
Soren Hansen6adacc82011-09-09 13:34:35 +02008class ImagesTest(tests.FunctionalTest):
Soren Hansenbc1d3a02011-09-08 13:33:17 +02009
10 def setUp(self):
Soren Hansen6adacc82011-09-09 13:34:35 +020011 super(ImagesTest, self).setUp()
Soren Hansend6b047a2011-09-09 13:39:32 +020012 self.os = openstack.Manager(self.nova)
Soren Hansenbc1d3a02011-09-08 13:33:17 +020013
Soren Hansenbc1d3a02011-09-08 13:33:17 +020014 def _assert_image_links(self, image):
15 image_id = str(image['id'])
16
Soren Hansen5f4ad832011-09-09 14:08:19 +020017 mgmt_url = self.os.nova.management_url
18 bmk_url = re.sub(r'v1.1\/', r'', mgmt_url)
19
20 self_link = os.path.join(mgmt_url, 'images', image_id)
21 bookmark_link = os.path.join(bmk_url, 'images', image_id)
Soren Hansenbc1d3a02011-09-08 13:33:17 +020022
23 expected_links = [
24 {
25 'rel': 'self',
26 'href': self_link,
27 },
28 {
29 'rel': 'bookmark',
30 'href': bookmark_link,
31 },
32 ]
33
34 self.assertEqual(image['links'], expected_links)
35
36 def _assert_image_entity_basic(self, image):
37 actual_keys = set(image.keys())
38 expected_keys = set((
39 'id',
40 'name',
41 'links',
42 ))
43 self.assertEqual(actual_keys, expected_keys)
44
45 self._assert_image_links(image)
46
47 def _assert_image_entity_detailed(self, image):
48 keys = image.keys()
49 if 'server' in keys:
50 keys.remove('server')
51 actual_keys = set(keys)
52 expected_keys = set((
53 'id',
54 'name',
55 'progress',
56 'created',
57 'updated',
58 'status',
59 'metadata',
60 'links',
61 ))
62 self.assertEqual(actual_keys, expected_keys)
63
64 self._assert_image_links(image)
65
66 def test_index(self):
67 """List all images"""
68
69 response, body = self.os.nova.request('GET', '/images')
70
71 self.assertEqual(response['status'], '200')
72 resp_body = json.loads(body)
73 self.assertEqual(resp_body.keys(), ['images'])
74
75 for image in resp_body['images']:
76 self._assert_image_entity_basic(image)
77
78 def test_detail(self):
79 """List all images in detail"""
80
81 response, body = self.os.nova.request('GET', '/images/detail')
82
83 self.assertEqual(response['status'], '200')
84 resp_body = json.loads(body)
85 self.assertEqual(resp_body.keys(), ['images'])
86
87 for image in resp_body['images']:
88 self._assert_image_entity_detailed(image)