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
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 5
137 changes: 137 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: CI

on:
push:
branches: [ "main" ]
paths-ignore:
- "**/*.md"

pull_request:
branches: [ "main" ]
paths-ignore:
- "**/*.md"

jobs:
lint:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]

steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 flake8-pyproject ruff==0.15.22
- name: Lint with flake8
run: |
flake8 .
- name: Lint with ruff
run: |
ruff check .

build-check:
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout
uses: actions/checkout@v7

- name: Set up Python 3.12
uses: actions/setup-python@v7
with:
python-version: "3.12"
cache: 'pip'

- name: Install build tools
run: |
python -m pip install --upgrade pip
python -m pip install build twine

- name: Build package
run: |
python -m build

- name: Check package metadata
run: |
twine check dist/*

test-pglab:
runs-on: ubuntu-24.04
name: "test: pglab | ubuntu-24.04 | pg16 | py${{ matrix.python-version }}"
needs: build-check
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]

steps:
- name: Checkout
uses: actions/checkout@v7

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install PostgreSQL and PgLab system dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
postgresql-16 \
postgresql-client-16 \
libpq-dev \
iproute2 \
iputils-ping \
iptables \
util-linux

- name: Install Python test dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r tests/requirements.txt

- name: PgLab preflight
run: |
set -eux
"$(pg_config --bindir)/postgres" --version
pg_config --bindir
findmnt -n -o SOURCE,FSTYPE -T /var/tmp
mount | grep cgroup || true
cat /sys/fs/cgroup/cgroup.controllers
cat /sys/fs/cgroup/cgroup.subtree_control || true

- name: Run privileged PgLab tests
run: |
set -eux
mkdir -p "${{ github.workspace }}/logs-pglab"
PYTHON="$(command -v python)"
PG_BIN="$(pg_config --bindir)"
sudo env \
PATH="$PATH" \
TESTGRES_PGLAB_TESTS=1 \
PG_BIN="$PG_BIN" \
PGLAB_OS_USER="$USER" \
PGLAB_DB_USER=postgres \
PGLAB_TEST_ROOT=/var/tmp \
TEST_CFG__LOG_DIR="${{ github.workspace }}/logs-pglab" \
"$PYTHON" -m pytest -vv -s tests

- name: Upload PgLab logs
uses: actions/upload-artifact@v7
if: always()
with:
name: testgres--pglab-logs--py${{ matrix.python-version }}--id${{ github.run_id }}
path: logs-pglab/
70 changes: 70 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# This workflow will upload a Python Package to PyPI when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
release-build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v7

- uses: actions/setup-python@v7
with:
python-version: "3.x"

- name: Build release distributions
run: |
# NOTE: put your own distribution build steps here.
python -m pip install build
python -m build

- name: Upload distributions
uses: actions/upload-artifact@v7
with:
name: release-dists
path: dist/

pypi-publish:
runs-on: ubuntu-latest
needs:
- release-build
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write

# Dedicated environments with protections for publishing are strongly recommended.
# For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
environment:
name: pypi
# OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
# url: https://pypi.org/p/YOURPROJECT
#
# ALTERNATIVE: if your GitHub Release name is the PyPI project version string
# ALTERNATIVE: exactly, uncomment the following line instead:
# url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }}

steps:
- name: Retrieve release distributions
uses: actions/download-artifact@v8
with:
name: release-dists
path: dist/

- name: Publish release distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/
2 changes: 1 addition & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
from pathlib import Path

from pglab import PgLab
from src import PgLab


def need_env(name):
Expand Down
32 changes: 25 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
[build-system]
requires = ["setuptools>=77"]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[tool.setuptools.package-dir]
"testgres_exts.pglab" = "src"

[tool.setuptools.dynamic]
version = {attr = "testgres_exts.pglab.__version__"}

[project]
name = "testgres-pglab"
version = "0.1.0"
name = "testgres_exts.pglab"
dynamic = ["version"]
description = "Linux netns/cgroup/netem fault injection for PostgreSQL tests using Testgres"
readme = "README.md"
requires-python = ">=3.9"
requires-python = ">=3.8"
license = "PostgreSQL"
dependencies = [
"testgres>=1.17.0",
"testgres>=1.17,<1.18",
]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Topic :: Software Development :: Testing",
"Topic :: Database",
]
Expand All @@ -26,8 +39,13 @@ test = [
"pytest>=8,<10",
]

[tool.setuptools]
py-modules = ["pglab"]
[tool.flake8]
extend-ignore = ["E501"]
exclude = [".git", "__pycache__", "env", "venv"]

# Pytest settings
[tool.pytest.ini_options]
testpaths = ["tests"]
log_file_level = "NOTSET"
log_file_format = "%(levelname)8s [%(asctime)s] %(message)s"
log_file_date_format = "%Y-%m-%d %H:%M:%S"
2 changes: 1 addition & 1 deletion smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
from pathlib import Path

from pglab import PgLab
from src import PgLab


def need_env(name):
Expand Down
7 changes: 5 additions & 2 deletions pglab.py → src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@
import ipaddress
import os
import pwd
import shlex
import signal
import shutil
import stat
import subprocess
from dataclasses import dataclass
from pathlib import Path
from typing import Dict, Optional, Union, Any
from typing import Optional

from testgres.api import get_new_node
from testgres.backup import NodeBackup
from testgres.node import PostgresNode
from testgres.operations.local_ops import LocalOperations
import tempfile


__version__ = "0.1.0"


class PgLabError(RuntimeError):
pass

Expand Down
Empty file added tests/__init__.py
Empty file.
Loading
Loading