From e79675c24022a7148575c74110872b6450f550a2 Mon Sep 17 00:00:00 2001 From: Antoine Lambert <anlambert@softwareheritage.org> Date: Thu, 13 Jul 2023 14:54:36 +0200 Subject: [PATCH 1/2] backend: Move postgresql backend initialization in a separate class Since commit swh/devel/swh-core@89d48572, the "swh db init" command attempts to instantiate the postgresql backend of a swh module using the get_datastore function of the module with a "cls" and "db" parameters. While it works fine for most of swh modules, it does not for the vault as more parameters are expected by the "get_vault" function and thus the database init is failing. The issue was spotted in the docker environment after updating the swh/stack image. So extract postgresql backend initialization for the vault in a new class named VaultBackendDataStore and set it as swh.vault.get_datastore attribute value. --- swh/vault/__init__.py | 4 +++- swh/vault/backend.py | 19 ++++++++++++++----- swh/vault/cookers/__init__.py | 3 ++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/swh/vault/__init__.py b/swh/vault/__init__.py index 425a5b2..5f6bdef 100644 --- a/swh/vault/__init__.py +++ b/swh/vault/__init__.py @@ -10,6 +10,8 @@ import logging from typing import Dict import warnings +from swh.vault.backend import VaultBackendDataStore + logger = logging.getLogger(__name__) @@ -57,4 +59,4 @@ def get_vault(cls: str = "remote", **kwargs): return Vault(**kwargs) -get_datastore = get_vault +get_datastore = VaultBackendDataStore diff --git a/swh/vault/backend.py b/swh/vault/backend.py index 5c00fa0..c0afd81 100644 --- a/swh/vault/backend.py +++ b/swh/vault/backend.py @@ -66,18 +66,15 @@ The Software Heritage Developers """ -class VaultBackend: +class VaultBackendDataStore: """ - Backend for the Software Heritage Vault. + PostgreSQL backend for the Software Heritage Vault. """ current_version = 4 def __init__(self, **config): self.config = config - self.cache = VaultCache(**config["cache"]) - self.scheduler = get_scheduler(**config["scheduler"]) - self.storage = get_storage(**config["storage"]) if "db" not in self.config: raise ValueError( @@ -102,6 +99,18 @@ class VaultBackend: if db is not self._db: db.put_conn() + +class VaultBackend(VaultBackendDataStore): + """ + Backend for the Software Heritage Vault. + """ + + def __init__(self, **config): + super().__init__(**config) + self.cache = VaultCache(**config["cache"]) + self.scheduler = get_scheduler(**config["scheduler"]) + self.storage = get_storage(**config["storage"]) + @db_transaction() def progress( self, diff --git a/swh/vault/cookers/__init__.py b/swh/vault/cookers/__init__.py index 9689d96..1053628 100644 --- a/swh/vault/cookers/__init__.py +++ b/swh/vault/cookers/__init__.py @@ -12,7 +12,6 @@ from swh.core.config import load_named_config from swh.core.config import read as read_config from swh.model.swhids import CoreSWHID, ObjectType from swh.storage import get_storage -from swh.vault import get_vault from swh.vault.cookers.base import DEFAULT_CONFIG, DEFAULT_CONFIG_PATH, BaseVaultCooker from swh.vault.cookers.directory import DirectoryCooker from swh.vault.cookers.git_bare import GitBareCooker @@ -98,6 +97,8 @@ def get_cooker(bundle_type: str, swhid: CoreSWHID): EnvironmentError in case the vault configuration reference a non remote class. """ + from swh.vault import get_vault + if "SWH_CONFIG_FILENAME" in os.environ: cfg = read_config(os.environ["SWH_CONFIG_FILENAME"], DEFAULT_CONFIG) else: -- GitLab From cac3766c99c339896747ea6d89d2ce33f4faded7 Mon Sep 17 00:00:00 2001 From: Antoine Lambert <anlambert@softwareheritage.org> Date: Thu, 13 Jul 2023 16:08:51 +0200 Subject: [PATCH 2/2] s/VaultBackendDataStore/VaultDB/ --- swh/vault/__init__.py | 4 ++-- swh/vault/backend.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/swh/vault/__init__.py b/swh/vault/__init__.py index 5f6bdef..96b9550 100644 --- a/swh/vault/__init__.py +++ b/swh/vault/__init__.py @@ -10,7 +10,7 @@ import logging from typing import Dict import warnings -from swh.vault.backend import VaultBackendDataStore +from swh.vault.backend import VaultDB logger = logging.getLogger(__name__) @@ -59,4 +59,4 @@ def get_vault(cls: str = "remote", **kwargs): return Vault(**kwargs) -get_datastore = VaultBackendDataStore +get_datastore = VaultDB diff --git a/swh/vault/backend.py b/swh/vault/backend.py index c0afd81..a14d349 100644 --- a/swh/vault/backend.py +++ b/swh/vault/backend.py @@ -66,7 +66,7 @@ The Software Heritage Developers """ -class VaultBackendDataStore: +class VaultDB: """ PostgreSQL backend for the Software Heritage Vault. """ @@ -100,7 +100,7 @@ class VaultBackendDataStore: db.put_conn() -class VaultBackend(VaultBackendDataStore): +class VaultBackend(VaultDB): """ Backend for the Software Heritage Vault. """ -- GitLab