ALPHA: wire is a tool to deploy nixos systems wire.althaea.zone/
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

add test for create_ssh_opts & _args

+105 -18
+1 -1
wire/lib/src/commands/common.rs
··· 34 34 context 35 35 .node 36 36 .target 37 - .create_ssh_opts(context.modifiers, false)?, 37 + .create_ssh_opts(context.modifiers, false), 38 38 )]), 39 39 )?; 40 40
+1 -1
wire/lib/src/commands/interactive.rs
··· 410 410 modifiers: SubCommandModifiers, 411 411 ) -> Result<portable_pty::CommandBuilder, HiveLibError> { 412 412 let mut command = portable_pty::CommandBuilder::new("ssh"); 413 - command.args(target.create_ssh_args(modifiers, false, false)?); 413 + command.args(target.create_ssh_args(modifiers, false, false)); 414 414 command.arg(target.get_preferred_host()?.to_string()); 415 415 Ok(command) 416 416 }
+1 -1
wire/lib/src/commands/noninteractive.rs
··· 192 192 modifiers: SubCommandModifiers, 193 193 ) -> Result<Command, HiveLibError> { 194 194 let mut command = Command::new("ssh"); 195 - command.args(target.create_ssh_args(modifiers, true, false)?); 195 + command.args(target.create_ssh_args(modifiers, true, false)); 196 196 command.arg(target.get_preferred_host()?.to_string()); 197 197 198 198 Ok(command)
+101 -9
wire/lib/src/hive/node.rs
··· 47 47 48 48 impl Target { 49 49 #[instrument(ret(level = tracing::Level::DEBUG), skip_all)] 50 - pub fn create_ssh_opts( 51 - &self, 52 - modifiers: SubCommandModifiers, 53 - master: bool, 54 - ) -> Result<String, HiveLibError> { 55 - Ok(self.create_ssh_args(modifiers, false, master)?.join(" ")) 50 + pub fn create_ssh_opts(&self, modifiers: SubCommandModifiers, master: bool) -> String { 51 + self.create_ssh_args(modifiers, false, master).join(" ") 56 52 } 57 53 58 54 #[instrument(ret(level = tracing::Level::DEBUG), skip_all)] ··· 61 57 modifiers: SubCommandModifiers, 62 58 non_interactive_forced: bool, 63 59 master: bool, 64 - ) -> Result<Vec<String>, HiveLibError> { 60 + ) -> Vec<String> { 65 61 let mut vector = vec![ 66 62 "-l".to_string(), 67 63 self.user.to_string(), ··· 96 92 vector.push("-o".to_string()); 97 93 vector.extend(options.into_iter().intersperse("-o".to_string())); 98 94 99 - Ok(vector) 95 + vector 100 96 } 101 97 } 102 98 ··· 232 228 .log_stdout(), 233 229 HashMap::from([( 234 230 "NIX_SSHOPTS".into(), 235 - self.target.create_ssh_opts(modifiers, true)?, 231 + self.target.create_ssh_opts(modifiers, true), 236 232 )]), 237 233 )?; 238 234 ··· 447 443 448 444 #[cfg(test)] 449 445 mod tests { 446 + use rand::distr::Alphabetic; 447 + 450 448 use super::*; 451 449 use crate::{ 452 450 function_name, get_test_path, ··· 674 672 Err(HiveLibError::NetworkError(NetworkError::HostsExhausted)) 675 673 ); 676 674 } 675 + } 676 + 677 + #[test] 678 + fn test_ssh_opts() { 679 + let target = Target::from_host("hello-world"); 680 + let subcommand_modifiers = SubCommandModifiers { 681 + non_interactive: false, 682 + ..Default::default() 683 + }; 684 + let tmp = format!( 685 + "/tmp/{}", 686 + rand::distr::SampleString::sample_string(&Alphabetic, &mut rand::rng(), 10) 687 + ); 688 + 689 + std::fs::create_dir(&tmp).unwrap(); 690 + 691 + unsafe { env::set_var("XDG_RUNTIME_DIR", &tmp) } 692 + 693 + let args = [ 694 + "-l".to_string(), 695 + target.user.to_string(), 696 + "-p".to_string(), 697 + target.port.to_string(), 698 + "-o".to_string(), 699 + "StrictHostKeyChecking=accept-new".to_string(), 700 + "-o".to_string(), 701 + "ControlMaster=no".to_string(), 702 + "-o".to_string(), 703 + format!("ControlPath={tmp}/wire/%C"), 704 + "-o".to_string(), 705 + format!("ControlPersist={CONTROL_PERSIST}"), 706 + ]; 707 + 708 + assert_eq!( 709 + target.create_ssh_args(subcommand_modifiers, false, false), 710 + args 711 + ); 712 + assert_eq!( 713 + target.create_ssh_opts(subcommand_modifiers, false), 714 + args.join(" ") 715 + ); 716 + 717 + assert_eq!( 718 + target.create_ssh_args(subcommand_modifiers, false, true), 719 + [ 720 + "-l".to_string(), 721 + target.user.to_string(), 722 + "-p".to_string(), 723 + target.port.to_string(), 724 + "-o".to_string(), 725 + "StrictHostKeyChecking=accept-new".to_string(), 726 + "-o".to_string(), 727 + "ControlMaster=yes".to_string(), 728 + "-o".to_string(), 729 + format!("ControlPath={tmp}/wire/%C"), 730 + "-o".to_string(), 731 + format!("ControlPersist={CONTROL_PERSIST}"), 732 + ] 733 + ); 734 + 735 + assert_eq!( 736 + target.create_ssh_args(subcommand_modifiers, true, true), 737 + [ 738 + "-l".to_string(), 739 + target.user.to_string(), 740 + "-p".to_string(), 741 + target.port.to_string(), 742 + "-o".to_string(), 743 + "StrictHostKeyChecking=accept-new".to_string(), 744 + "-o".to_string(), 745 + "PasswordAuthentication=no".to_string(), 746 + "-o".to_string(), 747 + "KbdInteractiveAuthentication=no".to_string(), 748 + "-o".to_string(), 749 + "ControlMaster=yes".to_string(), 750 + "-o".to_string(), 751 + format!("ControlPath={tmp}/wire/%C"), 752 + "-o".to_string(), 753 + format!("ControlPersist={CONTROL_PERSIST}"), 754 + ] 755 + ); 756 + 757 + // forced non interactive is the same as --non-interactive 758 + assert_eq!( 759 + target.create_ssh_args(subcommand_modifiers, true, false), 760 + target.create_ssh_args( 761 + SubCommandModifiers { 762 + non_interactive: true, 763 + ..Default::default() 764 + }, 765 + false, 766 + false 767 + ) 768 + ); 677 769 } 678 770 }
+1 -5
wire/lib/src/hive/steps/cleanup.rs
··· 27 27 28 28 async fn execute(&self, ctx: &mut Context<'_>) -> Result<(), HiveLibError> { 29 29 let output = Command::new("ssh") 30 - .args( 31 - ctx.node 32 - .target 33 - .create_ssh_args(ctx.modifiers, true, false)?, 34 - ) 30 + .args(ctx.node.target.create_ssh_args(ctx.modifiers, true, false)) 35 31 .args(["-O", "stop", ctx.node.target.get_preferred_host()?]) 36 32 .output() 37 33 .await;
-1
wire/lib/src/test_support.rs
··· 6 6 io, 7 7 path::Path, 8 8 process::Command, 9 - sync::{Arc, Mutex}, 10 9 }; 11 10 12 11 use tempdir::TempDir;