Skip to content

Commit 0094791

Browse files
test(testkit): set the supervisor log level on a sandbox
Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
1 parent 8101a6e commit 0094791

1 file changed

Lines changed: 44 additions & 9 deletions

File tree

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

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ impl Context {
191191
handles: self.handles.clone(),
192192
policy: None,
193193
driver_config: None,
194+
log_level: None,
194195
spec: SandboxSpec {
195196
name: Some(self.sandbox_name(suffix)),
196197
..SandboxSpec::default()
@@ -431,6 +432,7 @@ pub struct SandboxBuilder {
431432
handles: Handles,
432433
policy: Option<proto::SandboxPolicy>,
433434
driver_config: Option<serde_json::Value>,
435+
log_level: Option<String>,
434436
spec: SandboxSpec,
435437
}
436438

@@ -488,6 +490,13 @@ impl SandboxBuilder {
488490
self
489491
}
490492

493+
/// Run the sandbox's supervisor at `level`, such as `info`, instead of the
494+
/// driver's default.
495+
pub fn log_level(mut self, level: impl Into<String>) -> Self {
496+
self.log_level = Some(level.into());
497+
self
498+
}
499+
491500
/// Full access to the spec for fields without a builder method.
492501
pub fn spec(mut self, update: impl FnOnce(&mut SandboxSpec)) -> Self {
493502
update(&mut self.spec);
@@ -507,25 +516,29 @@ impl SandboxBuilder {
507516
pub async fn create(self) -> Result<Sandbox> {
508517
let name = self.spec.name.clone().unwrap_or_default();
509518
self.handles.track(&name);
510-
let id = if self.policy.is_none() && self.driver_config.is_none() {
519+
let id = if self.policy.is_none()
520+
&& self.driver_config.is_none()
521+
&& self.log_level.is_none()
522+
{
511523
self.handles
512524
.client
513525
.create_sandbox(self.spec)
514526
.await
515527
.context(format!("create sandbox {name}"))?
516528
.id
517529
} else {
518-
// The SDK's spec has no policy or driver config, so create
519-
// through gRPC.
530+
// The SDK's spec has no policy, driver config or log level, so
531+
// create through gRPC.
520532
crate::ensure!(
521533
!self.spec.gpu && self.spec.service_exposures.is_empty(),
522-
"testkit doesn't create a sandbox with a policy or driver config and a GPU or service exposures"
534+
"testkit doesn't create a sandbox with a policy, driver config or log level and a GPU or service exposures"
523535
);
524536
let driver_config = self.driver_config.map(driver_config_struct).transpose()?;
525537
let request = grpc_create_request(
526538
self.spec,
527539
self.policy,
528540
driver_config,
541+
self.log_level,
529542
self.handles.grpc.scope(),
530543
);
531544
self.handles
@@ -572,6 +585,7 @@ fn grpc_create_request(
572585
spec: SandboxSpec,
573586
policy: Option<proto::SandboxPolicy>,
574587
driver_config: Option<prost_types::Struct>,
588+
log_level: Option<String>,
575589
workspace_scope: Option<proto::datamodel::v1::WorkspaceSelector>,
576590
) -> proto::CreateSandboxRequest {
577591
let SandboxSpec {
@@ -603,6 +617,7 @@ fn grpc_create_request(
603617
command,
604618
tty,
605619
policy,
620+
log_level: log_level.unwrap_or_default(),
606621
restart_policy: proto::SandboxRestartPolicy::from(restart_policy) as i32,
607622
..proto::SandboxSpec::default()
608623
}),
@@ -1083,7 +1098,7 @@ mod tests {
10831098
};
10841099
let policy = crate::policy::base();
10851100

1086-
let spec = grpc_create_request(spec, Some(policy.clone()), None, None)
1101+
let spec = grpc_create_request(spec, Some(policy.clone()), None, None, None)
10871102
.spec
10881103
.expect("spec");
10891104

@@ -1101,9 +1116,15 @@ mod tests {
11011116
}))
11021117
.expect("an object converts");
11031118

1104-
let spec = grpc_create_request(SandboxSpec::default(), None, Some(config.clone()), None)
1105-
.spec
1106-
.expect("spec");
1119+
let spec = grpc_create_request(
1120+
SandboxSpec::default(),
1121+
None,
1122+
Some(config.clone()),
1123+
None,
1124+
None,
1125+
)
1126+
.spec
1127+
.expect("spec");
11071128

11081129
let template = spec.template.expect("a template for the driver config");
11091130
assert_eq!(template.image, "", "an empty image selects the default");
@@ -1113,12 +1134,26 @@ mod tests {
11131134

11141135
#[test]
11151136
fn grpc_create_request_omits_an_empty_template() {
1116-
let spec = grpc_create_request(SandboxSpec::default(), None, None, None)
1137+
let spec = grpc_create_request(SandboxSpec::default(), None, None, None, None)
11171138
.spec
11181139
.expect("spec");
11191140
assert_eq!(spec.template, None);
11201141
}
11211142

1143+
#[test]
1144+
fn grpc_create_request_carries_the_log_level() {
1145+
let spec = grpc_create_request(
1146+
SandboxSpec::default(),
1147+
None,
1148+
None,
1149+
Some("info".to_string()),
1150+
None,
1151+
)
1152+
.spec
1153+
.expect("spec");
1154+
assert_eq!(spec.log_level, "info");
1155+
}
1156+
11221157
#[test]
11231158
fn driver_config_must_be_an_object() {
11241159
let error = driver_config_struct(serde_json::json!(["docker"])).expect_err("an array");

0 commit comments

Comments
 (0)