~ubuntu-branches/ubuntu/precise/glance/precise-proposed

« back to all changes in this revision

Viewing changes to glance/tests/unit/test_config.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandleman
  • Date: 2012-01-20 14:37:16 UTC
  • mfrom: (1.1.24)
  • Revision ID: package-import@ubuntu.com-20120120143716-2va2h1g2230m51zx
Tags: 2012.1~e3~20120120.1206-0ubuntu1
[Chuck Short]
* New upstream release.

[Adam Gandleman]
* debian/glance-api.install, glance-registry.install:  Install
  new paste configs that have been split among servers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#    under the License.
17
17
 
18
18
import os.path
 
19
import shutil
19
20
import unittest
20
21
 
21
22
import stubout
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
28
30
 
29
31
 
30
32
class TestPasteApp(unittest.TestCase):
35
37
    def tearDown(self):
36
38
        self.stubs.UnsetAll()
37
39
 
 
40
    def _do_test_load_paste_app(self,
 
41
                                expected_app_type,
 
42
                                paste_group={},
 
43
                                paste_copy=True,
 
44
                                paste_append=None):
 
45
 
 
46
        conf = test_utils.TestConfigOpts(groups=paste_group)
 
47
 
 
48
        def _appendto(orig, copy, str):
 
49
            shutil.copy(orig, copy)
 
50
            with open(copy, 'ab') as f:
 
51
                f.write(str or '')
 
52
                f.flush()
 
53
 
 
54
        if paste_copy:
 
55
            paste_from = os.path.join(os.getcwd(), 'etc/glance-api-paste.ini')
 
56
            paste_to = os.path.join(conf.temp_file.replace('.conf',
 
57
                                                       '-paste.ini'))
 
58
            _appendto(paste_from, paste_to, paste_append)
 
59
 
 
60
        app = config.load_paste_app(conf, 'glance-api')
 
61
 
 
62
        self.assertEquals(expected_app_type, type(app))
 
63
 
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')])
42
 
 
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)
46
 
 
47
 
        app = config.load_paste_app(conf, 'glance-api')
48
 
 
49
 
        self.assertEquals(version_negotiation.VersionNegotiationFilter,
50
 
                          type(app))
 
65
        type = version_negotiation.VersionNegotiationFilter
 
66
        self._do_test_load_paste_app(type)
 
67
 
 
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'
 
72
 
 
73
        type = context.ContextMiddleware
 
74
        self._do_test_load_paste_app(type, paste_group, paste_append=pipeline)
 
75
 
 
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}}
 
80
 
 
81
        type = version_negotiation.VersionNegotiationFilter
 
82
        self._do_test_load_paste_app(type, paste_group, paste_copy=False)
51
83
 
52
84
    def test_load_paste_app_with_conf_name(self):
53
85
        def fake_join(*args):