23
24
from glance.api.middleware import version_negotiation
24
25
from glance.api.v1 import images
25
26
from glance.api.v1 import members
26
from glance.common import config
27
from glance.common import config, context, utils
27
28
from glance.image_cache import pruner
29
from glance.tests import utils as test_utils
30
32
class TestPasteApp(unittest.TestCase):
35
37
def tearDown(self):
36
38
self.stubs.UnsetAll()
40
def _do_test_load_paste_app(self,
46
conf = test_utils.TestConfigOpts(groups=paste_group)
48
def _appendto(orig, copy, str):
49
shutil.copy(orig, copy)
50
with open(copy, 'ab') as f:
55
paste_from = os.path.join(os.getcwd(), 'etc/glance-api-paste.ini')
56
paste_to = os.path.join(conf.temp_file.replace('.conf',
58
_appendto(paste_from, paste_to, paste_append)
60
app = config.load_paste_app(conf, 'glance-api')
62
self.assertEquals(expected_app_type, type(app))
38
64
def test_load_paste_app(self):
39
conf = config.GlanceConfigOpts()
40
conf(['--config-file',
41
os.path.join(os.getcwd(), 'etc/glance-api.conf')])
43
self.stubs.Set(config, 'setup_logging', lambda *a: None)
44
self.stubs.Set(images, 'create_resource', lambda *a: None)
45
self.stubs.Set(members, 'create_resource', lambda *a: None)
47
app = config.load_paste_app(conf, 'glance-api')
49
self.assertEquals(version_negotiation.VersionNegotiationFilter,
65
type = version_negotiation.VersionNegotiationFilter
66
self._do_test_load_paste_app(type)
68
def test_load_paste_app_with_paste_flavor(self):
69
paste_group = {'paste_deploy': {'flavor': 'incomplete'}}
70
pipeline = '[pipeline:glance-api-incomplete]\n' + \
71
'pipeline = context apiv1app'
73
type = context.ContextMiddleware
74
self._do_test_load_paste_app(type, paste_group, paste_append=pipeline)
76
def test_load_paste_app_with_paste_config_file(self):
77
paste_config_file = os.path.join(os.getcwd(),
78
'etc/glance-api-paste.ini')
79
paste_group = {'paste_deploy': {'config_file': paste_config_file}}
81
type = version_negotiation.VersionNegotiationFilter
82
self._do_test_load_paste_app(type, paste_group, paste_copy=False)
52
84
def test_load_paste_app_with_conf_name(self):
53
85
def fake_join(*args):