예제 #1
0
파일: test_wsgi.py 프로젝트: Dieterbe/swift
    def test_init_request_processor(self):
        config = """
        [DEFAULT]
        swift_dir = TEMPDIR

        [pipeline:main]
        pipeline = catch_errors proxy-server

        [app:proxy-server]
        use = egg:swift#proxy
        conn_timeout = 0.2

        [filter:catch_errors]
        use = egg:swift#catch_errors
        """
        contents = dedent(config)
        with temptree(["proxy-server.conf"]) as t:
            conf_file = os.path.join(t, "proxy-server.conf")
            with open(conf_file, "w") as f:
                f.write(contents.replace("TEMPDIR", t))
            _fake_rings(t)
            app, conf, logger, log_name = wsgi.init_request_processor(conf_file, "proxy-server")
        # verify pipeline is catch_errors -> proxy-servery
        expected = swift.common.middleware.catch_errors.CatchErrorMiddleware
        self.assert_(isinstance(app, expected))
        self.assert_(isinstance(app.app, swift.proxy.server.Application))
        # config settings applied to app instance
        self.assertEquals(0.2, app.app.conn_timeout)
        # appconfig returns values from 'proxy-server' section
        expected = {"__file__": conf_file, "here": os.path.dirname(conf_file), "conn_timeout": "0.2", "swift_dir": t}
        self.assertEquals(expected, conf)
        # logger works
        logger.info("testing")
        self.assertEquals("proxy-server", log_name)
예제 #2
0
    def test_init_request_processor(self):
        config = """
        [DEFAULT]
        swift_dir = TEMPDIR

        [pipeline:main]
        pipeline = proxy-server

        [app:proxy-server]
        use = egg:swift#proxy
        conn_timeout = 0.2
        """
        contents = dedent(config)
        with temptree(['proxy-server.conf']) as t:
            conf_file = os.path.join(t, 'proxy-server.conf')
            with open(conf_file, 'w') as f:
                f.write(contents.replace('TEMPDIR', t))
            _fake_rings(t)
            app, conf, logger, log_name = wsgi.init_request_processor(
                conf_file, 'proxy-server')
        # verify pipeline is catch_errors -> dlo -> proxy-server
        expected = swift.common.middleware.catch_errors.CatchErrorMiddleware
        self.assert_(isinstance(app, expected))

        app = app.app
        expected = swift.common.middleware.gatekeeper.GatekeeperMiddleware
        self.assert_(isinstance(app, expected))

        app = app.app
        expected = swift.common.middleware.dlo.DynamicLargeObject
        self.assert_(isinstance(app, expected))

        app = app.app
        expected = swift.proxy.server.Application
        self.assert_(isinstance(app, expected))
        # config settings applied to app instance
        self.assertEquals(0.2, app.conn_timeout)
        # appconfig returns values from 'proxy-server' section
        expected = {
            '__file__': conf_file,
            'here': os.path.dirname(conf_file),
            'conn_timeout': '0.2',
            'swift_dir': t,
        }
        self.assertEquals(expected, conf)
        # logger works
        logger.info('testing')
        self.assertEquals('proxy-server', log_name)
예제 #3
0
    def test_init_request_processor(self):
        config = """
        [DEFAULT]
        swift_dir = TEMPDIR

        [pipeline:main]
        pipeline = proxy-server

        [app:proxy-server]
        use = egg:swift#proxy
        conn_timeout = 0.2
        """
        contents = dedent(config)
        with temptree(['proxy-server.conf']) as t:
            conf_file = os.path.join(t, 'proxy-server.conf')
            with open(conf_file, 'w') as f:
                f.write(contents.replace('TEMPDIR', t))
            _fake_rings(t)
            app, conf, logger, log_name = wsgi.init_request_processor(
                conf_file, 'proxy-server')
        # verify pipeline is catch_errors -> dlo -> proxy-server
        expected = swift.common.middleware.catch_errors.CatchErrorMiddleware
        self.assert_(isinstance(app, expected))

        app = app.app
        expected = swift.common.middleware.gatekeeper.GatekeeperMiddleware
        self.assert_(isinstance(app, expected))

        app = app.app
        expected = swift.common.middleware.dlo.DynamicLargeObject
        self.assert_(isinstance(app, expected))

        app = app.app
        expected = swift.proxy.server.Application
        self.assert_(isinstance(app, expected))
        # config settings applied to app instance
        self.assertEquals(0.2, app.conn_timeout)
        # appconfig returns values from 'proxy-server' section
        expected = {
            '__file__': conf_file,
            'here': os.path.dirname(conf_file),
            'conn_timeout': '0.2',
            'swift_dir': t,
        }
        self.assertEquals(expected, conf)
        # logger works
        logger.info('testing')
        self.assertEquals('proxy-server', log_name)
