Skip to content
Merged
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
49 changes: 47 additions & 2 deletions src/agent/nodeagent/src/bluechi/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ spec:
let models = result.unwrap();
assert_eq!(models.len(), 1);
}

// Test case for a valid scenario where get_complete_model works correctly
#[tokio::test]
async fn test_get_complete_model_success() {
Expand Down Expand Up @@ -319,14 +320,36 @@ spec:
network: antipinch-network
"#;

let models_yaml = r#"
apiVersion: v1
kind: Model
metadata:
name: antipinch-enable-core
annotations:
io.piccolo.annotations.package-type: test
io.piccolo.annotations.package-name: test
io.piccolo.annotations.package-network: test
labels:
app: antipinch-enable-core
spec:
hostNetwork: true
containers:
- name: antipinch-enable-core
image: localhost/antipinch:1.0
terminationGracePeriodSeconds: 0
"#;

// Try to deserialize the package
let package_missing_volume: Result<Package, _> =
serde_yaml::from_str(package_yaml_missing_volume);
assert!(package_missing_volume.is_ok()); // Package should still parse correctly

let model: Result<Model, _> = serde_yaml::from_str(models_yaml);
let m: Vec<Model> = vec![model.unwrap()];

// Call get_complete_model and check if it returns an error due to missing volume
let package = package_missing_volume.unwrap();
let result = get_complete_model(package).await;
let result = get_complete_model(package, "HPC".to_string(), m).await;
assert!(result.is_err()); // Should fail due to missing volume
}

Expand All @@ -350,14 +373,36 @@ spec:
volume: antipinch-volume
"#;

let models_yaml = r#"
apiVersion: v1
kind: Model
metadata:
name: antipinch-enable-core
annotations:
io.piccolo.annotations.package-type: test
io.piccolo.annotations.package-name: test
io.piccolo.annotations.package-network: test
labels:
app: antipinch-enable-core
spec:
hostNetwork: true
containers:
- name: antipinch-enable-core
image: localhost/antipinch:1.0
terminationGracePeriodSeconds: 0
"#;

// Try to deserialize the package
let package_missing_network: Result<Package, _> =
serde_yaml::from_str(package_yaml_missing_network);
assert!(package_missing_network.is_ok()); // Package should still parse correctly

let model: Result<Model, _> = serde_yaml::from_str(models_yaml);
let m: Vec<Model> = vec![model.unwrap()];

// Call get_complete_model and check if it returns an error due to missing network
let package = package_missing_network.unwrap();
let result = get_complete_model(package).await;
let result = get_complete_model(package, "HPC".to_string(), m).await;
assert!(result.is_err()); // Should fail due to missing network
}
}
6 changes: 4 additions & 2 deletions src/agent/nodeagent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ async fn initialize(tx_grpc: Sender<HandleYamlRequest>, hostname: String) {
tx: tx_grpc.clone(),
};

let addr = if hostname.trim().eq_ignore_ascii_case("HPC") {
let hostname_in_setting = common::setting::get_config().host.name.clone();

let addr = if hostname.trim().eq_ignore_ascii_case(&hostname_in_setting) {
common::nodeagent::open_server()
} else {
common::nodeagent::open_guest_server()
Expand Down Expand Up @@ -92,7 +94,7 @@ mod tests {
channel(100);
let local = LocalSet::new();
local.spawn_local(async move {
let _ = launch_manager(rx_grpc).await;
let _ = launch_manager(rx_grpc, "hostname".to_string()).await;
});
tokio::select! {
_ = local => {}
Expand Down
4 changes: 4 additions & 0 deletions src/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ fn open_server(port: u16) -> String {
}

fn open_guest_server(port: u16) -> String {
if crate::setting::get_config().guest.is_none() {
// If no guest is configured, return the host server address
return open_server(port);
}
let guest_ip = crate::setting::get_config()
.guest
.as_ref()
Expand Down
5 changes: 2 additions & 3 deletions src/player/actioncontroller/src/grpc/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,8 @@ mod tests {
desired: 3,
});

let response = receiver.reconcile(request).await.unwrap();
assert_eq!(response.get_ref().status, 1);
assert!(response.get_ref().desc.contains("Failed to reconcile"));
let response = receiver.reconcile(request).await.unwrap_err();
assert!(response.message().contains("Failed to reconcile"));
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/player/actioncontroller/src/grpc/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ mod tests {
let action = 1;
let description = "example description".to_string();

let result = handle_workload(workload_name, action, description).await;
let result = handle_yaml(workload_name).await;
if let Err(ref e) = result {
println!("Error in test_handle_workload_success: {:?}", e);
} else {
Expand All @@ -159,7 +159,7 @@ mod tests {
let action = -999; // Invalid action code
let description = "".to_string(); // Empty description

let result = handle_workload(workload_name, action, description).await;
let result = handle_yaml(workload_name).await;

assert!(result.is_err());
}
Expand Down
Loading