2025-12-01 12:48:39 +01:00
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
|
|
|
|
|
use testing_framework_core::scenario::{DynError, NodeControlHandle};
|
|
|
|
|
use tokio::process::Command;
|
2025-12-11 10:08:49 +01:00
|
|
|
use tracing::info;
|
2025-12-01 12:48:39 +01:00
|
|
|
|
2025-12-10 15:26:34 +01:00
|
|
|
use crate::{docker::commands::run_docker_command, errors::ComposeRunnerError};
|
2025-12-01 12:48:39 +01:00
|
|
|
|
|
|
|
|
pub async fn restart_compose_service(
|
|
|
|
|
compose_file: &Path,
|
|
|
|
|
project_name: &str,
|
|
|
|
|
service: &str,
|
|
|
|
|
) -> Result<(), ComposeRunnerError> {
|
|
|
|
|
let mut command = Command::new("docker");
|
|
|
|
|
command
|
|
|
|
|
.arg("compose")
|
|
|
|
|
.arg("-f")
|
|
|
|
|
.arg(compose_file)
|
|
|
|
|
.arg("-p")
|
|
|
|
|
.arg(project_name)
|
|
|
|
|
.arg("restart")
|
|
|
|
|
.arg(service);
|
|
|
|
|
|
|
|
|
|
let description = "docker compose restart";
|
2025-12-11 10:08:49 +01:00
|
|
|
info!(service, project = project_name, compose_file = %compose_file.display(), "restarting compose service");
|
2025-12-01 12:48:39 +01:00
|
|
|
run_docker_command(
|
|
|
|
|
command,
|
|
|
|
|
testing_framework_core::adjust_timeout(std::time::Duration::from_secs(120)),
|
2025-12-10 15:26:34 +01:00
|
|
|
description,
|
2025-12-01 12:48:39 +01:00
|
|
|
)
|
|
|
|
|
.await
|
2025-12-10 15:26:34 +01:00
|
|
|
.map_err(ComposeRunnerError::Compose)
|
2025-12-01 12:48:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Compose-specific node control handle for restarting nodes.
|
|
|
|
|
pub struct ComposeNodeControl {
|
|
|
|
|
pub(crate) compose_file: PathBuf,
|
|
|
|
|
pub(crate) project_name: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[async_trait::async_trait]
|
|
|
|
|
impl NodeControlHandle for ComposeNodeControl {
|
|
|
|
|
async fn restart_validator(&self, index: usize) -> Result<(), DynError> {
|
|
|
|
|
restart_compose_service(
|
|
|
|
|
&self.compose_file,
|
|
|
|
|
&self.project_name,
|
|
|
|
|
&format!("validator-{index}"),
|
|
|
|
|
)
|
|
|
|
|
.await
|
|
|
|
|
.map_err(|err| format!("validator restart failed: {err}").into())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn restart_executor(&self, index: usize) -> Result<(), DynError> {
|
|
|
|
|
restart_compose_service(
|
|
|
|
|
&self.compose_file,
|
|
|
|
|
&self.project_name,
|
|
|
|
|
&format!("executor-{index}"),
|
|
|
|
|
)
|
|
|
|
|
.await
|
|
|
|
|
.map_err(|err| format!("executor restart failed: {err}").into())
|
|
|
|
|
}
|
|
|
|
|
}
|