Skip to content

MGMT-22783: add pytest e2e test suite for vmaas - #18

Merged
openshift-merge-bot[bot] merged 1 commit into
osac-project:mainfrom
omer-vishlitzky:feature/pytest-e2e-mgmt-22783
Mar 24, 2026
Merged

openshift-merge-bot[bot] merged 1 commit into
osac-project:mainfrom
omer-vishlitzky:feature/pytest-e2e-mgmt-22783

Conversation

@omer-vishlitzky

@omer-vishlitzky omer-vishlitzky commented Mar 22, 2026 •

Copy link
Copy Markdown
Contributor

https://redhat.atlassian.net/browse/MGMT-22783

Port all ansible e2e tests to pytest with 1:1 parity. The hub creation test was removed — hub creation is implicitly verified by every compute instance test since they all go through the fulfillment api on the hub.

Tests support a two-cluster topology where the hub cluster runs the osac operator and the remote cluster runs the kubevirt vms. The k8s client takes a kubeconfig parameter, and tests that need to inspect vms on the remote cluster use a separate OSAC_VM_KUBECONFIG env var. See MGMT-23623 for the remote cluster setup script.

Tests:

  • compute instance lifecycle (create, wait for running, delete)
  • delete during provision
  • restart (trigger via grpc, verify new vmi creation timestamp)
  • restart negative (past timestamp ignored)
  • api fields (explicit cpu/memory/disk via grpc)
  • cli fields (explicit cpu/memory/disk via fulfillment-cli)

@openshift-ci-robot

openshift-ci-robot commented Mar 22, 2026 •

Copy link
Copy Markdown

@omer-vishlitzky: This pull request references MGMT-22783 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.22.0" version, but no target version was set.

Details

In response to this:

https://redhat.atlassian.net/browse/MGMT-22783

Port all ansible e2e tests to pytest with 1:1 parity. The hub creation test was removed — hub creation is implicitly verified by every compute instance test since they all go through the fulfillment api on the hub.

Tests support a two-cluster topology where the hub cluster runs the osac operator and the remote cluster runs the kubevirt VMs. The k8s client takes a kubeconfig parameter, and tests that need to inspect VMs on the remote cluster use a separate OSAC_VM_KUBECONFIG env var. See MGMT-23623 for the remote cluster setup script.

Tests

  • compute instance lifecycle (create, wait for running, delete)
  • delete during provision
  • restart (trigger via grpc, verify new vmi creation timestamp)
  • restart negative (past timestamp ignored)
  • api fields (explicit cpu/memory/disk via grpc)
  • cli fields (explicit cpu/memory/disk via fulfillment-cli)

Infrastructure

  • k8s client with two-kubeconfig support (hub + remote)
  • grpc client wrapping grpcurl
  • fulfillment-cli wrapper with typed methods
  • poll_until helper matching ansible retry semantics
  • Makefile with MAKEFILE_TARGET dispatch for ci
  • pyproject.toml with ruff and basedpyright config

Verified

All 6 tests pass on a two-cluster deployment (hub SNO + remote virt cluster) with fulfillment-service v0.0.48 and latest operator.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci
openshift-ci Bot requested review from jhernand and trewest March 22, 2026 02:44
@openshift-ci-robot

openshift-ci-robot commented Mar 22, 2026 •

Copy link
Copy Markdown

@omer-vishlitzky: This pull request references MGMT-22783 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.22.0" version, but no target version was set.

Details

In response to this:

https://redhat.atlassian.net/browse/MGMT-22783

Port all ansible e2e tests to pytest with 1:1 parity. The hub creation test was removed — hub creation is implicitly verified by every compute instance test since they all go through the fulfillment api on the hub.

Tests support a two-cluster topology where the hub cluster runs the osac operator and the remote cluster runs the kubevirt vms. The k8s client takes a kubeconfig parameter, and tests that need to inspect vms on the remote cluster use a separate OSAC_VM_KUBECONFIG env var. See MGMT-23623 for the remote cluster setup script.

Tests:

  • compute instance lifecycle (create, wait for running, delete)
  • delete during provision
  • restart (trigger via grpc, verify new vmi creation timestamp)
  • restart negative (past timestamp ignored)
  • api fields (explicit cpu/memory/disk via grpc)
  • cli fields (explicit cpu/memory/disk via fulfillment-cli)

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@omer-vishlitzky
omer-vishlitzky force-pushed the feature/pytest-e2e-mgmt-22783 branch 6 times, most recently from b535310 to fbbdafe Compare March 22, 2026 10:07

@eranco74 eranco74 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well-structured pytest port with solid architecture (runner/client abstraction layers, two-kubeconfig design). A few items to address:

Must fix

k8s_virt_client crashes with KeyError when OSAC_VM_KUBECONFIG is not set (conftest.py:51)
os.environ["OSAC_VM_KUBECONFIG"] raises a raw KeyError if the env var is missing, but the README says it defaults to the hub kubeconfig. Fix:

vm_kubeconfig = os.environ.get("OSAC_VM_KUBECONFIG")
return K8sClient(namespace=namespace, kubeconfig=vm_kubeconfig)

Should fix

No cleanup on test failure
If a test fails after creating a compute instance but before the cleanup section, the resource leaks. Over time this causes resource exhaustion in CI. Use request.addfinalizer() or yield fixtures for cleanup.

cli fixture duplicates fulfillment_address derivation (conftest.py)
The cli fixture re-derives the fulfillment address instead of depending on the existing fulfillment_address fixture. Use the fixture to avoid duplication and potential inconsistency.