예제 #4
0
 def test_init_request_processor_from_conf_dir(self):
     config_dir = {
         'proxy-server.conf.d/pipeline.conf':
         """
         [pipeline:main]
         pipeline = catch_errors proxy-server
         """,
         'proxy-server.conf.d/app.conf':
         """
         [app:proxy-server]
         use = egg:swift#proxy
         conn_timeout = 0.2
         """,
         'proxy-server.conf.d/catch-errors.conf':
         """
         [filter:catch_errors]
         use = egg:swift#catch_errors
         """
     }
     # strip indent from test config contents
     config_dir = dict((f, dedent(c)) for (f, c) in config_dir.items())
     with mock.patch('swift.proxy.server.Application.modify_wsgi_pipeline'):
         with temptree(*zip(*config_dir.items())) as conf_root:
             conf_dir = os.path.join(conf_root, 'proxy-server.conf.d')
             with open(os.path.join(conf_dir, 'swift.conf'), 'w') as f:
                 f.write('[DEFAULT]\nswift_dir = %s' % conf_root)
             _fake_rings(conf_root)
             app, conf, logger, log_name = wsgi.init_request_processor(
                 conf_dir, 'proxy-server')
     # verify pipeline is catch_errors -> proxy-server
     expected = swift.common.middleware.catch_errors.CatchErrorMiddleware
     self.assert_(isinstance(app, expected))
     self.assert_(isinstance(app.app, swift.proxy.server.Application))
     # config settings applied to app instance
     self.assertEquals(0.2, app.app.conn_timeout)
     # appconfig returns values from 'proxy-server' section
     expected = {
         '__file__': conf_dir,
         'here': conf_dir,
         'conn_timeout': '0.2',
         'swift_dir': conf_root,
     }
     self.assertEquals(expected, conf)
     # logger works
     logger.info('testing')
     self.assertEquals('proxy-server', log_name)
예제 #5
0
파일: test_wsgi.py 프로젝트: Taejun/swift
 def test_init_request_processor_from_conf_dir(self):
     config_dir = {
         'proxy-server.conf.d/pipeline.conf': """
         [pipeline:main]
         pipeline = catch_errors proxy-server
         """,
         'proxy-server.conf.d/app.conf': """
         [app:proxy-server]
         use = egg:swift#proxy
         conn_timeout = 0.2
         """,
         'proxy-server.conf.d/catch-errors.conf': """
         [filter:catch_errors]
         use = egg:swift#catch_errors
         """
     }
     # strip indent from test config contents
     config_dir = dict((f, dedent(c)) for (f, c) in config_dir.items())
     with mock.patch('swift.proxy.server.Application.modify_wsgi_pipeline'):
         with temptree(*zip(*config_dir.items())) as conf_root:
             conf_dir = os.path.join(conf_root, 'proxy-server.conf.d')
             with open(os.path.join(conf_dir, 'swift.conf'), 'w') as f:
                 f.write('[DEFAULT]\nswift_dir = %s' % conf_root)
             _fake_rings(conf_root)
             app, conf, logger, log_name = wsgi.init_request_processor(
                 conf_dir, 'proxy-server')
     # verify pipeline is catch_errors -> proxy-server
     expected = swift.common.middleware.catch_errors.CatchErrorMiddleware
     self.assert_(isinstance(app, expected))
     self.assert_(isinstance(app.app, swift.proxy.server.Application))
     # config settings applied to app instance
     self.assertEquals(0.2, app.app.conn_timeout)
     # appconfig returns values from 'proxy-server' section
     expected = {
         '__file__': conf_dir,
         'here': conf_dir,
         'conn_timeout': '0.2',
         'swift_dir': conf_root,
     }
     self.assertEquals(expected, conf)
     # logger works
     logger.info('testing')
     self.assertEquals('proxy-server', log_name)
예제 #6
0
파일: test_wsgi.py 프로젝트: Dieterbe/swift
 def test_init_request_processor_from_conf_dir(self):
     config_dir = {
         "proxy-server.conf.d/pipeline.conf": """
         [pipeline:main]
         pipeline = catch_errors proxy-server
         """,
         "proxy-server.conf.d/app.conf": """
         [app:proxy-server]
         use = egg:swift#proxy
         conn_timeout = 0.2
         """,
         "proxy-server.conf.d/catch-errors.conf": """
         [filter:catch_errors]
         use = egg:swift#catch_errors
         """,
     }
     # strip indent from test config contents
     config_dir = dict((f, dedent(c)) for (f, c) in config_dir.items())
     with temptree(*zip(*config_dir.items())) as conf_root:
         conf_dir = os.path.join(conf_root, "proxy-server.conf.d")
         with open(os.path.join(conf_dir, "swift.conf"), "w") as f:
             f.write("[DEFAULT]\nswift_dir = %s" % conf_root)
         _fake_rings(conf_root)
         app, conf, logger, log_name = wsgi.init_request_processor(conf_dir, "proxy-server")
     # verify pipeline is catch_errors -> proxy-servery
     expected = swift.common.middleware.catch_errors.CatchErrorMiddleware
     self.assert_(isinstance(app, expected))
     self.assert_(isinstance(app.app, swift.proxy.server.Application))
     # config settings applied to app instance
     self.assertEquals(0.2, app.app.conn_timeout)
     # appconfig returns values from 'proxy-server' section
     expected = {"__file__": conf_dir, "here": conf_dir, "conn_timeout": "0.2", "swift_dir": conf_root}
     self.assertEquals(expected, conf)
     # logger works
     logger.info("testing")
     self.assertEquals("proxy-server", log_name)
예제 #7
0
    def test_init_request_processor_with_dynamic_pipeline(self):
        config_dir = {
            'proxy-server.conf.d/pipeline.conf':
            """
            [DEFAULT]
            dynamic_pipelines: True

            [pipeline:main]
            pipeline = tempauth proxy-server
            """,
            'proxy-server.conf.d/app.conf':
            """
            [app:proxy-server]
            use = egg:swift#proxy
            """,
            'proxy-server.conf.d/catch-errors.conf':
            """
            [filter:catch_errors]
            use = egg:swift#catch_errors
            pipeline = main
            before = #start healthcheck
            """,
            'proxy-server.conf.d/others.conf':
            """
            [filter:tempauth]
            use = egg:swift#tempauth

            [filter:keystone]
            use = egg:swift#keystoneauth
            before = tempauth proxy-server
            pipeline = main

            [filter:healthcheck]
            use = egg:swift#healthcheck
            before = #start
            pipeline = main
            """,
        }

        # strip indent from test config contents
        config_dir = dict((f, dedent(c)) for (f, c) in config_dir.items())
        with temptree(*zip(*config_dir.items())) as conf_root:
            conf_dir = os.path.join(conf_root, 'proxy-server.conf.d')
            with open(os.path.join(conf_dir, 'swift.conf'), 'w') as f:
                f.write('[DEFAULT]\nswift_dir = %s' % conf_root)
            _fake_rings(conf_root)
            app, conf, logger, log_name = wsgi.init_request_processor(
                conf_dir, 'proxy-server')

        # verify pipeline
        def get_pipeline(app):
            yield app
            while hasattr(app, 'app'):
                app = app.app
                yield app

        def get_pipeline_class_names(app):
            for ware in get_pipeline(app):
                yield ware.__class__.__name__

        expected_classnames = [
            'CatchErrorMiddleware', 'HealthCheckMiddleware', 'KeystoneAuth',
            'TempAuth', 'Application'
        ]

        pipeline_classnames = list(get_pipeline_class_names(app))
        self.assertEquals(expected_classnames, pipeline_classnames)