blob: 73b70a9a2a6a91efa7ddc6acd3f20a782d779e38 [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 FlavorsTest(tests.FunctionalTest):
Soren Hansenbc1d3a02011-09-08 13:33:17 +02009 def setUp(self):
Soren Hansen6adacc82011-09-09 13:34:35 +020010 super(FlavorsTest, self).setUp()
Soren Hansend6b047a2011-09-09 13:39:32 +020011 self.os = openstack.Manager(self.nova)
Soren Hansenbc1d3a02011-09-08 13:33:17 +020012
Soren Hansenbc1d3a02011-09-08 13:33:17 +020013 def _index_flavors(self):
14 url = '/flavors'
15 response, body = self.os.nova.request('GET', url)
16 self.assertEqual(response['status'], '200')
17 body_dict = json.loads(body)
18 self.assertEqual(body_dict.keys(), ['flavors'])
19 return body_dict['flavors']
20
21 def _show_flavor(self, flavor_id):
22 url = '/flavors/%s' % flavor_id
23 response, body = self.os.nova.request('GET', url)
24 self.assertEqual(response['status'], '200')
25 body_dict = json.loads(body)
26 self.assertEqual(body_dict.keys(), ['flavor'])
27 return body_dict['flavor']
28
29 def _assert_flavor_entity_basic(self, flavor):
30 actual_keys = set(flavor.keys())
31 expected_keys = set(('id', 'name', 'links'))
32 self.assertEqual(actual_keys, expected_keys)
33 self._assert_flavor_links(flavor)
34
35 def _assert_flavor_entity_detailed(self, flavor):
36 actual_keys = set(flavor.keys())
37 expected_keys = set(('id', 'name', 'ram', 'disk', 'links'))
38 self.assertEqual(actual_keys, expected_keys)
39 self.assertEqual(type(flavor['ram']), int)
40 self.assertEqual(type(flavor['disk']), int)
41 self._assert_flavor_links(flavor)
42
43 def _assert_flavor_links(self, flavor):
44 actual_links = flavor['links']
45
46 flavor_id = str(flavor['id'])
47 host = self.os.config.nova.host
48 port = self.os.config.nova.port
Soren Hansen5f4ad832011-09-09 14:08:19 +020049 mgmt_url = self.os.nova.management_url
50 bmk_url = re.sub(r'v1.1\/', r'', mgmt_url)
Soren Hansenbc1d3a02011-09-08 13:33:17 +020051
Soren Hansen5f4ad832011-09-09 14:08:19 +020052 self_link = os.path.join(mgmt_url, 'flavors', flavor_id)
53 bookmark_link = os.path.join(bmk_url, 'flavors', flavor_id)
Soren Hansenbc1d3a02011-09-08 13:33:17 +020054
55 expected_links = [
56 {
57 'rel': 'self',
58 'href': self_link,
59 },
60 {
61 'rel': 'bookmark',
62 'href': bookmark_link,
63 },
64 ]
65
66 self.assertEqual(actual_links, expected_links)
67
68 def test_show_flavor(self):
69 """Retrieve a single flavor"""
70
71 flavors = self._index_flavors()
72
73 for flavor in flavors:
74 detailed_flavor = self._show_flavor(flavor['id'])
75 self._assert_flavor_entity_detailed(detailed_flavor)
76
77 def test_index_flavors_basic(self):
78 """List all flavors"""
79
80 flavors = self._index_flavors()
81
82 for flavor in flavors:
83 self._assert_flavor_entity_basic(flavor)
84
85 def test_index_flavors_detailed(self):
86 """List all flavors in detail"""
87
88 url = '/flavors/detail'
89 response, body = self.os.nova.request('GET', url)
90 self.assertEqual(response['status'], '200')
91 body_dict = json.loads(body)
92 self.assertEqual(body_dict.keys(), ['flavors'])
93 flavors = body_dict['flavors']
94
95 for flavor in flavors:
96 self._assert_flavor_entity_detailed(flavor)