Skip to content
Snippets Groups Projects
Commit 1614bb65 authored by Antoine Lambert's avatar Antoine Lambert
Browse files

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.
parent 4054c8b1
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,8 @@ import logging
from typing import Dict
import warnings
from swh.vault.backend import VaultDB
logger = logging.getLogger(__name__)
......@@ -57,4 +59,4 @@ def get_vault(cls: str = "remote", **kwargs):
return Vault(**kwargs)
get_datastore = get_vault
get_datastore = VaultDB
......@@ -66,18 +66,15 @@ The Software Heritage Developers
"""
class VaultBackend:
class VaultDB:
"""
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(VaultDB):
"""
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,
......
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment