Replace lexical Rust fragments with real modules
This commit is contained in:
parent
f8849cdb5f
commit
247819250b
3 changed files with 3302 additions and 2671 deletions
|
|
@ -1,25 +1,40 @@
|
|||
struct Fixture {
|
||||
use super::{
|
||||
Arc, AwaitingAttachedRunsc, BENCHMARK_GUEST, BTreeMap, BundleDigest, CommittedSandboxRuntime,
|
||||
ConfigurationLoadRequest, ContainerId, CoordinatorId, DnsProbeTarget, DnsQueryExpectation,
|
||||
Domain, DomainStoreMutation, DurableDecision, Generation, GenerationId,
|
||||
HostCoordinatorDomainStore, HostProcessOwnershipSlot, IpAddress, Ipv4Addr, MatrixError,
|
||||
NETWORK_NAMESPACE_PATH, NetworkCoordinator, NetworkProbeRequest, NetworkSidecarId, Path,
|
||||
PathBuf, ProcessOwnershipContext, ReachabilityExpectation, ResolvedDomainConfiguration,
|
||||
RootProcess, RunscCommand, RuntimeNetworkLaunch, RuntimeSupervisorLaunch,
|
||||
SANDBOX_NETWORK_PROBE, SandboxBuildRequest, SandboxBundle, SandboxCoordinator, SandboxId,
|
||||
SocketAddr, SocketAddrExt, TcpListener, TcpProbeTarget, TempDir, UnixListener,
|
||||
build_sandbox_bundle, current_mount_identity, current_process_identity, default_sandbox_layout,
|
||||
derive_ipv4_policy, failure, fs, hex, host_path, load_trusted_configuration, lock_file,
|
||||
stage_benchmark_rootfs_and_control, stage_rootfs_and_control, try_exclusive_flock,
|
||||
};
|
||||
|
||||
pub(super) struct Fixture {
|
||||
_tree: Option<TempDir>,
|
||||
configuration: ResolvedDomainConfiguration,
|
||||
store: Arc<HostCoordinatorDomainStore>,
|
||||
bundle: SandboxBundle,
|
||||
activity: PathBuf,
|
||||
benchmark_results: Option<PathBuf>,
|
||||
pub(super) configuration: ResolvedDomainConfiguration,
|
||||
pub(super) store: Arc<HostCoordinatorDomainStore>,
|
||||
pub(super) bundle: SandboxBundle,
|
||||
pub(super) activity: PathBuf,
|
||||
pub(super) benchmark_results: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl Fixture {
|
||||
fn new() -> Result<Self, MatrixError> {
|
||||
pub(super) fn new() -> Result<Self, MatrixError> {
|
||||
let tree = tempfile::tempdir()?;
|
||||
let root = tree.path().to_path_buf();
|
||||
Self::build(&root, Some(tree))
|
||||
}
|
||||
|
||||
fn in_directory(root: &Path) -> Result<Self, MatrixError> {
|
||||
pub(super) fn in_directory(root: &Path) -> Result<Self, MatrixError> {
|
||||
Self::build(root, None)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn build_benchmark(
|
||||
pub(super) fn build_benchmark(
|
||||
root: &Path,
|
||||
workspace: &Path,
|
||||
host_root: &Path,
|
||||
|
|
@ -239,11 +254,11 @@ impl Fixture {
|
|||
})
|
||||
}
|
||||
|
||||
fn launch_pending(&self) -> Result<AwaitingAttachedRunsc, MatrixError> {
|
||||
pub(super) fn launch_pending(&self) -> Result<AwaitingAttachedRunsc, MatrixError> {
|
||||
self.launch_pending_with_command(self.bundle.command())
|
||||
}
|
||||
|
||||
fn launch_pending_with_command(
|
||||
pub(super) fn launch_pending_with_command(
|
||||
&self,
|
||||
command: &RunscCommand,
|
||||
) -> Result<AwaitingAttachedRunsc, MatrixError> {
|
||||
|
|
@ -260,7 +275,7 @@ impl Fixture {
|
|||
.map_err(failure)
|
||||
}
|
||||
|
||||
fn alternate_bundle(&self) -> Result<SandboxBundle, MatrixError> {
|
||||
pub(super) fn alternate_bundle(&self) -> Result<SandboxBundle, MatrixError> {
|
||||
let namespace =
|
||||
lazaret_linux::filesystem::namespace_identity(Path::new(NETWORK_NAMESPACE_PATH))?;
|
||||
build_sandbox_bundle(SandboxBuildRequest {
|
||||
|
|
@ -282,7 +297,7 @@ impl Fixture {
|
|||
.map_err(failure)
|
||||
}
|
||||
|
||||
fn launch_committed(&self) -> Result<CommittedSandboxRuntime, MatrixError> {
|
||||
pub(super) fn launch_committed(&self) -> Result<CommittedSandboxRuntime, MatrixError> {
|
||||
let handoff = self
|
||||
.bundle
|
||||
.capture_handoff_authority(&self.configuration)
|
||||
|
|
@ -299,19 +314,19 @@ impl Fixture {
|
|||
}
|
||||
}
|
||||
|
||||
struct NetworkFixture {
|
||||
pub(super) struct NetworkFixture {
|
||||
_tree: TempDir,
|
||||
_host_loopback: TcpListener,
|
||||
_host_abstract: UnixListener,
|
||||
configuration: ResolvedDomainConfiguration,
|
||||
store: HostCoordinatorDomainStore,
|
||||
bundle: SandboxBundle,
|
||||
policy: lazaret_core::network::CanonicalDerivedNetworkPolicy,
|
||||
probe_result: PathBuf,
|
||||
pub(super) configuration: ResolvedDomainConfiguration,
|
||||
pub(super) store: HostCoordinatorDomainStore,
|
||||
pub(super) bundle: SandboxBundle,
|
||||
pub(super) policy: lazaret_core::network::CanonicalDerivedNetworkPolicy,
|
||||
pub(super) probe_result: PathBuf,
|
||||
}
|
||||
|
||||
impl NetworkFixture {
|
||||
fn new() -> Result<Self, MatrixError> {
|
||||
pub(super) fn new() -> Result<Self, MatrixError> {
|
||||
let tree = tempfile::tempdir()?;
|
||||
let root = tree.path();
|
||||
let workspace = root.join("workspace");
|
||||
|
|
@ -375,11 +390,11 @@ impl NetworkFixture {
|
|||
})
|
||||
}
|
||||
|
||||
fn launch(&self) -> Result<CommittedSandboxRuntime, MatrixError> {
|
||||
pub(super) fn launch(&self) -> Result<CommittedSandboxRuntime, MatrixError> {
|
||||
self.launch_with_permitted([1, 1, 1, 1], 443)
|
||||
}
|
||||
|
||||
fn launch_with_permitted(
|
||||
pub(super) fn launch_with_permitted(
|
||||
&self,
|
||||
permitted_address: [u8; 4],
|
||||
permitted_port: u16,
|
||||
|
|
@ -517,4 +532,3 @@ fn network_store(
|
|||
.map_err(failure)?;
|
||||
Ok(store)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,24 @@
|
|||
fn run_handoff_matrix() -> Result<(), MatrixError> {
|
||||
use super::{
|
||||
AttachedRunscSignal, CoordinatorId, Duration, Fixture, GenerationId, HOST_COORDINATOR_DRIVER,
|
||||
HostProcessOwnershipSlot, MatrixError, ParticipantState, Path, PathBuf, PidfsProcessIdentityV1,
|
||||
PlatformObservation, ProcessOwnershipCommitAck, ProcessOwnershipContext, RetainedProcess,
|
||||
SandboxCoordinator, Signal, TargetCommand, UnixListener, check_platform, child_broker,
|
||||
current_process_identity, failed_probe_blocks_sandbox_start, fs, host_path,
|
||||
networked_sandbox_view_isolated, read_start_time, sandbox_participant, thread,
|
||||
};
|
||||
|
||||
pub(super) fn run_handoff_matrix() -> Result<(), MatrixError> {
|
||||
require_matrix_prerequisites()?;
|
||||
replaced_handoff_authority_refuses_target_work()?;
|
||||
cross_bundle_handoff_refuses_target_work()
|
||||
}
|
||||
|
||||
fn run_network_cases() -> Result<(), MatrixError> {
|
||||
pub(super) fn run_network_cases() -> Result<(), MatrixError> {
|
||||
failed_probe_blocks_sandbox_start()?;
|
||||
networked_sandbox_view_isolated()
|
||||
}
|
||||
|
||||
fn require_matrix_prerequisites() -> Result<(), MatrixError> {
|
||||
pub(super) fn require_matrix_prerequisites() -> Result<(), MatrixError> {
|
||||
let release = fs::read_to_string("/proc/sys/kernel/osrelease")?;
|
||||
check_platform(&PlatformObservation {
|
||||
operating_system: std::env::consts::OS,
|
||||
|
|
@ -58,7 +67,7 @@ fn require_runtime_prerequisites() -> Result<(), MatrixError> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn lost_acknowledgment_refuses_target_work() -> Result<(), MatrixError> {
|
||||
pub(super) fn lost_acknowledgment_refuses_target_work() -> Result<(), MatrixError> {
|
||||
let fixture = Fixture::new()?;
|
||||
let mut pending = fixture.launch_pending()?;
|
||||
let staged = pending
|
||||
|
|
@ -82,7 +91,7 @@ fn lost_acknowledgment_refuses_target_work() -> Result<(), MatrixError> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn replaced_handoff_authority_refuses_target_work() -> Result<(), MatrixError> {
|
||||
pub(super) fn replaced_handoff_authority_refuses_target_work() -> Result<(), MatrixError> {
|
||||
let fixture = Fixture::new()?;
|
||||
let handoff = fixture
|
||||
.bundle
|
||||
|
|
@ -130,7 +139,7 @@ fn cross_bundle_handoff_refuses_target_work() -> Result<(), MatrixError> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn normal_stop_and_stop_resume() -> Result<(), MatrixError> {
|
||||
pub(super) fn normal_stop_and_stop_resume() -> Result<(), MatrixError> {
|
||||
let fixture = Fixture::new()?;
|
||||
let mut runtime = fixture.launch_committed()?;
|
||||
wait_for_activity(&fixture.activity)?;
|
||||
|
|
@ -166,7 +175,7 @@ fn normal_stop_and_stop_resume() -> Result<(), MatrixError> {
|
|||
assert_activity_stable(&fixture.activity)
|
||||
}
|
||||
|
||||
fn attached_runsc_loss_stops_guest() -> Result<(), MatrixError> {
|
||||
pub(super) fn attached_runsc_loss_stops_guest() -> Result<(), MatrixError> {
|
||||
let fixture = Fixture::new()?;
|
||||
let mut runtime = fixture.launch_committed()?;
|
||||
wait_for_activity(&fixture.activity)?;
|
||||
|
|
@ -181,7 +190,7 @@ fn attached_runsc_loss_stops_guest() -> Result<(), MatrixError> {
|
|||
assert_activity_stable(&fixture.activity)
|
||||
}
|
||||
|
||||
fn runtime_supervisor_loss_stops_guest() -> Result<(), MatrixError> {
|
||||
pub(super) fn runtime_supervisor_loss_stops_guest() -> Result<(), MatrixError> {
|
||||
let fixture = Fixture::new()?;
|
||||
let runtime = fixture.launch_committed()?;
|
||||
wait_for_activity(&fixture.activity)?;
|
||||
|
|
@ -198,7 +207,7 @@ fn runtime_supervisor_loss_stops_guest() -> Result<(), MatrixError> {
|
|||
assert_activity_stable(&fixture.activity)
|
||||
}
|
||||
|
||||
fn host_coordinator_loss_stops_guest() -> Result<(), MatrixError> {
|
||||
pub(super) fn host_coordinator_loss_stops_guest() -> Result<(), MatrixError> {
|
||||
let tree = tempfile::tempdir()?;
|
||||
let ready = tree.path().join("host-coordinator-ready");
|
||||
let activity = tree.path().join("workspace/activity");
|
||||
|
|
@ -275,7 +284,7 @@ impl Drop for ExactChild {
|
|||
}
|
||||
}
|
||||
|
||||
fn run_host_coordinator_driver(arguments: &[std::ffi::OsString]) -> std::io::Result<()> {
|
||||
pub(super) fn run_host_coordinator_driver(arguments: &[std::ffi::OsString]) -> std::io::Result<()> {
|
||||
let tree = arguments
|
||||
.first()
|
||||
.map(PathBuf::from)
|
||||
|
|
@ -298,13 +307,13 @@ fn run_host_coordinator_driver(arguments: &[std::ffi::OsString]) -> std::io::Res
|
|||
}
|
||||
}
|
||||
|
||||
fn matrix_io(error: MatrixError) -> std::io::Error {
|
||||
pub(super) fn matrix_io(error: MatrixError) -> std::io::Error {
|
||||
match error {
|
||||
MatrixError::Skip(detail) | MatrixError::Failure(detail) => std::io::Error::other(detail),
|
||||
}
|
||||
}
|
||||
|
||||
fn failure(error: impl std::fmt::Display) -> MatrixError {
|
||||
pub(super) fn failure(error: impl std::fmt::Display) -> MatrixError {
|
||||
MatrixError::Failure(error.to_string())
|
||||
}
|
||||
|
||||
|
|
@ -364,4 +373,3 @@ fn assert_activity_stable(path: &Path) -> Result<(), MatrixError> {
|
|||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,11 @@
|
|||
fn failed_probe_blocks_sandbox_start() -> Result<(), MatrixError> {
|
||||
use super::{
|
||||
ContainerId, Duration, File, HostCoordinatorDomainStore, HostPath, Ipv4Addr, MatrixError,
|
||||
NetworkFixture, OpenOptions, OsStringExt, ParticipantRole, ParticipantState, Path, PathBuf,
|
||||
SandboxCoordinator, SocketAddr, SocketAddrExt, SocketAddrV4, TcpStream, ToSocketAddrs,
|
||||
UnixStream, failure, fs, symlink, thread,
|
||||
};
|
||||
|
||||
pub(super) fn failed_probe_blocks_sandbox_start() -> Result<(), MatrixError> {
|
||||
let fixture = NetworkFixture::new()?;
|
||||
if let Ok(runtime) = fixture.launch_with_permitted([203, 0, 113, 1], 9) {
|
||||
runtime
|
||||
|
|
@ -16,7 +23,7 @@ fn failed_probe_blocks_sandbox_start() -> Result<(), MatrixError> {
|
|||
}
|
||||
}
|
||||
|
||||
fn networked_sandbox_view_isolated() -> Result<(), MatrixError> {
|
||||
pub(super) fn networked_sandbox_view_isolated() -> Result<(), MatrixError> {
|
||||
let fixture = NetworkFixture::new()?;
|
||||
let runtime = fixture.launch()?;
|
||||
for _ in 0..6000 {
|
||||
|
|
@ -44,7 +51,7 @@ fn networked_sandbox_view_isolated() -> Result<(), MatrixError> {
|
|||
.map_err(failure)
|
||||
}
|
||||
|
||||
fn run_sandbox_network_probe(arguments: &[std::ffi::OsString]) -> std::io::Result<()> {
|
||||
pub(super) fn run_sandbox_network_probe(arguments: &[std::ffi::OsString]) -> std::io::Result<()> {
|
||||
let host_port = arguments
|
||||
.first()
|
||||
.and_then(|value| value.to_str())
|
||||
|
|
@ -89,7 +96,7 @@ fn run_sandbox_network_probe(arguments: &[std::ffi::OsString]) -> std::io::Resul
|
|||
}
|
||||
}
|
||||
|
||||
fn stage_rootfs_and_control(
|
||||
pub(super) fn stage_rootfs_and_control(
|
||||
runtime_domain: &Path,
|
||||
container_id: ContainerId,
|
||||
) -> Result<(), MatrixError> {
|
||||
|
|
@ -153,7 +160,7 @@ fn stage_rootfs_and_control(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn stage_benchmark_rootfs_and_control(runtime_domain: &Path) -> Result<(), MatrixError> {
|
||||
pub(super) fn stage_benchmark_rootfs_and_control(runtime_domain: &Path) -> Result<(), MatrixError> {
|
||||
let rootfs = runtime_domain.join("prepared-root");
|
||||
for directory in [
|
||||
"bin",
|
||||
|
|
@ -214,7 +221,9 @@ fn stage_benchmark_rootfs_and_control(runtime_domain: &Path) -> Result<(), Matri
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn sandbox_participant(store: &HostCoordinatorDomainStore) -> lazaret_core::records::Participant {
|
||||
pub(super) fn sandbox_participant(
|
||||
store: &HostCoordinatorDomainStore,
|
||||
) -> lazaret_core::records::Participant {
|
||||
store
|
||||
.snapshot()
|
||||
.unwrap()
|
||||
|
|
@ -224,7 +233,7 @@ fn sandbox_participant(store: &HostCoordinatorDomainStore) -> lazaret_core::reco
|
|||
.unwrap()
|
||||
}
|
||||
|
||||
fn lock_file(path: &Path) -> File {
|
||||
pub(super) fn lock_file(path: &Path) -> File {
|
||||
OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
|
|
@ -234,11 +243,11 @@ fn lock_file(path: &Path) -> File {
|
|||
.unwrap()
|
||||
}
|
||||
|
||||
fn host_path(path: &HostPath) -> PathBuf {
|
||||
pub(super) fn host_path(path: &HostPath) -> PathBuf {
|
||||
PathBuf::from(std::ffi::OsString::from_vec(path.as_bytes().to_vec()))
|
||||
}
|
||||
|
||||
fn hex(bytes: &[u8]) -> String {
|
||||
pub(super) fn hex(bytes: &[u8]) -> String {
|
||||
use std::fmt::Write as _;
|
||||
|
||||
bytes.iter().fold(String::new(), |mut output, byte| {
|
||||
|
|
|
|||
Loading…
Reference in a new issue