Repository navigation
OSAC-1561: add Metal3 backend E2E lifecycle tests #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-bot
merged 4 commits into
osac-project:main
from
carbonin:feat/OSAC-1561-bmaas-e2e-tests
Jul 16, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
660e30c
OSAC-1561: add BareMetalInstance and BareMetalHost E2E test utilities
carbonin ae7cf55
OSAC-1561: add BMaaS E2E lifecycle and power management tests
carbonin a90cdf7
OSAC-1561: add test-bmaas Makefile target and gitignore artifacts
carbonin ed89555
OSAC-1561: update Containerfile for bmaas E2E support
carbonin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,3 +22,6 @@ reports/ | |
|
|
||
| # Infrastructure backend outputs | ||
| infra/*/.env.infra | ||
|
|
||
| # Workflow artifacts | ||
| .artifacts/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import subprocess | ||
| import tempfile | ||
| import uuid | ||
| from collections.abc import Generator | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from tests.core.grpc_client import GRPCClient | ||
| from tests.core.runner import env | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def bmi_template() -> str: | ||
| return env("OSAC_BMI_TEMPLATE", "osac.templates.bm_host_provisioning") | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def bmh_namespace() -> str: | ||
| return env("OSAC_BMH_NAMESPACE", "host-inventory") | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def test_run_id() -> str: | ||
| return str(uuid.uuid4())[:8] | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def ssh_public_key() -> Generator[str, None, None]: | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| key_path = Path(tmpdir) / "bmi-test-key" | ||
| subprocess.run( | ||
| ["ssh-keygen", "-t", "ed25519", "-f", str(key_path), "-N", "", "-C", "bmi-e2e-test"], | ||
| capture_output=True, | ||
| check=True, | ||
| ) | ||
| yield (key_path.with_suffix(".pub")).read_text().strip() | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def catalog_item(private_grpc: GRPCClient, bmi_template: str, test_run_id: str) -> Generator[str, None, None]: | ||
| name = f"e2e-bmaas-{test_run_id}" | ||
| print(f"\nCreating BareMetalInstanceCatalogItem: {name}") | ||
| item_id: str = private_grpc.create_baremetal_instance_catalog_item( | ||
| name=name, | ||
| title=f"E2E BMaaS Test ({test_run_id})", | ||
| description="Temporary catalog item for BMaaS E2E tests", | ||
| template=bmi_template, | ||
| field_definitions=[{"path": "ssh_public_key", "display_name": "SSH Public Key", "editable": True}], | ||
| ) | ||
| print(f"CatalogItem created: {item_id}") | ||
|
|
||
| yield item_id | ||
|
|
||
| try: | ||
| print(f"\nDeleting BareMetalInstanceCatalogItem {item_id}...") | ||
| private_grpc.delete_baremetal_instance_catalog_item(item_id=item_id) | ||
| print(f"CatalogItem {item_id} deleted") | ||
| except Exception as e: | ||
| print(f"WARNING: Failed to delete catalog item {item_id}: {e}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from tests.core.grpc_client import GRPCClient | ||
| from tests.core.helpers import ( | ||
| wait_for_bmh_available, | ||
| wait_for_bmh_provisioned, | ||
| wait_for_bmi_cr, | ||
| wait_for_bmi_deletion, | ||
| wait_for_bmi_grpc_removal, | ||
| wait_for_bmi_running, | ||
| ) | ||
| from tests.core.k8s_client import K8sClient | ||
| from tests.core.osac_cli import OsacCLI | ||
| from tests.core.runner import poll_until | ||
|
|
||
|
|
||
| def test_baremetal_instance_lifecycle( | ||
| cli: OsacCLI, | ||
| grpc: GRPCClient, | ||
| k8s_hub_client: K8sClient, | ||
| catalog_item: str, | ||
| bmh_namespace: str, | ||
| test_run_id: str, | ||
| ssh_public_key: str, | ||
| ) -> None: | ||
| name = f"e2e-bmi-{test_run_id}" | ||
| bmi_id: str = cli.create_baremetal_instance(name=name, catalog_item=catalog_item, ssh_key=ssh_public_key) | ||
|
|
||
| try: | ||
| assert bmi_id in grpc.list_baremetal_instance_ids() | ||
|
|
||
| bmi_cr_name: str = wait_for_bmi_cr(k8s=k8s_hub_client, uuid=bmi_id) | ||
| wait_for_bmi_running(grpc=grpc, bmi_id=bmi_id) | ||
|
|
||
| external_host_id: str = k8s_hub_client.get_baremetal_instance_external_host_id(name=bmi_cr_name) | ||
| assert "/" in external_host_id, f"Expected namespace/name format, got: {external_host_id}" | ||
| bmh_ns, bmh_name = external_host_id.split("/", 1) | ||
| assert bmh_ns == bmh_namespace, f"BMH landed in {bmh_ns}, expected {bmh_namespace}" | ||
|
|
||
| # Verify provisioning | ||
| wait_for_bmh_provisioned(k8s=k8s_hub_client, name=bmh_name, bmh_namespace=bmh_ns) | ||
|
|
||
| image_url: str = k8s_hub_client.get_bmh_image_url(name=bmh_name, bmh_namespace=bmh_ns) | ||
| assert image_url != "", f"BMH {bmh_name} has no image URL after provisioning" | ||
|
|
||
| consumer_ref: str = k8s_hub_client.get_bmh_consumer_ref(name=bmh_name, bmh_namespace=bmh_ns) | ||
| assert consumer_ref != "", f"BMH {bmh_name} has no consumerRef after allocation" | ||
|
|
||
| online: str = k8s_hub_client.get_bmh_online(name=bmh_name, bmh_namespace=bmh_ns) | ||
| assert online == "true", f"BMH {bmh_name} should be online after provisioning, got: {online}" | ||
|
|
||
| # Power off | ||
| halted = "BARE_METAL_INSTANCE_RUN_STRATEGY_HALTED" | ||
| grpc.update_baremetal_instance_run_strategy(bmi_id=bmi_id, run_strategy=halted) | ||
|
|
||
| poll_until( | ||
| fn=lambda: k8s_hub_client.get_bmh_powered_on(name=bmh_name, bmh_namespace=bmh_ns), | ||
| until=lambda v: v == "false", | ||
| retries=60, | ||
| delay=5, | ||
| description=f"{bmh_name} powered off", | ||
| ) | ||
|
|
||
| # Power on | ||
| grpc.update_baremetal_instance_run_strategy( | ||
| bmi_id=bmi_id, run_strategy="BARE_METAL_INSTANCE_RUN_STRATEGY_ALWAYS" | ||
| ) | ||
|
|
||
| poll_until( | ||
| fn=lambda: k8s_hub_client.get_bmh_powered_on(name=bmh_name, bmh_namespace=bmh_ns), | ||
| until=lambda v: v == "true", | ||
| retries=60, | ||
| delay=5, | ||
| description=f"{bmh_name} powered on", | ||
| ) | ||
|
|
||
| # Deprovision | ||
| cli.delete_baremetal_instance(uuid=bmi_id) | ||
| wait_for_bmi_deletion(k8s=k8s_hub_client, name=bmi_cr_name) | ||
| wait_for_bmi_grpc_removal(grpc=grpc, uuid=bmi_id) | ||
|
|
||
| wait_for_bmh_available(k8s=k8s_hub_client, name=bmh_name, bmh_namespace=bmh_ns) | ||
|
|
||
| image_url_after: str = k8s_hub_client.get_bmh_image_url(name=bmh_name, bmh_namespace=bmh_ns) | ||
| assert image_url_after == "", f"BMH {bmh_name} image not cleared after deprovision: {image_url_after}" | ||
|
|
||
| consumer_ref_after: str = k8s_hub_client.get_bmh_consumer_ref(name=bmh_name, bmh_namespace=bmh_ns) | ||
| assert consumer_ref_after == "", f"BMH {bmh_name} consumerRef not cleared: {consumer_ref_after}" | ||
| except BaseException: | ||
| bmi_cr: str = k8s_hub_client.get_baremetal_instance_name(uuid=bmi_id, checked=False) | ||
| if bmi_cr: | ||
| try: | ||
| cli.delete_baremetal_instance(uuid=bmi_id) | ||
| wait_for_bmi_deletion(k8s=k8s_hub_client, name=bmi_cr) | ||
| wait_for_bmi_grpc_removal(grpc=grpc, uuid=bmi_id) | ||
| except Exception: | ||
| pass | ||
| raise | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.