~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to .pc/CVE-2012-2101.patch/nova/tests/api/openstack/compute/contrib/test_quotas.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
 
 
3
 
# Copyright 2011 OpenStack LLC.
4
 
# All Rights Reserved.
5
 
#
6
 
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
7
 
#    not use this file except in compliance with the License. You may obtain
8
 
#    a copy of the License at
9
 
#
10
 
#         http://www.apache.org/licenses/LICENSE-2.0
11
 
#
12
 
#    Unless required by applicable law or agreed to in writing, software
13
 
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
 
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
 
#    License for the specific language governing permissions and limitations
16
 
#    under the License.
17
 
 
18
 
import webob
19
 
from lxml import etree
20
 
 
21
 
from nova.api.openstack import wsgi
22
 
from nova.api.openstack.compute.contrib import quotas
23
 
from nova import test
24
 
from nova.tests.api.openstack import fakes
25
 
 
26
 
 
27
 
def quota_set(id):
28
 
    return {'quota_set': {'id': id, 'metadata_items': 128, 'volumes': 10,
29
 
            'gigabytes': 1000, 'ram': 51200, 'floating_ips': 10,
30
 
            'instances': 10, 'injected_files': 5, 'cores': 20,
31
 
            'injected_file_content_bytes': 10240}}
32
 
 
33
 
 
34
 
def quota_set_list():
35
 
    return {'quota_set_list': [quota_set('1234'), quota_set('5678'),
36
 
                               quota_set('update_me')]}
37
 
 
38
 
 
39
 
class QuotaSetsTest(test.TestCase):
40
 
 
41
 
    def setUp(self):
42
 
        super(QuotaSetsTest, self).setUp()
43
 
        self.controller = quotas.QuotaSetsController()
44
 
 
45
 
    def test_format_quota_set(self):
46
 
        raw_quota_set = {
47
 
            'instances': 10,
48
 
            'cores': 20,
49
 
            'ram': 51200,
50
 
            'volumes': 10,
51
 
            'floating_ips': 10,
52
 
            'metadata_items': 128,
53
 
            'gigabytes': 1000,
54
 
            'injected_files': 5,
55
 
            'injected_file_content_bytes': 10240}
56
 
 
57
 
        quota_set = quotas.QuotaSetsController()._format_quota_set('1234',
58
 
                                                            raw_quota_set)
59
 
        qs = quota_set['quota_set']
60
 
 
61
 
        self.assertEqual(qs['id'], '1234')
62
 
        self.assertEqual(qs['instances'], 10)
63
 
        self.assertEqual(qs['cores'], 20)
64
 
        self.assertEqual(qs['ram'], 51200)
65
 
        self.assertEqual(qs['volumes'], 10)
66
 
        self.assertEqual(qs['gigabytes'], 1000)
67
 
        self.assertEqual(qs['floating_ips'], 10)
68
 
        self.assertEqual(qs['metadata_items'], 128)
69
 
        self.assertEqual(qs['injected_files'], 5)
70
 
        self.assertEqual(qs['injected_file_content_bytes'], 10240)
71
 
 
72
 
    def test_quotas_defaults(self):
73
 
        uri = '/v2/fake_tenant/os-quota-sets/fake_tenant/defaults'
74
 
 
75
 
        req = fakes.HTTPRequest.blank(uri)
76
 
        res_dict = self.controller.defaults(req, 'fake_tenant')
77
 
 
78
 
        expected = {'quota_set': {
79
 
                    'id': 'fake_tenant',
80
 
                    'instances': 10,
81
 
                    'cores': 20,
82
 
                    'ram': 51200,
83
 
                    'volumes': 10,
84
 
                    'gigabytes': 1000,
85
 
                    'floating_ips': 10,
86
 
                    'metadata_items': 128,
87
 
                    'injected_files': 5,
88
 
                    'injected_file_content_bytes': 10240}}
89
 
 
90
 
        self.assertEqual(res_dict, expected)
91
 
 
92
 
    def test_quotas_show_as_admin(self):
93
 
        req = fakes.HTTPRequest.blank('/v2/fake4/os-quota-sets/1234',
94
 
                                      use_admin_context=True)
95
 
        res_dict = self.controller.show(req, 1234)
96
 
 
97
 
        self.assertEqual(res_dict, quota_set('1234'))