Worth noting

  • Session-scoped token with --duration 1h may expire during long test runs (total possible poll time across all tests exceeds 1h)
  • run_unchecked mixes stdout/stderr into one string — works now but fragile for assertions that match on error messages
  • UUID parsing from CLI output (re.search(r"'([^']+)'", stdout)) could silently grab wrong value if output format changes; a UUID regex would be safer
  • Inconsistent resource type references: "computeinstance" vs "computeinstance.osac.openshift.io" — pick one convention
  • No lock file committed despite uv sync in README — builds not reproducible

@omer-vishlitzky
omer-vishlitzky force-pushed the feature/pytest-e2e-mgmt-22783 branch from fbbdafe to 9666318 Compare March 22, 2026 21:59
@omer-vishlitzky

Copy link
Copy Markdown
Contributor Author
  1. k8s_virt_client crashes intentionally on a missing env var, this is a test setup, I want to fail fast. changed the readme to reflect that this env var should always be set though
  2. cleanup is redundant, this is going to run in the ci environment, baremetal machines are simply returned to the pool
  3. fixed the fixtures

omer-vishlitzky added a commit to omer-vishlitzky/osac-test-infra that referenced this pull request Mar 23, 2026
Self-contained image with all tools needed to run the
e2e test suite on a bare metal machine via podman.

Depends on osac-project#18 (pyproject.toml and uv.lock must exist).
@omer-vishlitzky
omer-vishlitzky force-pushed the feature/pytest-e2e-mgmt-22783 branch 2 times, most recently from fc33812 to 2f75918 Compare March 23, 2026 06:35
@omer-vishlitzky

Copy link
Copy Markdown
Contributor Author

/hold
waiting for @adriengentil review

@openshift-ci openshift-ci Bot added the do-not-merge/hold Block merge until the label is removed label Mar 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about BDD? I think it would be great to have way to express test in this way, for example like in NetworkManager repo: https://gitlab.freedesktop.org/NetworkManager/NetworkManager-ci/-/merge_requests/1971/diffs

Comment thread tests/grpc_client.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we build a python fulfillment-service client from the proto files?

Comment thread tests/k8s_client.py
self.kubeconfig: str | None = kubeconfig

def _base(self) -> list[str]:
args: list[str] = ["kubectl"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use python k8s client?

Comment thread tests/fulfillment_cli.py Outdated
run_strategy,
]
if user_data_secret_ref is not None:
args.extend(["--user-data-secret-ref", user_data_secret_ref])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
args.extend(["--user-data-secret-ref", user_data_secret_ref])
args.extend(["--user-data", user_data_secret_ref])

it was renamed in osac-project/fulfillment-service#333

@eranco74 eranco74 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous concerns addressed or reasonably justified:

  • ✅ cli fixture duplication — fixed, now uses fulfillment_address fixture
  • ✅ Resource type consistency — standardized on "computeinstance"
  • ✅ Lock file — uv.lock committed
  • ⚠️ k8s_virt_client KeyError — intentional fail-fast, README updated to mark as required
  • ❌ Cleanup on failure — CI-only, machines returned to pool, acceptable

LGTM. The remaining items (token expiry, stdout/stderr mixing, UUID parsing) are minor and can be improved in follow-ups. adriengentil's architectural suggestions (native Python clients, BDD) are good long-term goals but out of scope here.

@openshift-ci openshift-ci Bot added the lgtm label Mar 23, 2026
@omer-vishlitzky
omer-vishlitzky force-pushed the feature/pytest-e2e-mgmt-22783 branch from 2f75918 to 5525d27 Compare March 23, 2026 14:35
@openshift-ci openshift-ci Bot removed the lgtm label Mar 23, 2026
Port all ansible e2e tests to pytest with 1:1 parity. The hub
creation test was removed — hub creation is implicitly verified by
every compute instance test since they all go through the fulfillment
api on the hub.

Tests support a two-cluster topology where the hub cluster runs the
osac operator and the remote cluster runs the kubevirt VMs. The k8s
client takes a kubeconfig parameter, and tests that need to inspect
VMs on the remote cluster use a separate OSAC_VM_KUBECONFIG env var.
See MGMT-23623 for the remote cluster setup script.

Tests:
- compute instance lifecycle (create, wait for running, delete)
- delete during provision
- restart (trigger via grpc, verify new vmi creation timestamp)
- restart negative (past timestamp ignored)
- api fields (explicit cpu/memory/disk via grpc)
- cli fields (explicit cpu/memory/disk via fulfillment-cli)

Infrastructure:
- k8s client with two-kubeconfig support (hub + remote)
- grpc client wrapping grpcurl
- fulfillment-cli wrapper with typed methods
- poll_until helper matching ansible retry semantics
- Makefile with MAKEFILE_TARGET dispatch for ci
- pyproject.toml with ruff and basedpyright config
@omer-vishlitzky
omer-vishlitzky force-pushed the feature/pytest-e2e-mgmt-22783 branch from 5525d27 to 19c02cf Compare March 23, 2026 14:50
@openshift-ci

openshift-ci Bot commented Mar 24, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adriengentil, eranco74, omer-vishlitzky

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@omer-vishlitzky

Copy link
Copy Markdown
Contributor Author

/unhold

@openshift-ci openshift-ci Bot removed the do-not-merge/hold Block merge until the label is removed label Mar 24, 2026
@openshift-merge-bot
openshift-merge-bot Bot merged commit 2af0881 into osac-project:main Mar 24, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants