Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import shutil
import stat
import subprocess
import typing
from dataclasses import dataclass
from pathlib import Path
from typing import Optional
Expand Down Expand Up @@ -48,10 +49,14 @@ def _check_testgres_api():


def _run(cmd, check=True, capture=False):
kwargs = {"check": check, "text": True}
if capture:
kwargs.update(stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return subprocess.run(list(cmd), **kwargs)
pipe = subprocess.PIPE if capture else None
return subprocess.run(
list(cmd),
check=check,
text=True,
stdout=pipe,
stderr=pipe,
)


def _which(name):
Expand Down Expand Up @@ -111,10 +116,7 @@ def remove_node(self, cgroup):
cgroup.rmdir()

def cleanup_root(self):
try:
self.root.rmdir()
except OSError:
pass
raise NotImplementedError


class CgroupV2IO(CgroupIOBackend):
Expand Down Expand Up @@ -161,6 +163,12 @@ def kill_node(self, cgroup):
except OSError:
pass

def cleanup_root(self):
try:
self.root.rmdir()
except OSError:
pass


class CgroupV1Blkio(CgroupIOBackend):
version = 1
Expand Down Expand Up @@ -194,6 +202,12 @@ def apply_limits(self, cgroup, device, limits):
def membership_file(self, cgroup):
return cgroup / "tasks"

def cleanup_root(self):
try:
self.root.rmdir()
except OSError:
pass


def detect_cgroup_io_backend():
# Pure/unified v2 has cgroup.controllers at the top-level mount.
Expand Down Expand Up @@ -236,14 +250,17 @@ def __init__(self, namespace, os_user, db_user, cgroup=None, cgroup_membership_f
# runuser.
self._username = db_user

def environ(self, name):
def environ(
self,
var_name: str,
) -> typing.Optional[str]:
# target_os_ops may be asked to resolve PostgreSQL binaries while a
# replica is being cloned. Expose the PgLab-specific bin directory to
# Testgres without requiring the caller to mutate the process-wide
# PG_BIN environment variable.
if name == "PG_BIN" and self.pg_bin is not None:
if var_name == "PG_BIN" and self.pg_bin is not None:
return self.pg_bin
return super().environ(name)
return super().environ(var_name)

def mkdtemp(self, prefix=None):
assert prefix is None or type(prefix) is str
Expand Down Expand Up @@ -473,7 +490,7 @@ def __init__(
self.os_user = os_user
self.db_superuser = db_superuser or os_user
self.keep_data = keep_data
self.nodes = {} # type: Dict[str, LabNode]
self.nodes: typing.Dict[str, LabNode] = {}
self._created_bridge = False
self._closed = False
self._firewall_backend = None
Expand Down
4 changes: 4 additions & 0 deletions tools/verify_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
node_mod = importlib.import_module("testgres.node")
backup_mod = importlib.import_module("testgres.backup")

assert type(node_mod.__file__) is str
assert type(backup_mod.__file__) is str
assert type(pglab.__file__) is str

print("Python: {}".format(sys.version.split()[0]))
print("Testgres: {}".format(testgres_ver))
print("Testgres node: {}".format(Path(node_mod.__file__).resolve()))
Expand Down