Skip to content
Draft
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f3e089d
Initial pytest test migration
jvpasinatto Sep 23, 2025
7bdf097
Merge branch 'main' into pytest-complete
jvpasinatto Sep 23, 2025
fb96a0c
Refactor to adress comments
jvpasinatto Sep 24, 2025
1fc136f
Merge branch 'main' into pytest-complete
jvpasinatto Sep 24, 2025
37aa18d
Make wait more robust
jvpasinatto Sep 25, 2025
c784bf0
Add liveness test
jvpasinatto Sep 26, 2025
4b4bf43
Merge branch 'main' into pytest-complete
gkech Jan 23, 2026
cafa5f4
Add python rules in makefile
jvpasinatto Jan 23, 2026
ab14a77
update dependencies
jvpasinatto Jan 23, 2026
8fabdbe
Add more type hints
jvpasinatto Jan 23, 2026
9195e8a
Print env vars in test initialization and more
jvpasinatto Jan 23, 2026
b572b0d
Add resources collection on failure
jvpasinatto Jan 23, 2026
44858f8
move python scripts to folder
jvpasinatto Jan 29, 2026
ad7521d
fix liveness test and add more type hints
jvpasinatto Jan 29, 2026
9adffbc
fix init deploy test
jvpasinatto Jan 29, 2026
70d4f06
add py-fmt rule
jvpasinatto Jan 29, 2026
974c0d1
Update test readme and small fixes
jvpasinatto Jan 30, 2026
11eed52
use rich to handle logging
jvpasinatto Jan 30, 2026
8a100f3
Add bash wrapper
jvpasinatto Jan 30, 2026
ad60319
update lock file
jvpasinatto Jan 30, 2026
ba739c0
fix openshift detection
jvpasinatto Jan 30, 2026
a8cd1d4
divide tools into separated files plus improvements
jvpasinatto Feb 2, 2026
079499c
Fix report generation
jvpasinatto Feb 3, 2026
9a7560b
Merge branch 'main' into pytest-complete
jvpasinatto Feb 4, 2026
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
31 changes: 31 additions & 0 deletions .github/workflows/e2e-py-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: e2e-tests Python Quality Check

on:
pull_request:
paths:
- 'e2e-tests/**/*.py'

jobs:
quality-check:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: "pyproject.toml"

- name: Install dependencies
run: uv sync --locked

- name: Run ruff check
run: uv run ruff check e2e-tests/

- name: Run mypy
run: uv run mypy e2e-tests/
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,7 @@ bin/
projects/
installers/olm/operator_*.yaml
installers/olm/bundles

# Test Reports
e2e-tests/reports/
e2e-tests/**/__pycache__/
75 changes: 46 additions & 29 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void createCluster(String CLUSTER_SUFFIX) {
--preemptible \
--zone=${region} \
--machine-type='n1-standard-4' \
--cluster-version='1.31' \
--cluster-version='1.32' \
--num-nodes=3 \
--labels='delete-cluster-after-hours=6' \
--disk-size=30 \
Expand Down Expand Up @@ -101,6 +101,16 @@ void pushLogFile(String FILE_NAME) {
}
}

