def test_app_factory(self): data = 'test_app_factory' paste_conf = self.create_tempfile("""[DEFAULT] [app:myfoo] paste.app_factory = openstack.common.pastedeploy:app_factory openstack.app_factory = tests.unit.test_pastedeploy:App """) app = pastedeploy.paste_deploy_app(paste_conf, 'myfoo', data) self.assertEqual(app.data, data)
def test_app_factory_with_local_conf(self): data = 'test_app_factory_with_local_conf' paste_conf = self.create_tempfile("""[DEFAULT] [app:myfoo] paste.app_factory = openstack.common.pastedeploy:app_factory openstack.app_factory = tests.unit.test_pastedeploy:AppWithLocalConf foo = bar """) app = pastedeploy.paste_deploy_app(paste_conf, 'myfoo', data) self.assertEqual(app.data, data) self.assertEqual(app.foo, 'bar')
def test_filter_factory(self): data = 'test_filter_factory' paste_conf = self.create_tempfile("""[DEFAULT] [pipeline:myfoo] pipeline = myfoofilter myfooapp [filter:myfoofilter] paste.filter_factory = openstack.common.pastedeploy:filter_factory openstack.filter_factory = tests.unit.test_pastedeploy:Filter [app:myfooapp] paste.app_factory = openstack.common.pastedeploy:app_factory openstack.app_factory = tests.unit.test_pastedeploy:App """) app = pastedeploy.paste_deploy_app(paste_conf, 'myfoo', data) self.assertEqual(app.data, data) self.assertEqual(app.app.data, data)
def load_paste_app(app_name=None): ''' Builds and returns a WSGI app from a paste config file. We assume the last config file specified in the supplied ConfigOpts object is the paste config file. :param app_name: name of the application to load :raises RuntimeError when config file cannot be located or application cannot be loaded from config file ''' if app_name is None: app_name = CONF.prog # append the deployment flavor to the application name, # in order to identify the appropriate paste pipeline _register_paste_deploy_opts() app_name += _get_deployment_flavor() conf_file = _get_deployment_config_file() try: LOG.debug('Loading %(app_name)s from %(conf_file)s', { 'conf_file': conf_file, 'app_name': app_name }) AppFactory.KEY = CONF.paste_deploy.app_factory FilterFactory.KEY = CONF.paste_deploy.filter_factory app = paste_deploy_app(conf_file, app_name, CONF) return app except (LookupError, ImportError, ValueError) as e: msg = ('Unable to load %(app_name)s from ' 'configuration file %(conf_file)s.' '\nGot: %(e)r') % locals() LOG.error(msg) raise RuntimeError(msg)
def load_paste_app(app_name=None): ''' Builds and returns a WSGI app from a paste config file. We assume the last config file specified in the supplied ConfigOpts object is the paste config file. :param app_name: name of the application to load :raises RuntimeError when config file cannot be located or application cannot be loaded from config file ''' if app_name is None: app_name = CONF.prog # append the deployment flavor to the application name, # in order to identify the appropriate paste pipeline _register_paste_deploy_opts() app_name += _get_deployment_flavor() conf_file = _get_deployment_config_file() try: LOG.debug('Loading %(app_name)s from %(conf_file)s', {'conf_file': conf_file, 'app_name': app_name}) AppFactory.KEY = CONF.paste_deploy.app_factory FilterFactory.KEY = CONF.paste_deploy.filter_factory app = paste_deploy_app(conf_file, app_name, CONF) return app except (LookupError, ImportError, ValueError) as e: msg = ('Unable to load %(app_name)s from ' 'configuration file %(conf_file)s.' '\nGot: %(e)r') % locals() LOG.error(msg) raise RuntimeError(msg)