diff --git a/glance/sqlite_migration.py b/glance/sqlite_migration.py index b79fedaee5..8e06f9cddd 100644 --- a/glance/sqlite_migration.py +++ b/glance/sqlite_migration.py @@ -33,15 +33,18 @@ CONF.import_opt("image_cache_sqlite_db", "glance.image_cache.drivers.sqlite") def can_migrate_to_central_db(): + # Return immediately if cache is disabled + if not (CONF.paste_deploy.flavor and 'cache' in CONF.paste_deploy.flavor): + return False + + is_centralized_db_driver = CONF.image_cache_driver == "centralized_db" # Check worker_self_reference_url is set if cache is enabled and # cache driver is centralized_db - is_centralized_db_driver = CONF.image_cache_driver == "centralized_db" - if CONF.paste_deploy.flavor and 'cache' in CONF.paste_deploy.flavor: - if is_centralized_db_driver and not CONF.worker_self_reference_url: - msg = _("'worker_self_reference_url' needs to be set " - "if `centralized_db` is defined as cache driver " - "for image_cache_driver config option.") - raise RuntimeError(msg) + if is_centralized_db_driver and not CONF.worker_self_reference_url: + msg = _("'worker_self_reference_url' needs to be set " + "if `centralized_db` is defined as cache driver " + "for image_cache_driver config option.") + raise RuntimeError(msg) return is_centralized_db_driver diff --git a/glance/tests/unit/test_sqlite_migration.py b/glance/tests/unit/test_sqlite_migration.py index b878eb4b72..1a0047908b 100644 --- a/glance/tests/unit/test_sqlite_migration.py +++ b/glance/tests/unit/test_sqlite_migration.py @@ -101,10 +101,16 @@ class TestMigrate(test_utils.BaseTestCase): self.config(image_cache_driver="sqlite") self.assertFalse(sqlite_migration.migrate_if_required()) + def test_migrate_if_required_cache_disabled(self): + self.config(flavor="keystone", group="paste_deploy") + self.config(image_cache_driver="centralized_db") + self.assertFalse(sqlite_migration.migrate_if_required()) + @mock.patch('os.path.exists') @mock.patch('os.path.join', new=mock.MagicMock()) def test_migrate_if_required_db_not_found(self, mock_exists): mock_exists.return_value = False + self.config(flavor="keystone+cache", group="paste_deploy") self.config(image_cache_driver="centralized_db") with mock.patch.object(sqlite_migration, 'LOG') as mock_log: sqlite_migration.migrate_if_required()