3878aff Separate use of database sessions

Authored and Committed by cqi 4 years ago
54 files changed. 2717 lines added. 2479 lines removed.
conf/config.py
file modified
+2 -1
module_build_service/builder/KojiContentGenerator.py
file modified
+3 -2
module_build_service/builder/KojiModuleBuilder.py
file modified
+6 -4
module_build_service/builder/MockModuleBuilder.py
file modified
+3 -2
module_build_service/builder/base.py
file modified
+14 -10
module_build_service/logger.py
file modified
+6 -6
module_build_service/manage.py
file modified
+61 -56
module_build_service/models.py
file modified
+198 -132
module_build_service/resolver/DBResolver.py
file modified
+224 -231
module_build_service/resolver/MBSResolver.py
file modified
+10 -7
module_build_service/resolver/__init__.py
file modified
+0 -6
module_build_service/resolver/base.py
file modified
+2 -2
module_build_service/scheduler/__init__.py
file modified
+2 -2
module_build_service/scheduler/consumer.py
file modified
+15 -14
module_build_service/scheduler/default_modules.py
file modified
+2 -1
module_build_service/scheduler/handlers/components.py
file modified
+17 -15
module_build_service/scheduler/handlers/greenwave.py
file modified
+7 -6
module_build_service/scheduler/handlers/modules.py
file modified
+71 -59
module_build_service/scheduler/handlers/repos.py
file modified
+10 -8
module_build_service/scheduler/handlers/tags.py
file modified
+6 -6
module_build_service/scheduler/producer.py
file modified
+55 -50
module_build_service/utils/batches.py
file modified
+32 -17
module_build_service/utils/general.py
file modified
+87 -85
module_build_service/utils/mse.py
file modified
+27 -31
module_build_service/utils/reuse.py
file modified
+17 -17
module_build_service/utils/submit.py
file modified
+52 -55
module_build_service/utils/ursine.py
file modified
+17 -11
module_build_service/views.py
file modified
+19 -7
tests/__init__.py
file modified
+116 -383
tests/conftest.py
file modified
+325 -6
tests/test_build/test_build.py
file modified
+186 -163
tests/test_builder/test_base.py
file modified
+21 -20
tests/test_builder/test_koji.py
file modified
+94 -57
tests/test_builder/test_mock.py
file modified
+70 -72
tests/test_content_generator.py
file modified
+6 -3
tests/test_logger.py
file modified
+11 -11
tests/test_manage.py
file modified
+45 -45
tests/test_models/__init__.py
file modified
+0 -44
tests/test_models/test_models.py
file modified
+122 -117
tests/test_monitor.py
file modified
+12 -12
tests/test_resolver/test_db.py
file modified
+57 -58
tests/test_resolver/test_local.py
file modified
+7 -12
tests/test_resolver/test_mbs.py
file modified
+48 -53
tests/test_scheduler/test_greenwave.py
file modified
+24 -24
tests/test_scheduler/test_module_init.py
file modified
+35 -32
tests/test_scheduler/test_module_wait.py
file modified
+41 -37
tests/test_scheduler/test_poller.py
file modified
+85 -74
tests/test_scheduler/test_repo_done.py
file modified
+21 -12
tests/test_scheduler/test_tag_tagged.py
file modified
+72 -65
tests/test_utils/test_greenwave.py
file modified
+6 -10
tests/test_utils/test_ursine.py
file modified
+35 -33
tests/test_utils/test_utils.py
file modified
+284 -264
tests/test_utils/test_utils_mse.py
file modified
+22 -23
tests/test_views/test_views.py
file modified
+7 -6
    Separate use of database sessions
    
    This patch separates the use of database session in different MBS components
    and do not mix them together.
    
    In general, MBS components could be separated as the REST API (implemented
    based on Flask) and non-REST API including the backend build workflow
    (implemented as a fedmsg consumer on top of fedmsg-hub and running
    independently) and library shared by them. As a result, there are two kind of
    database session used in MBS, one is created and managed by Flask-SQLAlchemy,
    and another one is created from SQLAclhemy Session API directly. The goal of
    this patch is to make ensure session object is used properly in the right
    place.
    
    All the changes follow these rules:
    
    * REST API related code uses the session object db.session created and
      managed by Flask-SQLAlchemy.
    * Non-REST API related code uses the session object created with SQLAlchemy
      Session API. Function make_db_session does that.
    * Shared code does not created a new session object as much as possible.
      Instead, it accepts an argument db_session.
    
    The first two rules are applicable to tests as well.
    
    Major changes:
    
    * Switch tests back to run with a file-based SQLite database.
    * make_session is renamed to make_db_session and SQLAlchemy connection pool
      options are applied for PostgreSQL backend.
    * Frontend Flask related code uses db.session
    * Shared code by REST API and backend build workflow accepts SQLAlchemy session
      object as an argument. For example, resolver class is constructed with a
      database session, and some functions accepts an argument for database session.
    * Build workflow related code use session object returned from make_db_session
      and ensure db.session is not used.
    * Only tests for views use db.session, and other tests use db_session fixture
      to access database.
    * All argument name session, that is for database access, are renamed to
      db_session.
    * Functions model_tests_init_data, reuse_component_init_data and
      reuse_shared_userspace_init_data, which creates fixture data for
      tests, are converted into pytest fixtures from original function
      called inside setup_method or a test method. The reason of this
      conversion is to use fixture ``db_session`` rather than create a
      new one. That would also benefit the whole test suite to reduce the
      number of SQLAlchemy session objects.
    
    Signed-off-by: Chenxiong Qi <cqi@redhat.com>
    
        
file modified
+2 -1
file modified
+61 -56
file modified
+198 -132
file modified
+19 -7
file modified
+116 -383
file modified
+325 -6
file modified
+186 -163
file modified
+21 -20
file modified
+94 -57
file modified
+70 -72
file modified
+11 -11
file modified
+45 -45
file modified
+0 -44
file modified
+122 -117
file modified
+12 -12
file modified
+57 -58
file modified
+48 -53
file modified
+35 -33
file modified
+284 -264