diff options
| author | diogo464 <[email protected]> | 2025-07-10 22:06:59 +0100 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-07-10 22:06:59 +0100 |
| commit | 3b0721341c46922b5c1c94bdbbf37099424ee5bc (patch) | |
| tree | 5bb70b49f75eaf296c8d162ec913a3046a46aff9 | |
| parent | 66a0329b201a19d2a6d87b265b6fde3423a917c0 (diff) | |
cargo clippy --fix
| -rw-r--r-- | src/context.rs | 3 | ||||
| -rw-r--r-- | src/main.rs | 28 | ||||
| -rw-r--r-- | src/oar.rs | 6 |
3 files changed, 17 insertions, 20 deletions
diff --git a/src/context.rs b/src/context.rs index 323a8a5..ae25966 100644 --- a/src/context.rs +++ b/src/context.rs | |||
| @@ -31,8 +31,7 @@ impl Context { | |||
| 31 | 31 | ||
| 32 | pub fn frontend_hostname(&self) -> Result<&str> { | 32 | pub fn frontend_hostname(&self) -> Result<&str> { |
| 33 | self.frontend_hostname | 33 | self.frontend_hostname |
| 34 | .as_ref() | 34 | .as_deref() |
| 35 | .map(|s| s.as_str()) | ||
| 36 | .ok_or_else(|| eyre::eyre!("missing frontend hostname")) | 35 | .ok_or_else(|| eyre::eyre!("missing frontend hostname")) |
| 37 | } | 36 | } |
| 38 | } | 37 | } |
diff --git a/src/main.rs b/src/main.rs index f164d47..6f17df1 100644 --- a/src/main.rs +++ b/src/main.rs | |||
| @@ -27,7 +27,7 @@ pub mod latency_matrix; | |||
| 27 | pub mod machine; | 27 | pub mod machine; |
| 28 | pub mod oar; | 28 | pub mod oar; |
| 29 | 29 | ||
| 30 | const CONTAINER_IMAGE_NAME: &'static str = "local/oar-p2p-networking"; | 30 | const CONTAINER_IMAGE_NAME: &str = "local/oar-p2p-networking"; |
| 31 | 31 | ||
| 32 | #[derive(Debug, Parser)] | 32 | #[derive(Debug, Parser)] |
| 33 | struct Cli { | 33 | struct Cli { |
| @@ -185,7 +185,7 @@ async fn cmd_net_show(args: NetShowArgs) -> Result<()> { | |||
| 185 | } | 185 | } |
| 186 | addresses.sort(); | 186 | addresses.sort(); |
| 187 | for (machine, addr) in addresses { | 187 | for (machine, addr) in addresses { |
| 188 | println!("{} {}", machine, addr); | 188 | println!("{machine} {addr}"); |
| 189 | } | 189 | } |
| 190 | Ok(()) | 190 | Ok(()) |
| 191 | } | 191 | } |
| @@ -343,11 +343,11 @@ fn machine_containers_create_script(containers: &[ScheduledContainer]) -> String | |||
| 343 | for (key, val) in container.variables.iter() { | 343 | for (key, val) in container.variables.iter() { |
| 344 | script.push_str("\t-e "); | 344 | script.push_str("\t-e "); |
| 345 | script.push_str(key); | 345 | script.push_str(key); |
| 346 | script.push_str("="); | 346 | script.push('='); |
| 347 | script.push_str(val); | 347 | script.push_str(val); |
| 348 | script.push_str(" \\\n"); | 348 | script.push_str(" \\\n"); |
| 349 | } | 349 | } |
| 350 | script.push_str("\t"); | 350 | script.push('\t'); |
| 351 | script.push_str(&container.image); | 351 | script.push_str(&container.image); |
| 352 | script.push_str(" &\n"); | 352 | script.push_str(" &\n"); |
| 353 | script.push_str(&format!("pid_{idx}=$!\n\n")); | 353 | script.push_str(&format!("pid_{idx}=$!\n\n")); |
| @@ -371,7 +371,7 @@ async fn machine_create_containers( | |||
| 371 | ) -> Result<()> { | 371 | ) -> Result<()> { |
| 372 | tracing::info!("creating {} containers", containers.len()); | 372 | tracing::info!("creating {} containers", containers.len()); |
| 373 | let script = machine_containers_create_script(containers); | 373 | let script = machine_containers_create_script(containers); |
| 374 | machine_run_script(&ctx, machine, &script).await?; | 374 | machine_run_script(ctx, machine, &script).await?; |
| 375 | tracing::info!("containers created"); | 375 | tracing::info!("containers created"); |
| 376 | Ok(()) | 376 | Ok(()) |
| 377 | } | 377 | } |
| @@ -380,7 +380,7 @@ async fn machine_create_containers( | |||
| 380 | async fn machine_start_containers(ctx: &Context, machine: Machine) -> Result<()> { | 380 | async fn machine_start_containers(ctx: &Context, machine: Machine) -> Result<()> { |
| 381 | tracing::info!("starting all containers"); | 381 | tracing::info!("starting all containers"); |
| 382 | machine_run_script( | 382 | machine_run_script( |
| 383 | &ctx, | 383 | ctx, |
| 384 | machine, | 384 | machine, |
| 385 | "docker container ls -aq | xargs docker container start", | 385 | "docker container ls -aq | xargs docker container start", |
| 386 | ) | 386 | ) |
| @@ -439,7 +439,7 @@ async fn machine_containers_save_logs( | |||
| 439 | ) -> Result<()> { | 439 | ) -> Result<()> { |
| 440 | tracing::info!("saving logs from {} containers", containers.len()); | 440 | tracing::info!("saving logs from {} containers", containers.len()); |
| 441 | let script = machine_containers_save_logs_script(containers); | 441 | let script = machine_containers_save_logs_script(containers); |
| 442 | machine_run_script(&ctx, machine, &script).await?; | 442 | machine_run_script(ctx, machine, &script).await?; |
| 443 | tracing::info!("logs saved"); | 443 | tracing::info!("logs saved"); |
| 444 | Ok(()) | 444 | Ok(()) |
| 445 | } | 445 | } |
| @@ -704,7 +704,7 @@ async fn machine_clean(ctx: &Context, machine: Machine) -> Result<()> { | |||
| 704 | script.push_str("tc qdisc del dev lo root 2>/dev/null || true\n"); | 704 | script.push_str("tc qdisc del dev lo root 2>/dev/null || true\n"); |
| 705 | script.push_str("tc qdisc del dev lo ingress 2>/dev/null || true\n"); | 705 | script.push_str("tc qdisc del dev lo ingress 2>/dev/null || true\n"); |
| 706 | script.push_str("nft delete table oar-p2p 2>/dev/null || true\n"); | 706 | script.push_str("nft delete table oar-p2p 2>/dev/null || true\n"); |
| 707 | machine_net_container_run_script(&ctx, machine, &script).await?; | 707 | machine_net_container_run_script(ctx, machine, &script).await?; |
| 708 | tracing::info!("network interfaces clean"); | 708 | tracing::info!("network interfaces clean"); |
| 709 | Ok(()) | 709 | Ok(()) |
| 710 | } | 710 | } |
| @@ -715,7 +715,7 @@ fn machine_configuration_script(config: &MachineConfig) -> String { | |||
| 715 | script.push_str("cat << EOF | ip -b -\n"); | 715 | script.push_str("cat << EOF | ip -b -\n"); |
| 716 | for command in config.ip_commands.iter() { | 716 | for command in config.ip_commands.iter() { |
| 717 | script.push_str(command); | 717 | script.push_str(command); |
| 718 | script.push_str("\n"); | 718 | script.push('\n'); |
| 719 | } | 719 | } |
| 720 | script.push_str("\nEOF\n"); | 720 | script.push_str("\nEOF\n"); |
| 721 | 721 | ||
| @@ -723,7 +723,7 @@ fn machine_configuration_script(config: &MachineConfig) -> String { | |||
| 723 | script.push_str("cat << EOF | tc -b -\n"); | 723 | script.push_str("cat << EOF | tc -b -\n"); |
| 724 | for command in config.tc_commands.iter() { | 724 | for command in config.tc_commands.iter() { |
| 725 | script.push_str(command); | 725 | script.push_str(command); |
| 726 | script.push_str("\n"); | 726 | script.push('\n'); |
| 727 | } | 727 | } |
| 728 | script.push_str("\nEOF\n"); | 728 | script.push_str("\nEOF\n"); |
| 729 | 729 | ||
| @@ -817,8 +817,7 @@ fn machine_generate_configs( | |||
| 817 | let latency_mark = idx + 1; | 817 | let latency_mark = idx + 1; |
| 818 | 818 | ||
| 819 | machine_tc_commands.push(format!( | 819 | machine_tc_commands.push(format!( |
| 820 | "class add dev {iface} parent 1: classid 1:{} htb rate 10gbit", | 820 | "class add dev {iface} parent 1: classid 1:{latency_class_id} htb rate 10gbit" |
| 821 | latency_class_id | ||
| 822 | )); | 821 | )); |
| 823 | // why idx + 2 here? I dont remember anymore and forgot to comment | 822 | // why idx + 2 here? I dont remember anymore and forgot to comment |
| 824 | machine_tc_commands.push(format!( | 823 | machine_tc_commands.push(format!( |
| @@ -828,8 +827,7 @@ fn machine_generate_configs( | |||
| 828 | )); | 827 | )); |
| 829 | // TODO: is the order of these things correct? | 828 | // TODO: is the order of these things correct? |
| 830 | machine_tc_commands.push(format!( | 829 | machine_tc_commands.push(format!( |
| 831 | "filter add dev {iface} parent 1:0 prio 1 handle {} fw flowid 1:{}", | 830 | "filter add dev {iface} parent 1:0 prio 1 handle {latency_mark} fw flowid 1:{latency_class_id}", |
| 832 | latency_mark, latency_class_id, | ||
| 833 | )); | 831 | )); |
| 834 | } | 832 | } |
| 835 | } | 833 | } |
| @@ -852,7 +850,7 @@ fn machine_generate_configs( | |||
| 852 | } | 850 | } |
| 853 | machine_nft_script.push_str("\t\t}\n"); | 851 | machine_nft_script.push_str("\t\t}\n"); |
| 854 | machine_nft_script.push_str("\t}\n"); | 852 | machine_nft_script.push_str("\t}\n"); |
| 855 | machine_nft_script.push_str("\n"); | 853 | machine_nft_script.push('\n'); |
| 856 | machine_nft_script.push_str("\tchain postrouting {\n"); | 854 | machine_nft_script.push_str("\tchain postrouting {\n"); |
| 857 | machine_nft_script.push_str("\t\ttype filter hook postrouting priority mangle -1\n"); | 855 | machine_nft_script.push_str("\t\ttype filter hook postrouting priority mangle -1\n"); |
| 858 | machine_nft_script.push_str("\t\tpolicy accept\n"); | 856 | machine_nft_script.push_str("\t\tpolicy accept\n"); |
| @@ -33,7 +33,7 @@ pub async fn job_list_machines(ctx: &Context) -> Result<Vec<Machine>> { | |||
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | let stdout = std::str::from_utf8(&output.stdout)?; | 35 | let stdout = std::str::from_utf8(&output.stdout)?; |
| 36 | extract_machines_from_oar_stat_json(&stdout, job_id) | 36 | extract_machines_from_oar_stat_json(stdout, job_id) |
| 37 | } | 37 | } |
| 38 | ExecutionNode::Unknown => { | 38 | ExecutionNode::Unknown => { |
| 39 | let job_id = ctx.job_id()?; | 39 | let job_id = ctx.job_id()?; |
| @@ -53,7 +53,7 @@ pub async fn job_list_machines(ctx: &Context) -> Result<Vec<Machine>> { | |||
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | let stdout = std::str::from_utf8(&output.stdout)?; | 55 | let stdout = std::str::from_utf8(&output.stdout)?; |
| 56 | extract_machines_from_oar_stat_json(&stdout, job_id) | 56 | extract_machines_from_oar_stat_json(stdout, job_id) |
| 57 | } | 57 | } |
| 58 | ExecutionNode::Machine(_) => { | 58 | ExecutionNode::Machine(_) => { |
| 59 | let nodefile = std::env::var("OAR_NODEFILE").context("reading OAR_NODEFILE env var")?; | 59 | let nodefile = std::env::var("OAR_NODEFILE").context("reading OAR_NODEFILE env var")?; |
| @@ -101,7 +101,7 @@ mod test { | |||
| 101 | use super::*; | 101 | use super::*; |
| 102 | 102 | ||
| 103 | const OAR_STAT_JSON_JOB_ID: u32 = 36627; | 103 | const OAR_STAT_JSON_JOB_ID: u32 = 36627; |
| 104 | const OAR_STAT_JSON_OUTPUT: &'static str = r#" | 104 | const OAR_STAT_JSON_OUTPUT: &str = r#" |
| 105 | { | 105 | { |
| 106 | "36627" : { | 106 | "36627" : { |
| 107 | "types" : [], | 107 | "types" : [], |