void pushReportFile() {
echo "Push final_report.html to S3!"
withCredentials([aws(credentialsId: 'AMI/OVF', accessKeyVariable: 'AWS_ACCESS_KEY_ID', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY')]) {
sh """
S3_PATH=s3://percona-jenkins-artifactory-public/\$JOB_NAME/\$(git rev-parse --short HEAD)
aws s3 cp --content-type text/html --quiet final_report.html \$S3_PATH/final_report.html || :
"""
}
}

void pushArtifactFile(String FILE_NAME) {
echo "Push $FILE_NAME file to S3!"

Expand Down Expand Up @@ -146,24 +156,6 @@ void markPassedTests() {
}
}

void printKubernetesStatus(String LOCATION, String CLUSTER_SUFFIX) {
sh """
export KUBECONFIG=/tmp/${CLUSTER_NAME}-${CLUSTER_SUFFIX}
echo "========== KUBERNETES STATUS $LOCATION TEST =========="
gcloud container clusters list|grep -E "NAME|${CLUSTER_NAME}-${CLUSTER_SUFFIX} "
echo
kubectl get nodes
echo
kubectl top nodes
echo
kubectl get pods --all-namespaces
echo
kubectl top pod --all-namespaces
echo
kubectl get events --field-selector type!=Normal --all-namespaces --sort-by=".lastTimestamp"
echo "======================================================"
"""
}

String formatTime(def time) {
if (!time || time == "N/A") return "N/A"
Expand Down Expand Up @@ -258,15 +250,24 @@ void runTest(Integer TEST_ID) {
export DEBUG_TESTS=1
fi
export KUBECONFIG=/tmp/${CLUSTER_NAME}-${clusterSuffix}
time ./e2e-tests/$testName/run
export PATH="\$HOME/.local/bin:\$PATH"
mkdir -p e2e-tests/reports

REPORT_OPTS="--html=e2e-tests/reports/${testName}.html --junitxml=e2e-tests/reports/${testName}.xml"

# Run native pytest if test_*.py exists, otherwise run bash via wrapper
if ls e2e-tests/$testName/test_*.py 1>/dev/null 2>&1; then
uv run pytest e2e-tests/$testName/ \$REPORT_OPTS
else
uv run pytest e2e-tests/test_pytest_wrapper.py --test-name=$testName \$REPORT_OPTS
fi
"""
}
pushArtifactFile("${env.GIT_BRANCH}-${env.GIT_SHORT_COMMIT}-$testName")
tests[TEST_ID]["result"] = "passed"
return true
}
catch (exc) {
printKubernetesStatus("AFTER","$clusterSuffix")
echo "Test $testName has failed!"
if (retryCount >= 1 || currentBuild.nextBuild != null) {
currentBuild.result = 'FAILURE'
Expand All @@ -290,7 +291,7 @@ void prepareNode() {
sudo curl -sLo /usr/local/bin/kubectl https://dl.k8s.io/release/\$(curl -Ls https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl && sudo chmod +x /usr/local/bin/kubectl
kubectl version --client --output=yaml

curl -fsSL https://get.helm.sh/helm-v3.19.0-linux-amd64.tar.gz | sudo tar -C /usr/local/bin --strip-components 1 -xzf - linux-amd64/helm
curl -fsSL https://get.helm.sh/helm-v3.20.0-linux-amd64.tar.gz | sudo tar -C /usr/local/bin --strip-components 1 -xzf - linux-amd64/helm

sudo curl -fsSL https://github.com/mikefarah/yq/releases/download/v4.48.1/yq_linux_amd64 -o /usr/local/bin/yq && sudo chmod +x /usr/local/bin/yq
sudo curl -fsSL https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux64 -o /usr/local/bin/jq && sudo chmod +x /usr/local/bin/jq
Expand All @@ -307,6 +308,10 @@ EOF
sudo yum install -y google-cloud-cli google-cloud-cli-gke-gcloud-auth-plugin

curl -sL https://github.com/mitchellh/golicense/releases/latest/download/golicense_0.2.0_linux_x86_64.tar.gz | sudo tar -C /usr/local/bin -xzf - golicense

curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="\$HOME/.local/bin:\$PATH"
uv sync --locked
"""
installAzureCLI()
azureAuth()
Expand Down Expand Up @@ -423,10 +428,10 @@ pipeline {
CLOUDSDK_CORE_DISABLE_PROMPTS = 1
CLEAN_NAMESPACE = 1
OPERATOR_NS = 'psmdb-operator'
GIT_SHORT_COMMIT = sh(script: 'git rev-parse --short HEAD', , returnStdout: true).trim()
GIT_SHORT_COMMIT = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
VERSION = "${env.GIT_BRANCH}-${env.GIT_SHORT_COMMIT}"
CLUSTER_NAME = sh(script: "echo jen-psmdb-${env.CHANGE_ID}-${GIT_SHORT_COMMIT}-${env.BUILD_NUMBER} | tr '[:upper:]' '[:lower:]'", , returnStdout: true).trim()
AUTHOR_NAME = sh(script: "echo ${CHANGE_AUTHOR_EMAIL} | awk -F'@' '{print \$1}'", , returnStdout: true).trim()
CLUSTER_NAME = sh(script: "echo jen-psmdb-${env.CHANGE_ID}-${GIT_SHORT_COMMIT}-${env.BUILD_NUMBER} | tr '[:upper:]' '[:lower:]'", returnStdout: true).trim()
AUTHOR_NAME = sh(script: "echo ${CHANGE_AUTHOR_EMAIL} | awk -F'@' '{print \$1}'", returnStdout: true).trim()
ENABLE_LOGGING = "true"
}
agent {
Expand Down Expand Up @@ -458,7 +463,7 @@ pipeline {
prepareNode()
script {
if (AUTHOR_NAME == 'null') {
AUTHOR_NAME = sh(script: "git show -s --pretty=%ae | awk -F'@' '{print \$1}'", , returnStdout: true).trim()
AUTHOR_NAME = sh(script: "git show -s --pretty=%ae | awk -F'@' '{print \$1}'", returnStdout: true).trim()
}
for (comment in pullRequest.comments) {
println("Author: ${comment.user}, Comment: ${comment.body}")
Expand Down Expand Up @@ -675,12 +680,24 @@ pipeline {
}
}
makeReport()
junit testResults: '*.xml', healthScaleFactor: 1.0
archiveArtifacts '*.xml'

if (fileExists('e2e-tests/reports')) {
sh """
export PATH="\$HOME/.local/bin:\$PATH"
uv run pytest_html_merger -i e2e-tests/reports -o final_report.html
uv run junitparser merge --glob 'e2e-tests/reports/*.xml' final_report.xml
"""
junit testResults: 'final_report.xml', healthScaleFactor: 1.0
archiveArtifacts 'final_report.xml, final_report.html'
pushReportFile()
} else {
junit testResults: '*.xml', healthScaleFactor: 1.0
archiveArtifacts '*.xml'
}

unstash 'IMAGE'
def IMAGE = sh(returnStdout: true, script: "cat results/docker/TAG").trim()
TestsReport = TestsReport + "\r\n\r\ncommit: ${env.CHANGE_URL}/commits/${env.GIT_COMMIT}\r\nimage: `${IMAGE}`\r\n"
TestsReport = TestsReport + "\r\n\r\nCommit: ${env.CHANGE_URL}/commits/${env.GIT_COMMIT}\r\nImage: `${IMAGE}`\r\nTest report: [report](${testUrlPrefix}/${env.GIT_BRANCH}/${env.GIT_SHORT_COMMIT}/final_report.html)\r\n"
pullRequest.comment(TestsReport)
}
deleteOldClusters("$CLUSTER_NAME")
Expand Down
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ undeploy: ## Undeploy operator
test: envtest generate ## Run tests.
DISABLE_TELEMETRY=true KUBEBUILDER_ASSETS="$(shell $(ENVTEST) --arch=amd64 use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out

py-deps: uv ## Install e2e-tests Python dependencies
$(UV) sync --locked

py-update-deps: uv ## Update e2e-tests Python dependencies
$(UV) lock --upgrade

py-fmt: uv ## Format and organize imports in e2e-tests
$(UV) run ruff check --select I --fix e2e-tests/
$(UV) run ruff format e2e-tests/

py-check: uv ## Run ruff and mypy checks on e2e-tests
$(UV) run ruff check e2e-tests/
$(UV) run mypy e2e-tests/

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
Expand Down Expand Up @@ -104,6 +118,13 @@ MOCKGEN = $(shell pwd)/bin/mockgen
mockgen: ## Download mockgen locally if necessary.
$(call go-get-tool,$(MOCKGEN), github.com/golang/mock/mockgen@latest)

UV = $(shell pwd)/bin/uv
uv: ## Download uv locally if necessary.
@[ -f $(UV) ] || { \
set -e ;\
curl -LsSf https://astral.sh/uv/install.sh | UV_INSTALL_DIR=$(PROJECT_DIR)/bin sh ;\
}

# Prepare release
include e2e-tests/release_versions
CERT_MANAGER_VER := $(shell grep -Eo "cert-manager v.*" go.mod|grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")
Expand Down
61 changes: 60 additions & 1 deletion e2e-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,65 @@ Test execution produces excessive output. It is recommended to redirect the outp
./e2e-tests/run >> /tmp/tests-run.out 2>&1
```

## Python development setup

The e2e tests are being migrated to pytest. This section covers setting up the Python environment.

### Installing uv

[uv](https://github.com/astral-sh/uv) is used for Python dependency management. Install it via make:

```
make uv
```

Or manually:

```
curl -LsSf https://astral.sh/uv/install.sh | sh
```

### Python make targets

```
make py-deps # Install Python dependencies (locked versions)
make py-update-deps # Update Python dependencies
make py-fmt # Format code and organize imports with ruff
make py-check # Run ruff linter and mypy type checks
```

### Running tests with pytest

First, install dependencies:

```
make py-deps
```

Run all pytest-based tests:

```
uv run pytest e2e-tests/
```

Run a specific test file:

```
uv run pytest e2e-tests/init-deploy/test_init_deploy.py
```

Run a specific test:

```
uv run pytest e2e-tests/init-deploy/test_init_deploy.py::TestInitDeploy::test_cluster_creation
```

Run tests matching a pattern:

```
uv run pytest e2e-tests/ -k "init"
```

## Using environment variables to customize the testing process

### Re-declaring default image names
Expand All @@ -129,7 +188,7 @@ You can use environment variables to re-declare all default images used for test
full list of variables is the following one:

* `IMAGE` - Percona Server for MongoDB Operator, `perconalab/percona-server-mongodb-operator:main` by default,
* `IMAGE_MONGOD` - mongod, `perconalab/percona-server-mongodb-operator:main-mongod4.4` by default,
* `IMAGE_MONGOD` - mongod, `perconalab/percona-server-mongodb-operator:main-mongod8.0` by default,
* `IMAGE_PMM_CLIENT` - Percona Monitoring and Management (PMM) client, `perconalab/pmm-client:dev-latest` by default,
* `IMAGE_BACKUP` - backup, `perconalab/percona-server-mongodb-operator:main-backup` by default,

Expand Down
Loading
Loading