/usr/share/pyshared/glance/tests/unit/test_config.py is in python-glance 2012.1.3+stable~20120821-120fcf-0ubuntu1.5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | # vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2011 OpenStack, LLC
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os.path
import shutil
import unittest
import stubout
from glance.common import config
from glance.common import context
from glance.image_cache import pruner
from glance.tests import utils as test_utils
class TestPasteApp(unittest.TestCase):
def setUp(self):
self.stubs = stubout.StubOutForTesting()
def tearDown(self):
self.stubs.UnsetAll()
def _do_test_load_paste_app(self,
expected_app_type,
paste_group={},
paste_copy=True,
paste_append=None):
conf = test_utils.TestConfigOpts(groups=paste_group,
clean=False)
def _appendto(orig, copy, str):
shutil.copy(orig, copy)
with open(copy, 'ab') as f:
f.write(str or '')
f.flush()
paste_to = os.path.join(conf.temp_file.replace('.conf',
'-paste.ini'))
if paste_copy:
paste_from = os.path.join(os.getcwd(),
'etc/glance-registry-paste.ini')
_appendto(paste_from, paste_to, paste_append)
app = config.load_paste_app(conf, 'glance-registry')
self.assertEquals(expected_app_type, type(app))
if paste_copy:
os.remove(conf.temp_file)
os.remove(paste_to)
os.rmdir(os.path.dirname(conf.temp_file))
def test_load_paste_app(self):
expected_middleware = context.ContextMiddleware
self._do_test_load_paste_app(expected_middleware)
def test_load_paste_app_with_paste_flavor(self):
paste_group = {'paste_deploy': {'flavor': 'incomplete'}}
pipeline = '[pipeline:glance-registry-incomplete]\n' + \
'pipeline = context registryapp'
type = context.ContextMiddleware
self._do_test_load_paste_app(type, paste_group, paste_append=pipeline)
def test_load_paste_app_with_paste_config_file(self):
paste_config_file = os.path.join(os.getcwd(),
'etc/glance-registry-paste.ini')
paste_group = {'paste_deploy': {'config_file': paste_config_file}}
expected_middleware = context.ContextMiddleware
self._do_test_load_paste_app(expected_middleware,
paste_group, paste_copy=False)
def test_load_paste_app_with_conf_name(self):
def fake_join(*args):
if len(args) == 2 and \
args[0].endswith('.glance') and \
args[1] == 'glance-cache.conf':
return os.path.join(os.getcwd(), 'etc', args[1])
else:
return orig_join(*args)
orig_join = os.path.join
self.stubs.Set(os.path, 'join', fake_join)
conf = config.GlanceCacheConfigOpts()
conf([])
self.stubs.Set(config, 'setup_logging', lambda *a: None)
self.stubs.Set(pruner, 'Pruner', lambda conf, **lc: 'pruner')
app = config.load_paste_app(conf, 'glance-pruner')
self.assertEquals('pruner', app)
|