~zulcss/cinder/cinder-ca-g2

« back to all changes in this revision

Viewing changes to cinder/tests/api/openstack/volume/test_extensions.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-10-09 08:26:21 UTC
  • mfrom: (3.1.10 quantal)
  • Revision ID: package-import@ubuntu.com-20121009082621-stc86vcuyzyrp7ow
Tags: 2012.2-0ubuntu2
* debian/cinder_tgt.conf: Add missing configuration file. (LP: #1064366) 
* debian/README.Debian: Added note about migration from nova-volume
  to cinder-volume.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
 
4
# Copyright 2011 OpenStack LLC.
 
5
# All Rights Reserved.
 
6
#
 
7
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
8
#    not use this file except in compliance with the License. You may obtain
 
9
#    a copy of the License at
 
10
#
 
11
#         http://www.apache.org/licenses/LICENSE-2.0
 
12
#
 
13
#    Unless required by applicable law or agreed to in writing, software
 
14
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
15
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
16
#    License for the specific language governing permissions and limitations
 
17
#    under the License.
 
18
 
 
19
 
 
20
import webob
 
21
from lxml import etree
 
22
import iso8601
 
23
 
 
24
from cinder.api.openstack import volume
 
25
from cinder.api.openstack import xmlutil
 
26
from cinder import flags
 
27
from cinder.openstack.common import jsonutils
 
28
from cinder import test
 
29
 
 
30
FLAGS = flags.FLAGS
 
31
NS = "{http://docs.openstack.org/common/api/v1.0}"
 
32
 
 
33
 
 
34
class ExtensionTestCase(test.TestCase):
 
35
    def setUp(self):
 
36
        super(ExtensionTestCase, self).setUp()
 
37
        ext_list = FLAGS.osapi_volume_extension[:]
 
38
        fox = ('cinder.tests.api.openstack.volume.extensions.'
 
39
               'foxinsocks.Foxinsocks')
 
40
        if fox not in ext_list:
 
41
            ext_list.append(fox)
 
42
            self.flags(osapi_volume_extension=ext_list)
 
43
 
 
44
 
 
45
class ExtensionControllerTest(ExtensionTestCase):
 
46
 
 
47
    def setUp(self):
 
48
        super(ExtensionControllerTest, self).setUp()
 
49
        self.ext_list = [
 
50
            "TypesManage",
 
51
            "TypesExtraSpecs",
 
52
            ]
 
53
        self.ext_list.sort()
 
54
 
 
55
    def test_list_extensions_json(self):
 
56
        app = volume.APIRouter()
 
57
        request = webob.Request.blank("/fake/extensions")
 
58
        response = request.get_response(app)
 
59
        self.assertEqual(200, response.status_int)
 
60
 
 
61
        # Make sure we have all the extensions, extra extensions being OK.
 
62
        data = jsonutils.loads(response.body)
 
63
        names = [str(x['name']) for x in data['extensions']
 
64
                 if str(x['name']) in self.ext_list]
 
65
        names.sort()
 
66
        self.assertEqual(names, self.ext_list)
 
67
 
 
68
        # Ensure all the timestamps are valid according to iso8601
 
69
        for ext in data['extensions']:
 
70
            iso8601.parse_date(ext['updated'])
 
71
 
 
72
        # Make sure that at least Fox in Sox is correct.
 
73
        (fox_ext, ) = [
 
74
            x for x in data['extensions'] if x['alias'] == 'FOXNSOX']
 
75
        self.assertEqual(fox_ext, {
 
76
                'namespace': 'http://www.fox.in.socks/api/ext/pie/v1.0',
 
77
                'name': 'Fox In Socks',
 
78
                'updated': '2011-01-22T13:25:27-06:00',
 
79
                'description': 'The Fox In Socks Extension',
 
80
                'alias': 'FOXNSOX',
 
81
                'links': []
 
82
            },
 
83
        )
 
84
 
 
85
        for ext in data['extensions']:
 
86
            url = '/fake/extensions/%s' % ext['alias']
 
87
            request = webob.Request.blank(url)
 
88
            response = request.get_response(app)
 
89
            output = jsonutils.loads(response.body)
 
90
            self.assertEqual(output['extension']['alias'], ext['alias'])
 
91
 
 
92
    def test_get_extension_json(self):
 
93
        app = volume.APIRouter()
 
94
        request = webob.Request.blank("/fake/extensions/FOXNSOX")
 
95
        response = request.get_response(app)
 
96
        self.assertEqual(200, response.status_int)
 
97
 
 
98
        data = jsonutils.loads(response.body)
 
99
        self.assertEqual(data['extension'], {
 
100
                "namespace": "http://www.fox.in.socks/api/ext/pie/v1.0",
 
101
                "name": "Fox In Socks",
 
102
                "updated": "2011-01-22T13:25:27-06:00",
 
103
                "description": "The Fox In Socks Extension",
 
104
                "alias": "FOXNSOX",
 
105
                "links": []})
 
106
 
 
107
    def test_get_non_existing_extension_json(self):
 
108
        app = volume.APIRouter()
 
109
        request = webob.Request.blank("/fake/extensions/4")
 
110
        response = request.get_response(app)
 
111
        self.assertEqual(404, response.status_int)
 
112
 
 
113
    def test_list_extensions_xml(self):
 
114
        app = volume.APIRouter()
 
115
        request = webob.Request.blank("/fake/extensions")
 
116
        request.accept = "application/xml"
 
117
        response = request.get_response(app)
 
118
        self.assertEqual(200, response.status_int)
 
119
 
 
120
        root = etree.XML(response.body)
 
121
        self.assertEqual(root.tag.split('extensions')[0], NS)
 
122
 
 
123
        # Make sure we have all the extensions, extras extensions being OK.
 
124
        exts = root.findall('{0}extension'.format(NS))
 
125
        self.assert_(len(exts) >= len(self.ext_list))
 
126
 
 
127
        # Make sure that at least Fox in Sox is correct.
 
128
        (fox_ext, ) = [x for x in exts if x.get('alias') == 'FOXNSOX']
 
129
        self.assertEqual(fox_ext.get('name'), 'Fox In Socks')
 
130
        self.assertEqual(fox_ext.get('namespace'),
 
131
            'http://www.fox.in.socks/api/ext/pie/v1.0')
 
132
        self.assertEqual(fox_ext.get('updated'), '2011-01-22T13:25:27-06:00')
 
133
        self.assertEqual(fox_ext.findtext('{0}description'.format(NS)),
 
134
            'The Fox In Socks Extension')
 
135
 
 
136
        xmlutil.validate_schema(root, 'extensions')
 
137
 
 
138
    def test_get_extension_xml(self):
 
139
        app = volume.APIRouter()
 
140
        request = webob.Request.blank("/fake/extensions/FOXNSOX")
 
141
        request.accept = "application/xml"
 
142
        response = request.get_response(app)
 
143
        self.assertEqual(200, response.status_int)
 
144
        xml = response.body
 
145
 
 
146
        root = etree.XML(xml)
 
147
        self.assertEqual(root.tag.split('extension')[0], NS)
 
148
        self.assertEqual(root.get('alias'), 'FOXNSOX')
 
149
        self.assertEqual(root.get('name'), 'Fox In Socks')
 
150
        self.assertEqual(root.get('namespace'),
 
151
            'http://www.fox.in.socks/api/ext/pie/v1.0')
 
152
        self.assertEqual(root.get('updated'), '2011-01-22T13:25:27-06:00')
 
153
        self.assertEqual(root.findtext('{0}description'.format(NS)),
 
154
            'The Fox In Socks Extension')
 
155
 
 
156
        xmlutil.validate_schema(root, 'extension')