Skip to content
Open
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
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,32 @@ providing broad coverage of copy-offload functionality in a single run.
podman run ... uv run pytest -m copyoffload_sanity -v --tc=source_provider:vsphere-8.0.1 ...
```

### Toehold (Copy Appliance) Runs

Toehold is an alternative disk transfer path (MTV 5.0, `feature_copy_appliance`): instead of
pulling disks directly from vSphere via VDDK, MTV deploys a copy appliance VM inside vSphere
and streams the disks through it over NBD. The path is a run-level toggle, not a marker:

```bash
# Regular transfer path (unchanged)
podman run ... uv run pytest -m tier0 -v --tc=source_provider:vsphere-7.0.3 ...

# Copy appliance transfer path — same provider, one flag
podman run ... uv run pytest -m tier0 --toehold -v --tc=source_provider:vsphere-7.0.3 ...
```

Requirements:

- A vSphere source provider with an entry in the hardcoded `TOEHOLD_CONFIG_BY_PROVIDER` map
in `utilities/toehold.py` (the map carries the appliance placement settings, template base
disk image, and dev CDI image overrides per provider). No `.providers.json` changes are
needed — the same provider entry serves both transfer paths. Passing `--toehold` with any
other provider exits with a usage error instead of silently running the regular path.
- The `mtv-api-tests run` CLI forwards the flag too: `uv run mtv-api-tests run --mode local
--toehold --source-provider vsphere-7.0.3`.
- The CDI/controller image overrides are cluster-wide: do not run other migration tests
against the same cluster while a toehold run is active.

**Examples** - Change `-m tier0` to run different tests:

> **Note**: In the examples below, replace `podman run ...` with the full `podman run` command shown in the
Expand Down
3 changes: 3 additions & 0 deletions cli/mtv_api_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def run(
storage_class: str = typer.Option("", help="OpenShift storage class name"), # noqa: M511
test_filter: str = typer.Option("", "-k", help="Pytest -k filter (e.g. MTV-559, thin)"), # noqa: M511
job_yaml: str = typer.Option(str(JOB_YAML_PATH), help="Path to Job YAML (for --mode job)"), # noqa: M511
toehold: bool = typer.Option(False, "--toehold", help="Run through the copy appliance transfer path"), # noqa: M511
) -> None:
"""Run tests locally or as an OpenShift Job.

Expand All @@ -72,6 +73,7 @@ def run(
storage_class: OpenShift storage class name (empty for interactive).
test_filter: Pytest -k filter expression.
job_yaml: Path to Job YAML file (for --mode job).
toehold: Whether to run through the copy appliance transfer path.

Raises:
typer.Exit: On test completion or error.
Expand All @@ -84,6 +86,7 @@ def run(
storage_class=storage_class,
test_filter=test_filter,
job_yaml=job_yaml,
toehold=toehold,
)


Expand Down
31 changes: 29 additions & 2 deletions cli/mtv_api_tests/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ def _get_cluster_config(ocp_provider: dict[str, Any] | None) -> tuple[list[str],


def _run_local(
provider_key: str, storage_class: str, category: str, test_filter: str, ocp_provider: dict[str, Any] | None
provider_key: str,
storage_class: str,
category: str,
test_filter: str,
ocp_provider: dict[str, Any] | None,
extra_pytest_args: list[str] | None = None,
) -> None:
"""Execute tests locally via uv run pytest.

Expand All @@ -182,6 +187,9 @@ def _run_local(
category: Pytest marker name (e.g. 'copyoffload', 'tier0').
test_filter: Optional pytest -k filter.
ocp_provider: OpenShift provider config dict, or None.
extra_pytest_args: Additional pytest arguments decided by the caller (e.g. a
feature-mode flag such as --toehold). Keeping them generic means a new run option
does not need a new parameter threaded through this shared launcher.

Raises:
typer.Exit: With the pytest process return code.
Expand All @@ -201,6 +209,8 @@ def _run_local(
cmd.extend(["-m", category])
if test_filter:
cmd.extend(["-k", test_filter])
if extra_pytest_args:
cmd.extend(extra_pytest_args)

console.print(f"\n[bold]Running:[/bold] {shlex.join(cmd)}\n")

Expand Down Expand Up @@ -273,6 +283,7 @@ def run_command(
storage_class: str,
test_filter: str,
job_yaml: str,
toehold: bool,
Comment thread
AmenB marked this conversation as resolved.
Resolved
) -> None:
"""Run tests locally or as an OpenShift Job.

Expand All @@ -284,13 +295,22 @@ def run_command(
storage_class: OpenShift storage class name (empty for interactive/auto from OCP provider).
test_filter: Pytest -k filter expression.
job_yaml: Path to Job YAML file.
toehold: Whether to run migrations through the copy appliance transfer path
(supported vSphere versions only; local mode only).

Raises:
typer.Exit: On test completion, missing configuration, or error.
"""
load_dotenv()

if mode == "job":
if toehold:
console.print(
"[red]Error: --toehold is not supported with --mode job: the Job manifest's pytest "
"command is fixed at 'generate' time and cannot carry the flag. Run locally with "
"--mode local --toehold, or edit the manifest's pytest command by hand.[/red]"
)
raise typer.Exit(code=1)
job_yaml_path = Path(job_yaml)
if not job_yaml_path.exists():
console.print(f"[red]Error: {job_yaml_path} not found. Run 'mtv-api-tests generate' first.[/red]")
Expand Down Expand Up @@ -345,4 +365,11 @@ def run_command(
else:
storage_class = Prompt.ask(" Enter storage class name")

_run_local(resolved_source, storage_class, resolved_category, test_filter, ocp_provider)
_run_local(
resolved_source,
storage_class,
resolved_category,
test_filter,
ocp_provider,
extra_pytest_args=["--toehold"] if toehold else None,
)
173 changes: 173 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@
from utilities.hooks import create_hook_if_configured
from utilities.logger import separator, setup_logging
from utilities.mtv_migration import get_vm_suffix, resolve_pvc_name_template
from utilities.toehold import (
TOEHOLD_CONFIG_BY_PROVIDER,
ToeholdClusterState,
apply_toehold_setup,
get_toehold_config,
restore_toehold_setup,
toehold_usage_error,
)
from utilities.must_gather import (
collect_class_must_gather,
collect_class_teardown_must_gather,
Expand Down Expand Up @@ -149,6 +157,13 @@
# Pytest start


# Fixtures that build their own source Provider resource (certificate-field and
# insecure-connection variants). The toehold appliance setup patches only the session provider,
# so a test using one of these would migrate over the VDDK path while its Plan readiness check
# reported appliance-path coverage.
_TOEHOLD_OWN_PROVIDER_FIXTURES = frozenset({"ca_crt_source_provider", "insecure_source_provider"})


def pytest_addoption(parser):
data_collector_group = parser.getgroup(name="DataCollector")
teardown_group = parser.getgroup(name="Teardown")
Expand All @@ -163,6 +178,17 @@ def pytest_addoption(parser):
default=None,
)

toehold_group = parser.getgroup(name="Toehold")
toehold_group.addoption(
"--toehold",
action="store_true",
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Resolved
Comment thread
AmenB marked this conversation as resolved.
Resolved
help=(
"Run migrations through the copy appliance transfer path. Uses the hardcoded "
f"appliance configuration; supported source providers: "
f"{', '.join(TOEHOLD_CONFIG_BY_PROVIDER)}"
),
)

mtv_upgrade_group = parser.getgroup(name="MTV Upgrade")
mtv_upgrade_group.addoption(
"--mtv-upgrade-timeout",
Expand Down Expand Up @@ -618,6 +644,68 @@ def pytest_collection_modifyitems(session, config, items):
source_provider_data = providers.get(py_config.get("source_provider", ""), {})
source_provider_type = source_provider_data.get("type") or py_config.get("source_provider_type")

# Attach the toehold pre-setup to every test when --toehold is passed; without the flag
# they run the regular VDDK transfer path. The appliance configuration is hardcoded per
# source provider, so the flag only attaches for a provider with an entry in the map —
# anything else exits with a usage error instead of silently running the
# regular path.
# Pool mode leaves the provider unresolved at collection time, so no setup is attached
# there — toehold runs require an explicit --tc=source_provider.
# A usefixtures marker added here would be ignored: pytest computes an item's fixture
# closure at item creation, before this hook runs. Appending to fixturenames is the way
# to attach a fixture at collection time.
if config.getoption("toehold"):
if not source_provider_data:
pytest.exit(
"--toehold requires an explicit --tc=source_provider: the appliance setup is "
"attached at collection time, before pool selection runs.",
returncode=pytest.ExitCode.USAGE_ERROR,
)
if usage_error := toehold_usage_error(
provider_name=py_config["source_provider"],
provider_type=source_provider_type,
provider_data=source_provider_data,
):
pytest.exit(
usage_error,
returncode=pytest.ExitCode.USAGE_ERROR,
)

if config.getoption("toehold"):
# Attached outside the dry-run guard so --setup-plan --toehold reports the
# appliance fixture in its plan; a real run validates the provider above.
# Appended, not inserted first: pytest orders same-scope fixtures by
# fixturenames position, and the toehold chain (source_provider) must not
# overtake the base_resource_name fixture, whose fixture_store key the
# provider creation reads. Scope ordering already guarantees this
# session-scoped setup runs before any class-scoped plan preparation.
for item in items:
if _TOEHOLD_OWN_PROVIDER_FIXTURES.intersection(item.fixturenames):
item.add_marker(
pytest.mark.skip(
reason=(
"--toehold configures only the session source provider; this test "
"creates its own Provider, so keep it out of toehold runs"
)
)
)
continue
if item.get_closest_marker("vddk_baseline"):
# The appliance setup clears the provider's vddkInitImage, so a test that
# compares a real VDDK transfer against another path would silently compare
# against the appliance instead. Keep it out of toehold runs rather than
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Resolved
# reporting a comparison the run cannot make.
item.add_marker(
pytest.mark.skip(
reason=(
"--toehold clears the source provider's vddkInitImage; this test "
"needs a genuine VDDK baseline, run it without --toehold"
)
)
)
continue
item.fixturenames.append("toehold_appliance")
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Resolved

if source_provider_type:
# Skip warm migration tests for providers that do not support warm migration.
warm_unsupported = (
Expand Down Expand Up @@ -1262,6 +1350,91 @@ def source_provider(
_source_provider.disconnect()


@pytest.fixture(scope="session")
def toehold_config(selected_source_provider: str, source_provider: BaseProvider) -> dict[str, Any]:
"""Resolve the hardcoded toehold appliance configuration for the source provider.

Attached to all collected tests at collection time when --toehold is passed; the appliance
configuration (placement and dev images) is hardcoded per provider in utilities/toehold.py.

Args:
selected_source_provider (str): Selected source provider key from the test config.
source_provider (BaseProvider): Source provider instance.

Returns:
dict[str, Any]: The toehold configuration for the provider.

Raises:
ValueError: If the provider type is not vSphere or the provider has no appliance
configuration.
"""
return get_toehold_config(
provider_name=selected_source_provider,
provider_type=source_provider.type,
)


@pytest.fixture(scope="session")
def toehold_appliance(
ocp_admin_client: DynamicClient,
source_provider: BaseProvider,
toehold_config: dict[str, Any],
fixture_store: dict[str, Any],
target_namespace: str,
mtv_namespace: str,
) -> Generator[None, None, None]:
"""Prepare the cluster for toehold migrations and restore everything on session end.

Patches the provider with the copy appliance placement settings, enables the copy
appliance feature on the ForkliftController (left enabled after the run — it is inert
without a provider CopyApplianceTemplate), applies the template config and the optional
controller image override (all through the ForkliftController CR — the operator owns the
controller deployment), overrides the CDI images when configured, and creates the
provider's CopyApplianceTemplate. The image and provider patches are restored on session
teardown; the feature gate is not. The setup is cluster-wide: no other migration tests
should run against the same cluster while it is active.

Args:
ocp_admin_client (DynamicClient): OpenShift admin client.
source_provider (BaseProvider): Source provider instance.
toehold_config (dict[str, Any]): Validated toehold configuration.
fixture_store (dict[str, Any]): Session fixture store for resource tracking.
target_namespace (str): Namespace for the migration resources.
mtv_namespace (str): Namespace where the ForkliftController is installed.

Yields:
None

Raises:
ValueError: If the source provider has no OCP resource.
"""
ocp_provider = source_provider.ocp_resource
if ocp_provider is None:
raise ValueError("Source provider has no OCP Provider resource")

# The try must start before the first cluster change: a failure while applying (validation,
# resource creation, template build, appliance readiness) has to restore whatever was applied.
state = ToeholdClusterState()
try:
apply_toehold_setup(
ocp_admin_client=ocp_admin_client,
ocp_provider=ocp_provider,
toehold_config=toehold_config,
fixture_store=fixture_store,
target_namespace=target_namespace,
mtv_namespace=mtv_namespace,
state=state,
)
yield
finally:
restore_toehold_setup(
ocp_admin_client=ocp_admin_client,
mtv_namespace=mtv_namespace,
state=state,
provider=ocp_provider,
)


@pytest.fixture(scope="class")
def vcenter_clone_provider(
source_provider_data: dict[str, Any],
Expand Down
5 changes: 4 additions & 1 deletion docs/automation-and-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,10 @@ by themselves.
| `mtv-api-tests run` | Runs the tests. `--mode local` shells out to `uv run pytest`; `--mode job` runs `oc apply -f` against the manifest |

Both accept `--category` (a pytest marker), and `run` accepts `--source-provider`, `--destination-provider`, `--storage-class`,
`--test-filter` / `-k`, and `--job-yaml`. `generate` additionally accepts `--image` for the Job container image.
`--test-filter` / `-k`, `--job-yaml`, and `--toehold` (run through the copy appliance transfer path; forwarded to
pytest as `--toehold`, supported vSphere providers only, `--mode local` only — `--mode job` exits with an error (exit code 1)
because the Job manifest's pytest command is fixed at `generate` time). `generate` additionally accepts `--image` for
the Job container image.

Useful entry points for automation and debugging:

Expand Down
Loading