Skip to content
Draft
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
117 changes: 116 additions & 1 deletion auraed/src/cells/cell_service/cell_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,13 +561,16 @@ mod tests {
use super::*;
use crate::{AURAED_RUNTIME, AuraedRuntime};
use crate::{
cells::cell_service::executables::ExecutableName,
cells::cell_service::validation::{
ValidatedCell, ValidatedCpuController, ValidatedCpusetController,
ValidatedMemoryController,
ValidatedExecutable, ValidatedMemoryController,
},
logging::log_channel::LogChannel,
};
use iter_tools::Itertools;
use proto::cells::Executable;
use std::ffi::OsString;
use test_helpers::*;

/// Test for the list function.
Expand Down Expand Up @@ -645,6 +648,61 @@ mod tests {
assert_eq!(actual_nested_cell_names, expected_nested_cell_names);
}

#[tokio::test]
async fn test_start_stop_free() {
skip_if_not_root!("test_start_stop_free");
skip_if_seccomp!("test_start_stop_free");

let _ = AURAED_RUNTIME.set(AuraedRuntime::default());

let service = CellService::new(ObserveService::new(
Arc::new(LogChannel::new(String::from("test"))),
(None, None, None),
));

let command = "tail -f /dev/null";

// Cover the default root cell start/stop entry points.
let root_executable_name =
format!("ae-exec-root-{}", uuid::Uuid::new_v4());
let result = service
.start(validated_start_request(&root_executable_name, command))
.await;
assert!(result.is_ok());

let response = result.unwrap().into_inner();
assert!(response.pid != 0);

assert!(service
.stop(validated_stop_request(&root_executable_name))
.await
.is_ok());

let cell_name = format!("ae-test-{}", uuid::Uuid::new_v4());
assert!(service.allocate(allocate_request(&cell_name)).await.is_ok());
let cell_name_ref = CellName::from(cell_name.as_str());

let executable_name = format!("ae-exec-{}", uuid::Uuid::new_v4());
// start/stop/free need to run within the allocated cell
let result = service
.start_in_cell(&cell_name_ref, start_request(&executable_name, command))
.await;
assert!(result.is_ok());

let response = result.unwrap().into_inner();
assert!(response.pid != 0);

assert!(service
.stop_in_cell(&cell_name_ref, stop_request(&executable_name))
.await
.is_ok());

assert!(service
.free(free_request(&cell_name))
.await
.is_ok());
}

/// Helper function to create a ValidatedCellServiceAllocateRequest.
///
/// # Arguments
Expand Down Expand Up @@ -676,4 +734,61 @@ mod tests {
// Return the validated allocate request
ValidatedCellServiceAllocateRequest { cell }
}

fn validated_start_request(
executable_name: &str,
command: &str,
) -> ValidatedCellServiceStartRequest {
let executable = ValidatedExecutable {
name: ExecutableName::new(String::from(executable_name)),
command: OsString::from(command),
description: String::new(),
};

ValidatedCellServiceStartRequest {
cell_name: None,
executable,
uid: None,
gid: None,
}
}

fn validated_stop_request(
executable_name: &str,
) -> ValidatedCellServiceStopRequest {
ValidatedCellServiceStopRequest {
cell_name: None,
executable_name: ExecutableName::new(String::from(executable_name)),
}
}

fn start_request(
executable_name: &str,
command: &str,
) -> CellServiceStartRequest {
let executable = Executable {
name: executable_name.to_string(),
command: command.to_string(),
description: String::new(),
};

CellServiceStartRequest {
cell_name: None,
executable: Some(executable),
uid: None,
gid: None,
}
}

fn stop_request(executable_name: &str) -> CellServiceStopRequest {
CellServiceStopRequest {
cell_name: None,
executable_name: executable_name.to_string(),
}
}

fn free_request(cell_name: &str) -> ValidatedCellServiceFreeRequest {
// Return the validated free request
ValidatedCellServiceFreeRequest { cell_name: CellName::from(cell_name) }
}
}