98
 
 
99
 
    def test_quotas_show_as_unauthorized_user(self):
100
 
        req = fakes.HTTPRequest.blank('/v2/fake4/os-quota-sets/1234')
101
 
        self.assertRaises(webob.exc.HTTPForbidden, self.controller.show,
102
 
                          req, 1234)
103
 
 
104
 
    def test_quotas_update_as_admin(self):
105
 
        body = {'quota_set': {'instances': 50, 'cores': 50,
106
 
                              'ram': 51200, 'volumes': 10,
107
 
                              'gigabytes': 1000, 'floating_ips': 10,
108
 
                              'metadata_items': 128, 'injected_files': 5,
109
 
                              'injected_file_content_bytes': 10240}}
110
 
 
111
 
        req = fakes.HTTPRequest.blank('/v2/fake4/os-quota-sets/update_me',
112
 
                                      use_admin_context=True)
113
 
        res_dict = self.controller.update(req, 'update_me', body)
114
 
 
115
 
        self.assertEqual(res_dict, body)
116
 
 
117
 
    def test_quotas_update_as_user(self):
118
 
        body = {'quota_set': {'instances': 50, 'cores': 50,
119
 
                              'ram': 51200, 'volumes': 10,
120
 
                              'gigabytes': 1000, 'floating_ips': 10,
121
 
                              'metadata_items': 128, 'injected_files': 5,
122
 
                              'injected_file_content_bytes': 10240}}
123
 
 
124
 
        req = fakes.HTTPRequest.blank('/v2/fake4/os-quota-sets/update_me')
125
 
        self.assertRaises(webob.exc.HTTPForbidden, self.controller.update,
126
 
                          req, 'update_me', body)
127
 
 
128
 
 
129
 
class QuotaXMLSerializerTest(test.TestCase):
130
 
    def setUp(self):
131
 
        super(QuotaXMLSerializerTest, self).setUp()
132
 
        self.serializer = quotas.QuotaTemplate()
133
 
        self.deserializer = wsgi.XMLDeserializer()
134
 
 
135
 
    def test_serializer(self):
136
 
        exemplar = dict(quota_set=dict(
137
 
                id='project_id',
138
 
                metadata_items=10,
139
 
                injected_file_content_bytes=20,
140
 
                volumes=30,
141
 
                gigabytes=40,
142
 
                ram=50,
143
 
                floating_ips=60,
144
 
                instances=70,
145
 
                injected_files=80,
146
 
                cores=90))
147
 
        text = self.serializer.serialize(exemplar)
148
 
 
149
 
        print text
150
 
        tree = etree.fromstring(text)
151
 
 
152
 
        self.assertEqual('quota_set', tree.tag)
153
 
        self.assertEqual('project_id', tree.get('id'))
154
 
        self.assertEqual(len(exemplar['quota_set']) - 1, len(tree))
155
 
        for child in tree:
156
 
            self.assertTrue(child.tag in exemplar['quota_set'])
157
 
            self.assertEqual(int(child.text), exemplar['quota_set'][child.tag])
158
 
 
159
 
    def test_deserializer(self):
160
 
        exemplar = dict(quota_set=dict(
161
 
                metadata_items='10',
162
 
                injected_file_content_bytes='20',
163
 
                volumes='30',
164
 
                gigabytes='40',
165
 
                ram='50',
166
 
                floating_ips='60',
167
 
                instances='70',
168
 
                injected_files='80',
169
 
                cores='90'))
170
 
        intext = ("<?xml version='1.0' encoding='UTF-8'?>\n"
171
 
                  '<quota_set>'
172
 
                  '<metadata_items>10</metadata_items>'
173
 
                  '<injected_file_content_bytes>20'
174
 
                  '</injected_file_content_bytes>'
175
 
                  '<volumes>30</volumes>'
176
 
                  '<gigabytes>40</gigabytes>'
177
 
                  '<ram>50</ram>'
178
 
                  '<floating_ips>60</floating_ips>'
179
 
                  '<instances>70</instances>'
180
 
                  '<injected_files>80</injected_files>'
181
 
                  '<cores>90</cores>'
182
 
                  '</quota_set>')
183
 
 
184
 
        result = self.deserializer.deserialize(intext)['body']
185
 
        self.assertEqual(result, exemplar)