~ubuntu-branches/ubuntu/saucy/glance/saucy-proposed

« back to all changes in this revision

Viewing changes to glance/tests/integration/legacy_functional/base.py

  • Committer: Package Import Robot
  • Author(s): James Page, Yolanda Robla, James Page
  • Date: 2013-07-19 16:05:21 UTC
  • mfrom: (1.1.53)
  • Revision ID: package-import@ubuntu.com-20130719160521-p9d6xeostzl7ewbo
Tags: 1:2013.2~b2-0ubuntu1
[ Yolanda Robla ]
* debian/tests: added autopkgtests

[ James Page ]
* New upstream release.
* d/control: Update VCS fields for new branch locations.
* d/control: Drop BD on pep8, not required.
* d/control: Add missing BD's on python-greenlet and python-cinderclient.
* d/control: Bumped Standards-Version 3.9.4:
  - d/copyright: Use released version of DEP-5, tidy fields for new
    names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
2
#    not use this file except in compliance with the License. You may obtain
 
3
#    a copy of the License at
 
4
#
 
5
#         http://www.apache.org/licenses/LICENSE-2.0
 
6
#
 
7
#    Unless required by applicable law or agreed to in writing, software
 
8
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
9
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
10
#    License for the specific language governing permissions and limitations
 
11
#    under the License.
 
12
 
 
13
import atexit
 
14
import os.path
 
15
import tempfile
 
16
 
 
17
import fixtures
 
18
from oslo.config import cfg
 
19
 
 
20
from glance import tests as glance_tests
 
21
import glance.common.client
 
22
from glance.common import config
 
23
import glance.db.sqlalchemy.api
 
24
import glance.db.sqlalchemy.migration
 
25
import glance.registry.client.v1.client
 
26
import glance.store
 
27
from glance.tests import utils as test_utils
 
28
 
 
29
 
 
30
TESTING_API_PASTE_CONF = """
 
31
[pipeline:glance-api]
 
32
pipeline = versionnegotiation gzip unauthenticated-context rootapp
 
33
 
 
34
[pipeline:glance-api-caching]
 
35
pipeline = versionnegotiation gzip unauthenticated-context cache rootapp
 
36
 
 
37
[pipeline:glance-api-cachemanagement]
 
38
pipeline =
 
39
    versionnegotiation
 
40
    gzip
 
41
    unauthenticated-context
 
42
    cache
 
43
    cache_manage
 
44
    rootapp
 
45
 
 
46
[pipeline:glance-api-fakeauth]
 
47
pipeline = versionnegotiation gzip fakeauth context rootapp
 
48
 
 
49
[pipeline:glance-api-noauth]
 
50
pipeline = versionnegotiation gzip context rootapp
 
51
 
 
52
[composite:rootapp]
 
53
paste.composite_factory = glance.api:root_app_factory
 
54
/: apiversions
 
55
/v1: apiv1app
 
56
/v2: apiv2app
 
57
 
 
58
[app:apiversions]
 
59
paste.app_factory = glance.api.versions:create_resource
 
60
 
 
61
[app:apiv1app]
 
62
paste.app_factory = glance.api.v1.router:API.factory
 
63
 
 
64
[app:apiv2app]
 
65
paste.app_factory = glance.api.v2.router:API.factory
 
66
 
 
67
[filter:versionnegotiation]
 
68
paste.filter_factory =
 
69
 glance.api.middleware.version_negotiation:VersionNegotiationFilter.factory
 
70
 
 
71
[filter:gzip]
 
72
paste.filter_factory = glance.api.middleware.gzip:GzipMiddleware.factory
 
73
 
 
74
[filter:cache]
 
75
paste.filter_factory = glance.api.middleware.cache:CacheFilter.factory
 
76
 
 
77
[filter:cache_manage]
 
78
paste.filter_factory =
 
79
 glance.api.middleware.cache_manage:CacheManageFilter.factory
 
80
 
 
81
[filter:context]
 
82
paste.filter_factory = glance.api.middleware.context:ContextMiddleware.factory
 
83
 
 
84
[filter:unauthenticated-context]
 
85
paste.filter_factory =
 
86
 glance.api.middleware.context:UnauthenticatedContextMiddleware.factory
 
87
 
 
88
[filter:fakeauth]
 
89
paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
 
90
"""
 
91
 
 
92
TESTING_REGISTRY_PASTE_CONF = """
 
93
[pipeline:glance-registry]
 
94
pipeline = unauthenticated-context registryapp
 
95
 
 
96
[pipeline:glance-registry-fakeauth]
 
97
pipeline = fakeauth context registryapp
 
98
 
 
99
[app:registryapp]
 
100
paste.app_factory = glance.registry.api.v1:API.factory
 
101
 
 
102
[filter:context]
 
103
paste.filter_factory = glance.api.middleware.context:ContextMiddleware.factory
 
104
 
 
105
[filter:unauthenticated-context]
 
106
paste.filter_factory =
 
107
 glance.api.middleware.context:UnauthenticatedContextMiddleware.factory
 
108
 
 
109
[filter:fakeauth]
 
110
paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
 
111
"""
 
112
 
 
113
CONF = cfg.CONF
 
114
CONF.import_opt('filesystem_store_datadir', 'glance.store.filesystem')
 
115
 
 
116
 
 
117
class ApiTest(test_utils.BaseTestCase):
 
118
    def setUp(self):
 
119
        super(ApiTest, self).setUp()
 
120
        self.test_dir = self.useFixture(fixtures.TempDir()).path
 
121
        self._configure_logging()
 
122
        self._setup_database()
 
123
        self._setup_stores()
 
124
        self.glance_registry_app = self._load_paste_app(
 
125
            'glance-registry',
 
126
            flavor=getattr(self, 'registry_flavor', ''),
 
127
            conf=getattr(self, 'registry_paste_conf',
 
128
                         TESTING_REGISTRY_PASTE_CONF),
 
129
        )
 
130
        self._connect_registry_client()
 
131
        self.glance_api_app = self._load_paste_app(
 
132
            'glance-api',
 
133
            flavor=getattr(self, 'api_flavor', ''),
 
134
            conf=getattr(self, 'api_paste_conf', TESTING_API_PASTE_CONF),
 
135
        )
 
136
        self.http = test_utils.Httplib2WsgiAdapter(self.glance_api_app)
 
137
 
 
138
    def _configure_logging(self):
 
139
        self.config(default_log_levels=[
 
140
                'amqplib=WARN',
 
141
                'sqlalchemy=WARN',
 
142
                'boto=WARN',
 
143
                'suds=INFO',
 
144
                'keystone=INFO',
 
145
                'eventlet.wsgi.server=DEBUG'
 
146
        ])
 
147
 
 
148
    def _setup_database(self):
 
149
        sql_connection = 'sqlite:////%s/tests.sqlite' % self.test_dir
 
150
        self.config(sql_connection=sql_connection)
 
151
        glance.db.sqlalchemy.api.clear_db_env()
 
152
        glance_db_env = 'GLANCE_DB_TEST_SQLITE_FILE'
 
153
        if glance_db_env in os.environ:
 
154
            # use the empty db created and cached as a tempfile
 
155
            # instead of spending the time creating a new one
 
156
            db_location = os.environ[glance_db_env]
 
157
            test_utils.execute('cp %s %s/tests.sqlite'
 
158
                               % (db_location, self.test_dir))
 
159
        else:
 
160
            glance.db.sqlalchemy.migration.db_sync()
 
161
 
 
162
            # copy the clean db to a temp location so that it
 
163
            # can be reused for future tests
 
164
            (osf, db_location) = tempfile.mkstemp()
 
165
            os.close(osf)
 
166
            test_utils.execute('cp %s/tests.sqlite %s'
 
167
                               % (self.test_dir, db_location))
 
168
            os.environ[glance_db_env] = db_location
 
169
 
 
170
            # cleanup the temp file when the test suite is
 
171
            # complete
 
172
            def _delete_cached_db():
 
173
                try:
 
174
                    os.remove(os.environ[glance_db_env])
 
175
                except Exception:
 
176
                    glance_tests.logger.exception(
 
177
                        "Error cleaning up the file %s" %
 
178
                        os.environ[glance_db_env])
 
179
            atexit.register(_delete_cached_db)
 
180
 
 
181
    def _setup_stores(self):
 
182
        image_dir = os.path.join(self.test_dir, "images")
 
183
        self.config(filesystem_store_datadir=image_dir)
 
184
        glance.store.create_stores()
 
185
 
 
186
    def _load_paste_app(self, name, flavor, conf):
 
187
        conf_file_path = os.path.join(self.test_dir, '%s-paste.ini' % name)
 
188
        with open(conf_file_path, 'wb') as conf_file:
 
189
            conf_file.write(conf)
 
190
            conf_file.flush()
 
191
        return config.load_paste_app(name, flavor=flavor,
 
192
                                     conf_file=conf_file_path)
 
193
 
 
194
    def _connect_registry_client(self):
 
195
        def get_connection_type(self2):
 
196
            def wrapped(*args, **kwargs):
 
197
                return test_utils.HttplibWsgiAdapter(self.glance_registry_app)
 
198
            return wrapped
 
199
 
 
200
        self.stubs.Set(glance.common.client.BaseClient,
 
201
                       'get_connection_type', get_connection_type)
 
202
 
 
203
    def tearDown(self):
 
204
        glance.db.sqlalchemy.api.clear_db_env()
 
205
        super(ApiTest, self).tearDown()