Skip to content

Commit e22087f

Browse files
test(testkit): split provider install into profile import and provider create
import_profile reads the profile's id from its YAML and returns it, and create_provider takes the provider name and type separately, so the provider name no longer has to match the profile id. install_provider does both. Document that policy::allow merges binaries under one name and that an override Python image must use a PYTHON_BINARIES path. Signed-off-by: Matthew Grossman <[email protected]>
1 parent d246355 commit e22087f

12 files changed

Lines changed: 95 additions & 48 deletions

File tree

‎tests/suites/conformance/Cargo.lock‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/suites/drivers/podman/Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/suites/features/Cargo.lock‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/support/Cargo.lock‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/testkit/Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/testkit/README.md‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,24 @@ fails. A killed test process skips cleanup, so names are unique to the run.
7979
- `testkit::python_image()` for sandboxes that run `python3`, curl, git, or
8080
openssl: `OPENSHELL_TEST_PYTHON_IMAGE`, or `openshell/e2e-python:dev`
8181
(`e2e/python/Dockerfile.workload`). The tmachine installers load it into
82-
every environment; `mise run e2e:workload:build` builds it locally.
82+
every environment; `mise run e2e:workload:build` builds it locally. An
83+
override image must run `python3` from one of `testkit::PYTHON_BINARIES`.
8384
- `cx.cli([...])` to run the installed CLI against the same gateway, with
8485
`success()`, `failure()`, and `json()` on the output. `cx.cli_handle()`
8586
returns that CLI for code that can't borrow `cx`, such as a cleanup hook.
8687
- `cx.on_cleanup(name, hook)` to remove something when the test ends.
8788
- `testkit::policy` for sandbox policies: `policy::base()` reads
8889
`testkit/src/base-policy.yaml`, which allows no network access, and
8990
`policy::allow(&mut policy, name, host, port, binaries)` adds an endpoint
90-
that `policy::Endpoint` configures (`.rest(Access::Full)`,
91-
`.credential_binding(provider)`, ...). Pass the result to
92-
`cx.sandbox(..).policy(policy)`, or `policy::to_yaml` for the CLI.
91+
(binaries apply to every endpoint under `name`) that `policy::Endpoint`
92+
configures (`.rest(Access::Full)`, `.credential_binding(provider)`, ...).
93+
Pass the result to `cx.sandbox(..).policy(policy)`, or `policy::to_yaml`
94+
for the CLI.
9395
`testkit::PYTHON_BINARIES` names `python3` in `python_image()` images.
94-
- `testkit::install_provider(cx, name, profile, credentials)` to import a
95-
provider profile, whose `id` must be `name`, and create a provider of it,
96-
with cleanup for both.
96+
- `testkit::import_profile(cx, profile)` to import a provider profile and
97+
return its `id`, and `testkit::create_provider(cx, name, type, credentials)`
98+
to create a provider, each with cleanup. `testkit::install_provider(cx, name,
99+
profile, credentials)` does both.
97100
- `testkit::YamlFile` for YAML a CLI command reads from a file.
98101
- `cx.client()` for SDK calls testkit does not wrap.
99102
- `error.grpc_code()` for the gRPC status code (`testkit::GrpcCode`) of a

‎tests/testkit/testkit/Cargo.toml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ libtest-mimic = "0.8"
2626
linkme = "0.3"
2727
quick-junit = "0.8"
2828
rand = "0.9"
29-
serde = "1"
29+
serde = { version = "1", features = ["derive"] }
3030
serde_json = "1"
31+
serde_yml = { package = "noyalib", version = "0.0.53", default-features = false, features = ["std", "compat-serde-yaml"] }
3132
tempfile = "3"
3233
tokio = { version = "1.43", features = ["macros", "process", "rt", "time"] }
3334
tonic = "0.14"

‎tests/testkit/testkit/src/context.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ impl SandboxBuilder {
390390
/// as the SDK builds one from `spec` alone. The spec is destructured without
391391
/// `..`, so a field added to the SDK's spec fails to compile here instead of
392392
/// being dropped. [`SandboxBuilder::create`] rejects a GPU or service
393-
/// exposures before calling this.
393+
/// exposures before calling this. A policy field on the SDK's spec would
394+
/// replace this (#5410).
394395
fn policy_create_request(
395396
spec: SandboxSpec,
396397
policy: proto::SandboxPolicy,

‎tests/testkit/testkit/src/image.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ const BASE_IMAGE_ENV: &str = "OPENSHELL_TEST_BASE_IMAGE";
99
/// nvcr.io.
1010
const DEFAULT_BASE_IMAGE: &str = "nvcr.io/nvidia/base/ubuntu:24.04";
1111

12-
/// Overrides [`DEFAULT_PYTHON_IMAGE`].
12+
/// Overrides [`DEFAULT_PYTHON_IMAGE`]. The image must run `python3` from one
13+
/// of [`PYTHON_BINARIES`]; otherwise policies that allow those paths don't
14+
/// match it, and its connections are denied.
1315
const PYTHON_IMAGE_ENV: &str = "OPENSHELL_TEST_PYTHON_IMAGE";
1416
/// The workload image for tests that run `python3`, curl, git or openssl in a
1517
/// sandbox, built from `e2e/python/Dockerfile.workload`. It isn't published:
@@ -19,7 +21,8 @@ const DEFAULT_PYTHON_IMAGE: &str = "openshell/e2e-python:dev";
1921

2022
/// The paths `python3` runs from in [`python_image`] images, as network
2123
/// policy binaries: the system Python, the pullable uv image's Python, and the
22-
/// workload image's uv-installed Python behind its virtualenv.
24+
/// workload image's uv-installed Python behind its virtualenv. Add a path
25+
/// here for an image that installs Python elsewhere.
2326
pub const PYTHON_BINARIES: &[&str] = &[
2427
"/usr/bin/python*",
2528
"/usr/local/bin/python*",

‎tests/testkit/testkit/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub use image::{PYTHON_BINARIES, base_image, python_image};
5353
pub use openshell_sdk as sdk;
5454
pub use poll::{Poll, poll_until};
5555
pub use program::main;
56-
pub use provider::install_provider;
56+
pub use provider::{create_provider, import_profile, install_provider};
5757
pub use ready::check as check_ready;
5858
pub use registry::Test;
5959
pub use run::{TestInfo, run};

0 commit comments

Comments
 (0)