Don't use PasteDeploy for scrubber and cache daemons

There are no WSGI apps involved here, no need to configure pipelines with
filters etc. All we're using PasteDeploy for is to construct an object.

Well ... there are easier ways to do that! :)

Change-Id: I4166d0071738fe587572db8f2883900408e9f097
This commit is contained in:
Mark McLoughlin 2012-06-16 16:57:56 +01:00
parent 3b4c276550
commit c44e16a538
12 changed files with 20 additions and 71 deletions

View File

@ -47,13 +47,18 @@ if os.path.exists(os.path.join(possible_topdir, 'glance', '__init__.py')):
gettext.install('glance', unicode=1)
from glance.common import config
from glance.image_cache import cleaner
from glance.openstack.common import cfg
CONF = cfg.CONF
if __name__ == '__main__':
try:
config.parse_cache_args()
config.setup_logging()
app = config.load_paste_app('glance-cleaner', 'glance-cache-paste.ini')
app = cleaner.Cleaner()
app.run()
except RuntimeError, e:
sys.exit("ERROR: %s" % e)

View File

@ -38,14 +38,18 @@ if os.path.exists(os.path.join(possible_topdir, 'glance', '__init__.py')):
gettext.install('glance', unicode=1)
from glance.common import config
from glance.image_cache import prefetcher
from glance.openstack.common import cfg
CONF = cfg.CONF
if __name__ == '__main__':
try:
config.parse_cache_args()
config.setup_logging()
app = config.load_paste_app('glance-prefetcher',
'glance-cache-paste.ini')
app = prefetcher.Prefetcher()
app.run()
except RuntimeError, e:
sys.exit("ERROR: %s" % e)

View File

@ -39,13 +39,18 @@ if os.path.exists(os.path.join(possible_topdir, 'glance', '__init__.py')):
gettext.install('glance', unicode=1)
from glance.common import config
from glance.image_cache import pruner
from glance.openstack.common import cfg
CONF = cfg.CONF
if __name__ == '__main__':
try:
config.parse_cache_args()
config.setup_logging()
app = config.load_paste_app('glance-pruner', 'glance-cache-paste.ini')
app = pruner.Pruner()
app.run()
except RuntimeError, e:
sys.exit("ERROR: %s" % e)

View File

@ -55,8 +55,9 @@ if __name__ == '__main__':
CONF.register_opt(cfg.IntOpt('wakeup_time', default=300))
config.parse_args()
config.setup_logging()
app = config.load_paste_app('glance-scrubber')
app = scrubber.Scrubber()
if CONF.daemon:
server = scrubber.Daemon(CONF.wakeup_time)

View File

@ -1,8 +0,0 @@
[app:glance-pruner]
paste.app_factory = glance.image_cache.pruner:Pruner.factory
[app:glance-prefetcher]
paste.app_factory = glance.image_cache.prefetcher:Prefetcher.factory
[app:glance-cleaner]
paste.app_factory = glance.image_cache.cleaner:Cleaner.factory

View File

@ -1,2 +0,0 @@
[app:glance-scrubber]
paste.app_factory = glance.store.scrubber:Scrubber.factory

View File

@ -21,7 +21,3 @@ class CacheApp(object):
def __init__(self):
self.cache = ImageCache()
@classmethod
def factory(cls, global_conf, **local_conf):
return cls()

View File

@ -88,10 +88,6 @@ class Scrubber(object):
store.create_stores()
@classmethod
def factory(cls, global_conf, **local_conf):
return cls()
def run(self, pool, event=None):
now = time.time()

View File

@ -396,9 +396,6 @@ wakeup_time = 2
scrubber_datadir = %(scrubber_datadir)s
registry_host = 0.0.0.0
registry_port = %(registry_port)s
"""
self.paste_conf_base = """[app:glance-scrubber]
paste.app_factory = glance.store.scrubber:Scrubber.factory
"""

View File

@ -206,18 +206,6 @@ metadata_encryption_key = %(metadata_encryption_key)s
log_file = %(log_file)s
""" % cache_file_options)
with open(cache_config_filepath.replace(".conf", "-paste.ini"),
'w') as paste_file:
paste_file.write("""[app:glance-pruner]
paste.app_factory = glance.image_cache.pruner:Pruner.factory
[app:glance-prefetcher]
paste.app_factory = glance.image_cache.prefetcher:Prefetcher.factory
[app:glance-cleaner]
paste.app_factory = glance.image_cache.cleaner:Cleaner.factory
""")
cmd = ("bin/glance-cache-prefetcher --config-file %s" %
cache_config_filepath)

View File

@ -457,18 +457,6 @@ metadata_encryption_key = %(metadata_encryption_key)s
log_file = %(log_file)s
""" % cache_file_options)
with open(cache_config_filepath.replace(".conf", "-paste.ini"),
'w') as paste_file:
paste_file.write("""[app:glance-pruner]
paste.app_factory = glance.image_cache.pruner:Pruner.factory
[app:glance-prefetcher]
paste.app_factory = glance.image_cache.prefetcher:Prefetcher.factory
[app:glance-cleaner]
paste.app_factory = glance.image_cache.cleaner:Cleaner.factory
""")
self.verify_no_images()
ids = {}

View File

@ -96,24 +96,3 @@ class TestPasteApp(test_utils.BaseTestCase):
expected_middleware = context.UnauthenticatedContextMiddleware
self._do_test_load_paste_app(expected_middleware,
paste_config_file=paste_config_file)
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)
config.parse_cache_args([])
self.stubs.Set(config, 'setup_logging', lambda *a: None)
self.stubs.Set(pruner.Pruner, '__init__', lambda p: None)
app = config.load_paste_app('glance-pruner')
self.assertTrue(isinstance(app, pruner.Pruner))