From c44e16a538113293c7e73eea22c2ebc0f84c365f Mon Sep 17 00:00:00 2001 From: Mark McLoughlin <markmc@redhat.com> Date: Sat, 16 Jun 2012 16:57:56 +0100 Subject: [PATCH] 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 --- bin/glance-cache-cleaner | 7 ++++++- bin/glance-cache-prefetcher | 8 +++++-- bin/glance-cache-pruner | 7 ++++++- bin/glance-scrubber | 3 ++- etc/glance-cache-paste.ini | 8 ------- etc/glance-scrubber-paste.ini | 2 -- glance/image_cache/base.py | 4 ---- glance/store/scrubber.py | 4 ---- glance/tests/functional/__init__.py | 3 --- .../v1/test_bin_glance_cache_manage.py | 12 ----------- .../functional/v1/test_cache_middleware.py | 12 ----------- glance/tests/unit/test_config.py | 21 ------------------- 12 files changed, 20 insertions(+), 71 deletions(-) delete mode 100644 etc/glance-cache-paste.ini delete mode 100644 etc/glance-scrubber-paste.ini diff --git a/bin/glance-cache-cleaner b/bin/glance-cache-cleaner index 6246714a24..3fcd26140b 100755 --- a/bin/glance-cache-cleaner +++ b/bin/glance-cache-cleaner @@ -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) diff --git a/bin/glance-cache-prefetcher b/bin/glance-cache-prefetcher index 9b73edfdba..7948ae9407 100755 --- a/bin/glance-cache-prefetcher +++ b/bin/glance-cache-prefetcher @@ -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) diff --git a/bin/glance-cache-pruner b/bin/glance-cache-pruner index 92f0638ab4..62b5a981d3 100755 --- a/bin/glance-cache-pruner +++ b/bin/glance-cache-pruner @@ -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) diff --git a/bin/glance-scrubber b/bin/glance-scrubber index 69afcb6b22..365ead9faf 100755 --- a/bin/glance-scrubber +++ b/bin/glance-scrubber @@ -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) diff --git a/etc/glance-cache-paste.ini b/etc/glance-cache-paste.ini deleted file mode 100644 index 36b0ffc81b..0000000000 --- a/etc/glance-cache-paste.ini +++ /dev/null @@ -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 diff --git a/etc/glance-scrubber-paste.ini b/etc/glance-scrubber-paste.ini deleted file mode 100644 index 8762aa1403..0000000000 --- a/etc/glance-scrubber-paste.ini +++ /dev/null @@ -1,2 +0,0 @@ -[app:glance-scrubber] -paste.app_factory = glance.store.scrubber:Scrubber.factory diff --git a/glance/image_cache/base.py b/glance/image_cache/base.py index b0385c1bbd..eb8832cb0e 100644 --- a/glance/image_cache/base.py +++ b/glance/image_cache/base.py @@ -21,7 +21,3 @@ class CacheApp(object): def __init__(self): self.cache = ImageCache() - - @classmethod - def factory(cls, global_conf, **local_conf): - return cls() diff --git a/glance/store/scrubber.py b/glance/store/scrubber.py index 6f52faad3c..5acfdf901c 100644 --- a/glance/store/scrubber.py +++ b/glance/store/scrubber.py @@ -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() diff --git a/glance/tests/functional/__init__.py b/glance/tests/functional/__init__.py index b239dfd63a..cf4e9dea70 100644 --- a/glance/tests/functional/__init__.py +++ b/glance/tests/functional/__init__.py @@ -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 """ diff --git a/glance/tests/functional/v1/test_bin_glance_cache_manage.py b/glance/tests/functional/v1/test_bin_glance_cache_manage.py index 4a477648c0..03e4b0d824 100644 --- a/glance/tests/functional/v1/test_bin_glance_cache_manage.py +++ b/glance/tests/functional/v1/test_bin_glance_cache_manage.py @@ -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) diff --git a/glance/tests/functional/v1/test_cache_middleware.py b/glance/tests/functional/v1/test_cache_middleware.py index d1d24034a1..2be0ae7602 100644 --- a/glance/tests/functional/v1/test_cache_middleware.py +++ b/glance/tests/functional/v1/test_cache_middleware.py @@ -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 = {} diff --git a/glance/tests/unit/test_config.py b/glance/tests/unit/test_config.py index 911731b456..c0ec0cf1dc 100644 --- a/glance/tests/unit/test_config.py +++ b/glance/tests/unit/test_config.py @@ -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))