def test_config_bugzilla(self): """ Test when the config is set for bugzilla to be the bugtracker. """ bugs.set_bugtracker() assert isinstance(bugs.bugtracker, bugs.Bugzilla)
def test_config_not_bugzilla(self): """ Test when the config is no set for bugzilla to be the bugtracker. """ bugs.set_bugtracker() self.assertTrue(isinstance(bugs.bugtracker, bugs.FakeBugTracker))
def __init__(self, hub, *args, **kwargs): """ Initialize the UpdatesHandler, subscribing it to the appropriate topics. Args: hub (moksha.hub.hub.CentralMokshaHub): The hub this handler is consuming messages from. It is used to look up the hub config. """ initialize_db(config) self.db_factory = util.transactional_session_maker() prefix = hub.config.get('topic_prefix') env = hub.config.get('environment') self.topic = [ prefix + '.' + env + '.bodhi.update.request.testing', prefix + '.' + env + '.bodhi.update.edit', ] self.handle_bugs = bool(config.get('bodhi_email')) if not self.handle_bugs: log.warning("No bodhi_email defined; not fetching bug details") else: bug_module.set_bugtracker() super(UpdatesHandler, self).__init__(hub, *args, **kwargs) log.info('Bodhi updates handler listening on:\n' '%s' % pprint.pformat(self.topic))
def _setup_method(self): """Set up Bodhi for testing.""" self.config = testing.setUp() self.app_settings = get_appsettings(os.environ["BODHI_CONFIG"]) config.config.clear() config.config.load_config(self.app_settings) # Ensure "cached" objects are cleared before each test. models.Release.clear_all_releases_cache() models.Release._tag_cache = None if engine is None: self.engine = _configure_test_db(config.config["sqlalchemy.url"]) else: self.engine = engine self.connection = self.engine.connect() models.Base.metadata.create_all(bind=self.connection) self.transaction = self.connection.begin() Session.remove() Session.configure(bind=self.engine, autoflush=False, expire_on_commit=False) self.Session = Session self.db = Session() self.db.begin_nested() if self._populate_db: populate(self.db) bugs.set_bugtracker() buildsys.setup_buildsystem({'buildsystem': 'dev'}) self._request_sesh = mock.patch( 'bodhi.server.webapp._complete_database_session', webapp._rollback_or_commit) self._request_sesh.start() # Create the test WSGI app one time. We should avoid creating too many # of these since Pyramid holds global references to the objects it creates # and this results in a substantial memory leak. Long term we should figure # out how to make Pyramid forget about these. global _app if _app is None: # We don't want to call Session.remove() during the unit tests, because that will # trigger the restart_savepoint() callback defined above which will remove the data # added by populate(). with mock.patch('bodhi.server.Session.remove'): _app = TestApp( main({}, testing='guest', session=self.db, **self.app_settings)) self.app = _app self.registry = self.app.app.registry # ensure a clean state of the dev build system buildsys.DevBuildsys.clear()
def setUp(self): """Set up Bodhi for testing.""" # Ensure "cached" objects are cleared before each test. models.Release._all_releases = None models.Release._tag_cache = None if engine is None: self.engine = _configure_test_db() else: self.engine = engine self.connection = self.engine.connect() models.Base.metadata.create_all(bind=self.connection) self.transaction = self.connection.begin() Session.remove() Session.configure(bind=self.engine, autoflush=False, expire_on_commit=False) self.Session = Session self.db = Session() self.db.begin_nested() if self._populate_db: populate(self.db) bugs.set_bugtracker() buildsys.setup_buildsystem({'buildsystem': 'dev'}) def request_db(request=None): """ Replace the db session function with one that doesn't close the session. This allows tests to make assertions about the database. Without it, all the changes would be rolled back to when the nested transaction is started. """ def cleanup(request): if request.exception is not None: Session().rollback() else: Session().commit() request.add_finished_callback(cleanup) return Session() self._request_sesh = mock.patch( 'bodhi.server.get_db_session_for_request', request_db) self._request_sesh.start() # Create the test WSGI app one time. We should avoid creating too many # of these since Pyramid holds global references to the objects it creates # and this results in a substantial memory leak. Long term we should figure # out how to make Pyramid forget about these. global _app if _app is None: _app = TestApp(main({}, testing=u'guest', **self.app_settings)) self.app = _app
def __init__(self, *args, **kwargs): """Initialize the UpdatesHandler.""" initialize_db(config) self.db_factory = util.transactional_session_maker() self.handle_bugs = bool(config.get('bodhi_email')) if not self.handle_bugs: log.warning("No bodhi_email defined; not fetching bug details") else: bug_module.set_bugtracker()
def __init__(self): """Set up the database, build system, bug tracker, and handlers.""" log.info('Initializing Bodhi') initialize_db(config) buildsys.setup_buildsystem(config) bugs.set_bugtracker() self.handler_infos = [ HandlerInfo('.buildsys.tag', "Signed", SignedHandler()), HandlerInfo('.buildsys.tag', 'Automatic Update', AutomaticUpdateHandler()), HandlerInfo('.greenwave.decision.update', 'Greenwave', GreenwaveHandler()), HandlerInfo('.ci.koji-build.test.running', 'CI', CIHandler()) ]
def __init__(self): """Set up the database, build system, bug tracker, and handlers.""" log.info('Initializing Bodhi') initialize_db(config) buildsys.setup_buildsystem(config) bugs.set_bugtracker() self.handler_infos = [ HandlerInfo('.buildsys.tag', "Signed", SignedHandler()), HandlerInfo('.buildsys.tag', 'Automatic Update', AutomaticUpdateHandler()), HandlerInfo('.ci.koji-build.test.running', 'CI', CIHandler()), HandlerInfo('.waiverdb.waiver.new', 'WaiverDB', WaiverdbHandler()), HandlerInfo('.resultsdb.result.new', 'ResultsDB', ResultsdbHandler()), ]
def __init__(self): """Set up the database, build system, bug tracker, and handlers.""" log.info('Initializing Bodhi') initialize_db(config) buildsys.setup_buildsystem(config) bugs.set_bugtracker() if ComposerHandler: self.composer_handler = ComposerHandler() else: log.info( 'The composer is not installed - Bodhi will ignore composer.start messages.' ) self.composer_handler = None self.signed_handler = SignedHandler() self.updates_handler = UpdatesHandler()
def __init__(self, hub, db_factory=None, mash_dir=config.get('mash_dir'), *args, **kw): if not db_factory: config_uri = '/etc/bodhi/production.ini' settings = get_appsettings(config_uri) engine = engine_from_config(settings, 'sqlalchemy.') Base.metadata.create_all(engine) self.db_factory = transactional_session_maker() else: self.db_factory = db_factory buildsys.setup_buildsystem(config) bugs.set_bugtracker() self.mash_dir = mash_dir prefix = hub.config.get('topic_prefix') env = hub.config.get('environment') self.topic = prefix + '.' + env + '.' + hub.config.get('masher_topic') self.valid_signer = hub.config.get('releng_fedmsg_certname') if not self.valid_signer: log.warn('No releng_fedmsg_certname defined' 'Cert validation disabled') super(Masher, self).__init__(hub, *args, **kw) log.info('Bodhi masher listening on topic: %s' % self.topic)
def main(global_config, testing=None, session=None, **settings): """ Return a WSGI application. Args: global_config (dict): A dictionary with two keys: __file__, a path to the ini file, and here, the path to the code. testing (str or None): If this app is contructed by the unit tests, they should set this to a username. session (sqlalchemy.orm.session.Session or None): If given, the session will be used instead of building a new one. settings (dictionary): Unused. Returns: pyramid.router.Router: A WSGI app. """ if settings: bodhi_config.load_config(settings) # Setup our bugtracker and buildsystem bugs.set_bugtracker() setup_buildsys() # Sessions & Caching from pyramid.session import SignedCookieSessionFactory session_factory = SignedCookieSessionFactory( bodhi_config['session.secret']) # Construct a list of all groups we're interested in default = [] for key in ('important_groups', 'admin_packager_groups', 'mandatory_packager_groups', 'admin_groups'): default.extend(bodhi_config.get(key)) # pyramid_fas_openid looks for this setting bodhi_config['openid.groups'] = bodhi_config.get('openid.groups', default) config = Configurator(settings=bodhi_config, session_factory=session_factory) # Plugins config.include('pyramid_mako') config.include('cornice') # Initialize the database scoped session initialize_db(bodhi_config) # Lazy-loaded memoized request properties if session: config.registry.sessionmaker = lambda: session else: config.registry.sessionmaker = Session config.add_request_method(lambda x: Session, 'db', reify=True) config.add_request_method(get_user, 'user', reify=True) config.add_request_method(get_koji, 'koji', reify=True) config.add_request_method(get_cacheregion, 'cache', reify=True) config.add_request_method(get_buildinfo, 'buildinfo', reify=True) config.add_request_method(get_from_tag_inherited, 'from_tag_inherited', reify=True) config.add_request_method(get_releases, 'releases', reify=True) # Templating config.add_mako_renderer('.html', settings_prefix='mako.') config.add_static_view( f'static/v{pkg_resources.get_distribution("bodhi").version}', 'bodhi:server/static') from bodhi.server.renderers import rss config.add_renderer('rss', rss) config.add_renderer('jsonp', JSONP(param_name='callback')) # i18n config.add_translation_dirs('bodhi:server/locale/') # Authentication & Authorization if testing: # use a permissive security policy while running unit tests config.testing_securitypolicy(userid=testing, permissive=True) else: timeout = bodhi_config.get('authtkt.timeout') config.set_authentication_policy( AuthTktAuthenticationPolicy(bodhi_config['authtkt.secret'], callback=groupfinder, secure=bodhi_config['authtkt.secure'], hashalg='sha512', timeout=timeout, max_age=timeout)) config.set_authorization_policy(ACLAuthorizationPolicy()) # Frontpage config.add_route('home', '/') # Views for creating new objects config.add_route('new_update', '/updates/new') config.add_route('new_override', '/overrides/new') # Metrics config.add_route('metrics', '/metrics') # Auto-completion search config.add_route('latest_candidates', '/latest_candidates') config.add_route('latest_builds', '/latest_builds') config.add_route('get_sidetags', '/get_sidetags') config.add_route('latest_builds_in_tag', '/latest_builds_in_tag') # pyramid.openid config.add_route('login', '/login') config.add_view('bodhi.server.security.login', route_name='login') config.add_route('logout', '/logout') config.add_view('bodhi.server.security.logout', route_name='logout') config.add_route('verify_openid', pattern='/dologin.html') config.add_view('pyramid_fas_openid.verify_openid', route_name='verify_openid') config.add_route('api_version', '/api_version') config.scan('bodhi.server.views') config.scan('bodhi.server.services') config.scan('bodhi.server.webapp') # Though importing in the middle of this function is the darkest of evils, we cannot do it any # other way without a backwards-incompatible change. See # https://github.com/fedora-infra/bodhi/issues/2294 from bodhi.server import models from bodhi.server.views import generic # Let's put a cache on the home page stats, but only if it isn't already cached. The cache adds # an invalidate attribute to the method, so that's how we can tell. The server would not # encounter this function already having a cache in normal operation, but the unit tests do run # this function many times so we don't want them to cause it to cache a cache of the cache of # the cache… if not hasattr(generic._generate_home_page_stats, 'invalidate'): generic._generate_home_page_stats = get_cacheregion( None).cache_on_arguments()(generic._generate_home_page_stats) if bodhi_config['warm_cache_on_start']: log.info('Warming up caches…') # Let's warm up the Releases._all_releases cache. We can just call the function - we don't # need to capture the return value. models.Release.all_releases() # Let's warm up the home page cache by calling _generate_home_page_stats(). We can ignore # the return value. generic._generate_home_page_stats() # Let's close out the db session we used to warm the caches. Session.remove() log.info('Bodhi ready and at your service!') return config.make_wsgi_app()
def main(global_config, testing=None, session=None, **settings): """ Return a WSGI application. Args: global_config (dict): A dictionary with two keys: __file__, a path to the ini file, and here, the path to the code. testing (bool or None): Whether or not we are in testing mode. session (sqlalchemy.orm.session.Session or None): If given, the session will be used instead of building a new one. settings (dictionary): Unused. Returns: pyramid.router.Router: A WSGI app. """ if settings: bodhi_config.load_config(settings) # Setup our bugtracker and buildsystem bugs.set_bugtracker() buildsys.setup_buildsystem(bodhi_config) # Sessions & Caching from pyramid.session import SignedCookieSessionFactory session_factory = SignedCookieSessionFactory( bodhi_config['session.secret']) # Construct a list of all groups we're interested in default = [] for key in ('important_groups', 'admin_packager_groups', 'mandatory_packager_groups', 'admin_groups'): default.extend(bodhi_config.get(key)) # pyramid_fas_openid looks for this setting bodhi_config['openid.groups'] = bodhi_config.get('openid.groups', default) config = Configurator(settings=bodhi_config, session_factory=session_factory) # Plugins config.include('pyramid_mako') config.include('cornice') # Initialize the database scoped session initialize_db(bodhi_config) # Lazy-loaded memoized request properties if session: config.registry.sessionmaker = lambda: session else: config.registry.sessionmaker = Session config.add_request_method(get_db_session_for_request, 'db', reify=True) config.add_request_method(get_user, 'user', reify=True) config.add_request_method(get_koji, 'koji', reify=True) config.add_request_method(get_cacheregion, 'cache', reify=True) config.add_request_method(get_buildinfo, 'buildinfo', reify=True) config.add_request_method(get_releases, 'releases', reify=True) # Templating config.add_mako_renderer('.html', settings_prefix='mako.') config.add_static_view('static', 'bodhi:server/static') from bodhi.server.renderers import rss, jpeg config.add_renderer('rss', rss) config.add_renderer('jpeg', jpeg) config.add_renderer('jsonp', JSONP(param_name='callback')) # i18n config.add_translation_dirs('bodhi:server/locale/') # Authentication & Authorization if testing: # use a permissive security policy while running unit tests config.testing_securitypolicy(userid=testing, permissive=True) else: timeout = bodhi_config.get('authtkt.timeout') config.set_authentication_policy( AuthTktAuthenticationPolicy(bodhi_config['authtkt.secret'], callback=groupfinder, secure=bodhi_config['authtkt.secure'], hashalg='sha512', timeout=timeout, max_age=timeout)) config.set_authorization_policy(ACLAuthorizationPolicy()) # Frontpage config.add_route('home', '/') # Views for creating new objects config.add_route('new_update', '/updates/new') config.add_route('new_override', '/overrides/new') config.add_route('new_stack', '/stacks/new') # Metrics config.add_route('metrics', '/metrics') config.add_route('masher_status', '/masher/') # Auto-completion search config.add_route('search_packages', '/search/packages') config.add_route('latest_candidates', '/latest_candidates') config.add_route('latest_builds', '/latest_builds') config.add_route('captcha_image', '/captcha/{cipherkey}/') # pyramid.openid config.add_route('login', '/login') config.add_view('bodhi.server.security.login', route_name='login') config.add_view('bodhi.server.security.login', context=HTTPForbidden) config.add_route('logout', '/logout') config.add_view('bodhi.server.security.logout', route_name='logout') config.add_route('verify_openid', pattern='/dologin.html') config.add_view('pyramid_fas_openid.verify_openid', route_name='verify_openid') config.add_route('api_version', '/api_version') # The only user preference we have. config.add_route('popup_toggle', '/popup_toggle') config.scan('bodhi.server.views') config.scan('bodhi.server.services') config.scan('bodhi.server.captcha') return config.make_wsgi_app()
def _do_init(): config.load_config() initialize_db(config) buildsys.setup_buildsystem(config) bugs.set_bugtracker()