blob: 055447ea406821efad786a8ff53fbcf73e10b629 [file] [log] [blame]
Soren Hansenbc1d3a02011-09-08 13:33:17 +02001import json
2import os
Soren Hansena86180a2011-09-09 16:22:26 +02003import 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 FlavorsTest(tests.FunctionalTest):
Soren Hansenbc1d3a02011-09-08 13:33:17 +020010 def setUp(self):
Soren Hansen6adacc82011-09-09 13:34:35 +020011 super(FlavorsTest, 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 _index_flavors(self):
15 url = '/flavors'
16 response, body = self.os.nova.request('GET', url)
17 self.assertEqual(response['status'], '200')
18 body_dict = json.loads(body)
19 self.assertEqual(body_dict.keys(), ['flavors'])
20 return body_dict['flavors']
21
22 def _show_flavor(self, flavor_id):
23 url = '/flavors/%s' % flavor_id
24 response, body = self.os.nova.request('GET', url)
25 self.assertEqual(response['status'], '200')
26 body_dict = json.loads(body)
27 self.assertEqual(body_dict.keys(), ['flavor'])
28 return body_dict['flavor']
29
30 def _assert_flavor_entity_basic(self, flavor):
31 actual_keys = set(flavor.keys())
32 expected_keys = set(('id', 'name', 'links'))
33 self.assertEqual(actual_keys, expected_keys)
34 self._assert_flavor_links(flavor)
35
36 def _assert_flavor_entity_detailed(self, flavor):
37 actual_keys = set(flavor.keys())
38 expected_keys = set(('id', 'name', 'ram', 'disk', 'links'))
39 self.assertEqual(actual_keys, expected_keys)
40 self.assertEqual(type(flavor['ram']), int)
41 self.assertEqual(type(flavor['disk']), int)
42 self._assert_flavor_links(flavor)
43
44 def _assert_flavor_links(self, flavor):
45 actual_links = flavor['links']
46
47 flavor_id = str(flavor['id'])
Soren Hansen5f4ad832011-09-09 14:08:19 +020048 mgmt_url = self.os.nova.management_url
49 bmk_url = re.sub(r'v1.1\/', r'', mgmt_url)
Soren Hansenbc1d3a02011-09-08 13:33:17 +020050
Soren Hansen5f4ad832011-09-09 14:08:19 +020051 self_link = os.path.join(mgmt_url, 'flavors', flavor_id)
52 bookmark_link = os.path.join(bmk_url, 'flavors', flavor_id)
Soren Hansenbc1d3a02011-09-08 13:33:17 +020053
54 expected_links = [
55 {
56 'rel': 'self',
57 'href': self_link,
58 },
59 {
60 'rel': 'bookmark',
61 'href': bookmark_link,
62 },
63 ]
64
65 self.assertEqual(actual_links, expected_links)
66
67 def test_show_flavor(self):
68 """Retrieve a single flavor"""
69
70 flavors = self._index_flavors()
71
72 for flavor in flavors:
73 detailed_flavor = self._show_flavor(flavor['id'])
74 self._assert_flavor_entity_detailed(detailed_flavor)
Soren Hansenfce58c52011-09-09 16:07:13 +020075 test_show_flavor.tags = ['nova', 'glance']
Soren Hansenbc1d3a02011-09-08 13:33:17 +020076
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)
Soren Hansenfce58c52011-09-09 16:07:13 +020084 test_index_flavors_basic.tags = ['nova', 'glance']
Soren Hansenbc1d3a02011-09-08 13:33:17 +020085
86 def test_index_flavors_detailed(self):
87 """List all flavors in detail"""
88
89 url = '/flavors/detail'
90 response, body = self.os.nova.request('GET', url)
91 self.assertEqual(response['status'], '200')
92 body_dict = json.loads(body)
93 self.assertEqual(body_dict.keys(), ['flavors'])
94 flavors = body_dict['flavors']
95
96 for flavor in flavors:
97 self._assert_flavor_entity_detailed(flavor)
Soren Hansenfce58c52011-09-09 16:07:13 +020098 test_index_flavors_detailed.tags = ['nova', 'glance']