consortium-crate 0.1.0

Core library — Rust implementation of ClusterShell
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
//! SSH Worker implementation.
//!
//! Provides SshWorker, which wraps ExecWorker to execute commands on remote
//! nodes via SSH. Mirrors ClusterShell's WorkerSsh / SshClient.

use std::collections::HashMap;
use std::os::unix::io::RawFd;
use std::time::Duration;

use crate::worker::exec::ExecWorker;
use crate::worker::{EventHandler, Worker, WorkerState};

/// SSH connection options.
#[derive(Debug, Clone)]
pub struct SshOptions {
    /// Path to the SSH binary.
    pub ssh_path: String,
    /// Path to the SCP binary.
    pub scp_path: String,
    /// SSH user (if different from current user).
    pub user: Option<String>,
    /// Custom SSH options (passed as -o key=value).
    pub options: Vec<String>,
    /// Connect timeout in seconds.
    pub connect_timeout: Option<u32>,
    /// Whether to use strict host key checking.
    pub strict_host_key_checking: bool,
    /// Whether to enable password authentication.
    pub password_auth: bool,
    /// Path to SSH identity file (passed as -i).
    pub identity_file: Option<String>,
    /// Path to SSH config file (passed as -F).
    pub config_file: Option<String>,
    /// Enable SSH ControlMaster multiplexing.
    pub control_master: Option<ControlMaster>,
    /// Path for ControlMaster socket (passed as -oControlPath=...).
    pub control_path: Option<String>,
    /// ControlPersist timeout (e.g. "10m", "yes").
    pub control_persist: Option<String>,
    /// SSH ProxyJump host (passed as -J).
    pub proxy_jump: Option<String>,
    /// SSH port (passed as -p).
    pub port: Option<u16>,
}

/// SSH ControlMaster modes.
#[derive(Debug, Clone, PartialEq)]
pub enum ControlMaster {
    /// Automatically start a master if one isn't running.
    Auto,
    /// Automatically start and automatically close.
    AutoAsk,
    /// Always be the master.
    Yes,
    /// Never be the master.
    No,
}

impl Default for SshOptions {
    fn default() -> Self {
        Self {
            ssh_path: "ssh".to_string(),
            scp_path: "scp".to_string(),
            user: None,
            options: Vec::new(),
            connect_timeout: Some(10),
            strict_host_key_checking: false,
            password_auth: false,
            identity_file: None,
            config_file: None,
            control_master: None,
            control_path: None,
            control_persist: None,
            proxy_jump: None,
            port: None,
        }
    }
}

impl SshOptions {
    /// Build the SSH command prefix for a given node.
    ///
    /// Returns the full SSH command string that will execute `command` on `node`.
    pub fn build_ssh_cmd(&self, node: &str, command: &str) -> String {
        let mut parts = Vec::new();
        parts.push(self.ssh_path.clone());

        // Config file must come early (before other options)
        if let Some(ref config_file) = self.config_file {
            parts.push("-F".to_string());
            parts.push(config_file.clone());
        }

        // Standard hardened options (mirrors Python SshClient._build_cmd)
        parts.push("-oForwardX11=no".to_string());

        if !self.strict_host_key_checking {
            parts.push("-oStrictHostKeyChecking=no".to_string());
        }

        if !self.password_auth {
            parts.push("-oPasswordAuthentication=no".to_string());
        }

        if let Some(timeout) = self.connect_timeout {
            parts.push(format!("-oConnectTimeout={}", timeout));
        }

        // ControlMaster multiplexing
        if let Some(ref cm) = self.control_master {
            let val = match cm {
                ControlMaster::Auto => "auto",
                ControlMaster::AutoAsk => "autoask",
                ControlMaster::Yes => "yes",
                ControlMaster::No => "no",
            };
            parts.push(format!("-oControlMaster={}", val));
        }
        if let Some(ref cp) = self.control_path {
            parts.push(format!("-oControlPath={}", cp));
        }
        if let Some(ref persist) = self.control_persist {
            parts.push(format!("-oControlPersist={}", persist));
        }

        // Custom options
        for opt in &self.options {
            parts.push(format!("-o{}", opt));
        }

        // Identity file
        if let Some(ref identity) = self.identity_file {
            parts.push("-i".to_string());
            parts.push(identity.clone());
        }

        // ProxyJump
        if let Some(ref jump) = self.proxy_jump {
            parts.push("-J".to_string());
            parts.push(jump.clone());
        }

        // Port
        if let Some(port) = self.port {
            parts.push("-p".to_string());
            parts.push(port.to_string());
        }

        // User
        if let Some(ref user) = self.user {
            parts.push("-l".to_string());
            parts.push(user.clone());
        }

        // Target node and command
        parts.push(node.to_string());
        parts.push(command.to_string());

        parts.join(" ")
    }

    /// Build an SCP command for copying files to/from a node.
    ///
    /// If `reverse` is true, copies from remote to local.
    pub fn build_scp_cmd(
        &self,
        node: &str,
        source: &str,
        dest: &str,
        reverse: bool,
        preserve: bool,
        directory: bool,
    ) -> String {
        let mut parts = Vec::new();
        parts.push(self.scp_path.clone());

        // Config file
        if let Some(ref config_file) = self.config_file {
            parts.push("-F".to_string());
            parts.push(config_file.clone());
        }

        if !self.strict_host_key_checking {
            parts.push("-oStrictHostKeyChecking=no".to_string());
        }

        if !self.password_auth {
            parts.push("-oPasswordAuthentication=no".to_string());
        }

        if let Some(timeout) = self.connect_timeout {
            parts.push(format!("-oConnectTimeout={}", timeout));
        }

        // ControlMaster multiplexing
        if let Some(ref cm) = self.control_master {
            let val = match cm {
                ControlMaster::Auto => "auto",
                ControlMaster::AutoAsk => "autoask",
                ControlMaster::Yes => "yes",
                ControlMaster::No => "no",
            };
            parts.push(format!("-oControlMaster={}", val));
        }
        if let Some(ref cp) = self.control_path {
            parts.push(format!("-oControlPath={}", cp));
        }
        if let Some(ref persist) = self.control_persist {
            parts.push(format!("-oControlPersist={}", persist));
        }

        if preserve {
            parts.push("-p".to_string());
        }

        if directory {
            parts.push("-r".to_string());
        }

        // Identity file
        if let Some(ref identity) = self.identity_file {
            parts.push("-i".to_string());
            parts.push(identity.clone());
        }

        // ProxyJump
        if let Some(ref jump) = self.proxy_jump {
            parts.push("-J".to_string());
            parts.push(jump.clone());
        }

        // Port
        if let Some(port) = self.port {
            parts.push("-P".to_string()); // SCP uses -P (uppercase) for port
            parts.push(port.to_string());
        }

        // Custom options
        for opt in &self.options {
            parts.push(format!("-o{}", opt));
        }

        // User prefix
        let user_prefix = if let Some(ref user) = self.user {
            format!("{}@", user)
        } else {
            String::new()
        };

        if reverse {
            // Remote -> Local
            parts.push(format!("{}{}:{}", user_prefix, node, source));
            parts.push(dest.to_string());
        } else {
            // Local -> Remote
            parts.push(source.to_string());
            parts.push(format!("{}{}:{}", user_prefix, node, dest));
        }

        parts.join(" ")
    }
}

/// Worker that executes commands on remote nodes via SSH.
///
/// SshWorker is a thin wrapper around ExecWorker that builds SSH
/// commands using configurable SshOptions. It mirrors ClusterShell's
/// WorkerSsh class.
pub struct SshWorker {
    /// Underlying ExecWorker that does the actual process management.
    inner: ExecWorker,
    /// SSH options used for command building.
    ssh_options: SshOptions,
    /// Original command (before SSH wrapping).
    original_command: String,
}

impl SshWorker {
    /// Create a new SshWorker.
    ///
    /// # Arguments
    /// * `nodes` - List of remote node names to execute on.
    /// * `command` - Command to run on each remote node.
    /// * `fanout` - Max concurrent SSH connections.
    /// * `timeout` - Optional per-node timeout.
    /// * `ssh_options` - SSH connection options.
    pub fn new(
        nodes: Vec<String>,
        command: String,
        fanout: usize,
        timeout: Option<Duration>,
        ssh_options: SshOptions,
    ) -> Self {
        // Build the SSH-wrapped command using %h for node substitution.
        // ExecWorker will replace %h with the actual node name.
        let ssh_cmd = ssh_options.build_ssh_cmd("%h", &command);

        SshWorker {
            inner: ExecWorker::new(nodes, ssh_cmd, fanout, timeout),
            ssh_options,
            original_command: command,
        }
    }

    /// Create a new SshWorker with default SSH options.
    pub fn with_defaults(
        nodes: Vec<String>,
        command: String,
        fanout: usize,
        timeout: Option<Duration>,
    ) -> Self {
        Self::new(nodes, command, fanout, timeout, SshOptions::default())
    }

    /// Enable stderr capture.
    pub fn with_stderr(mut self, stderr: bool) -> Self {
        self.inner = self.inner.with_stderr(stderr);
        self
    }

    /// Get the SSH options.
    pub fn ssh_options(&self) -> &SshOptions {
        &self.ssh_options
    }

    /// Get the original (unwrapped) command.
    pub fn original_command(&self) -> &str {
        &self.original_command
    }
}

impl Worker for SshWorker {
    fn start(&mut self) -> crate::worker::Result<()> {
        self.inner.start()
    }

    fn abort(&mut self, kill: bool) {
        self.inner.abort(kill);
    }

    fn state(&self) -> WorkerState {
        self.inner.state()
    }

    fn set_handler(&mut self, handler: Box<dyn EventHandler>) {
        self.inner.set_handler(handler);
    }

    fn read_fds(&self) -> Vec<RawFd> {
        self.inner.read_fds()
    }

    fn write_fds(&self) -> Vec<RawFd> {
        self.inner.write_fds()
    }

    fn handle_read(&mut self, fd: RawFd) -> crate::worker::Result<()> {
        self.inner.handle_read(fd)
    }

    fn handle_write(&mut self, fd: RawFd) -> crate::worker::Result<()> {
        self.inner.handle_write(fd)
    }

    fn is_done(&self) -> bool {
        self.inner.is_done()
    }

    fn retcodes(&self) -> &HashMap<String, i32> {
        self.inner.retcodes()
    }

    fn num_nodes(&self) -> usize {
        self.inner.num_nodes()
    }

    fn take_handler(&mut self) -> Option<Box<dyn EventHandler>> {
        self.inner.take_handler()
    }
}

/// Worker that copies files to/from remote nodes via SCP.
///
/// Mirrors ClusterShell's ScpClient / WorkerSsh copy mode.
pub struct ScpWorker {
    /// Underlying ExecWorker for running SCP commands.
    inner: ExecWorker,
    /// SSH/SCP options.
    #[allow(dead_code)]
    ssh_options: SshOptions,
    /// Source path.
    source: String,
    /// Destination path.
    dest: String,
    /// Whether this is a reverse copy (remote -> local).
    reverse: bool,
}

impl ScpWorker {
    /// Create a new ScpWorker for file copy.
    ///
    /// # Arguments
    /// * `nodes` - Remote nodes to copy to/from.
    /// * `source` - Source file/directory path.
    /// * `dest` - Destination file/directory path.
    /// * `fanout` - Max concurrent SCP operations.
    /// * `timeout` - Optional per-node timeout.
    /// * `ssh_options` - SSH/SCP options.
    /// * `reverse` - If true, copy from remote to local.
    /// * `preserve` - If true, preserve file attributes.
    /// * `directory` - If true, copy recursively.
    pub fn new(
        nodes: Vec<String>,
        source: String,
        dest: String,
        fanout: usize,
        timeout: Option<Duration>,
        ssh_options: SshOptions,
        reverse: bool,
        preserve: bool,
        directory: bool,
    ) -> Self {
        // Build SCP command with %h placeholder for node substitution
        let scp_cmd = ssh_options.build_scp_cmd("%h", &source, &dest, reverse, preserve, directory);

        ScpWorker {
            inner: ExecWorker::new(nodes, scp_cmd, fanout, timeout),
            ssh_options,
            source,
            dest,
            reverse,
        }
    }

    /// Get the source path.
    pub fn source(&self) -> &str {
        &self.source
    }

    /// Get the destination path.
    pub fn dest(&self) -> &str {
        &self.dest
    }

    /// Whether this is a reverse copy.
    pub fn is_reverse(&self) -> bool {
        self.reverse
    }
}

impl Worker for ScpWorker {
    fn start(&mut self) -> crate::worker::Result<()> {
        self.inner.start()
    }

    fn abort(&mut self, kill: bool) {
        self.inner.abort(kill);
    }

    fn state(&self) -> WorkerState {
        self.inner.state()
    }

    fn set_handler(&mut self, handler: Box<dyn EventHandler>) {
        self.inner.set_handler(handler);
    }

    fn read_fds(&self) -> Vec<RawFd> {
        self.inner.read_fds()
    }

    fn write_fds(&self) -> Vec<RawFd> {
        self.inner.write_fds()
    }

    fn handle_read(&mut self, fd: RawFd) -> crate::worker::Result<()> {
        self.inner.handle_read(fd)
    }

    fn handle_write(&mut self, fd: RawFd) -> crate::worker::Result<()> {
        self.inner.handle_write(fd)
    }

    fn is_done(&self) -> bool {
        self.inner.is_done()
    }

    fn retcodes(&self) -> &HashMap<String, i32> {
        self.inner.retcodes()
    }

    fn num_nodes(&self) -> usize {
        self.inner.num_nodes()
    }

    fn take_handler(&mut self) -> Option<Box<dyn EventHandler>> {
        self.inner.take_handler()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_ssh_options_default() {
        let opts = SshOptions::default();
        assert_eq!(opts.ssh_path, "ssh");
        assert_eq!(opts.scp_path, "scp");
        assert!(opts.user.is_none());
        assert_eq!(opts.connect_timeout, Some(10));
        assert!(!opts.strict_host_key_checking);
        assert!(!opts.password_auth);
    }

    #[test]
    fn test_ssh_options_build_ssh_cmd() {
        let opts = SshOptions::default();
        let cmd = opts.build_ssh_cmd("node1", "uname -a");

        assert!(cmd.starts_with("ssh "));
        assert!(cmd.contains("-oForwardX11=no"));
        assert!(cmd.contains("-oStrictHostKeyChecking=no"));
        assert!(cmd.contains("-oPasswordAuthentication=no"));
        assert!(cmd.contains("-oConnectTimeout=10"));
        assert!(cmd.contains("node1"));
        assert!(cmd.ends_with("uname -a"));
    }

    #[test]
    fn test_ssh_options_build_ssh_cmd_with_user() {
        let opts = SshOptions {
            user: Some("admin".to_string()),
            ..SshOptions::default()
        };
        let cmd = opts.build_ssh_cmd("node1", "hostname");

        assert!(cmd.contains("-l admin"));
        assert!(cmd.contains("node1"));
    }

    #[test]
    fn test_ssh_options_build_ssh_cmd_custom_options() {
        let opts = SshOptions {
            options: vec!["BatchMode=yes".to_string()],
            ..SshOptions::default()
        };
        let cmd = opts.build_ssh_cmd("node1", "ls");

        assert!(cmd.contains("-oBatchMode=yes"));
    }

    #[test]
    fn test_ssh_options_build_scp_cmd_forward() {
        let opts = SshOptions::default();
        let cmd = opts.build_scp_cmd("node1", "/tmp/file.txt", "/home/user/", false, true, false);

        assert!(cmd.starts_with("scp "));
        assert!(cmd.contains("-p")); // preserve
        assert!(cmd.contains("/tmp/file.txt"));
        assert!(cmd.contains("node1:/home/user/"));
    }

    #[test]
    fn test_ssh_options_build_scp_cmd_reverse() {
        let opts = SshOptions::default();
        let cmd = opts.build_scp_cmd(
            "node1",
            "/remote/file.txt",
            "/local/dir/",
            true,
            false,
            false,
        );

        assert!(cmd.contains("node1:/remote/file.txt"));
        assert!(cmd.ends_with("/local/dir/"));
    }

    #[test]
    fn test_ssh_options_build_scp_cmd_recursive() {
        let opts = SshOptions::default();
        let cmd = opts.build_scp_cmd("node1", "/src/", "/dst/", false, false, true);

        assert!(cmd.contains("-r")); // recursive
    }

    #[test]
    fn test_ssh_options_build_scp_cmd_with_user() {
        let opts = SshOptions {
            user: Some("deploy".to_string()),
            ..SshOptions::default()
        };
        let cmd = opts.build_scp_cmd("node1", "/f", "/d", false, false, false);

        assert!(cmd.contains("deploy@node1:/d"));
    }

    #[test]
    fn test_ssh_worker_creation() {
        let nodes = vec!["node1".to_string(), "node2".to_string()];
        let worker = SshWorker::with_defaults(nodes, "hostname".to_string(), 64, None);

        assert_eq!(worker.state(), WorkerState::Pending);
        assert_eq!(worker.num_nodes(), 2);
        assert_eq!(worker.original_command(), "hostname");
    }

    #[test]
    fn test_ssh_worker_custom_options() {
        let opts = SshOptions {
            user: Some("root".to_string()),
            connect_timeout: Some(5),
            ..SshOptions::default()
        };
        let nodes = vec!["node1".to_string()];
        let worker = SshWorker::new(nodes, "uptime".to_string(), 64, None, opts);

        assert_eq!(worker.ssh_options().user.as_deref(), Some("root"));
        assert_eq!(worker.ssh_options().connect_timeout, Some(5));
    }

    #[test]
    fn test_ssh_worker_with_stderr() {
        let nodes = vec!["node1".to_string()];
        let worker = SshWorker::with_defaults(nodes, "ls".to_string(), 64, None).with_stderr(true);

        assert_eq!(worker.state(), WorkerState::Pending);
    }

    #[test]
    fn test_scp_worker_creation() {
        let nodes = vec!["node1".to_string()];
        let opts = SshOptions::default();
        let worker = ScpWorker::new(
            nodes,
            "/local/file".to_string(),
            "/remote/dir".to_string(),
            64,
            None,
            opts,
            false,
            true,
            false,
        );

        assert_eq!(worker.state(), WorkerState::Pending);
        assert_eq!(worker.source(), "/local/file");
        assert_eq!(worker.dest(), "/remote/dir");
        assert!(!worker.is_reverse());
    }

    #[test]
    fn test_scp_worker_reverse() {
        let nodes = vec!["node1".to_string()];
        let opts = SshOptions::default();
        let worker = ScpWorker::new(
            nodes,
            "/remote/file".to_string(),
            "/local/dir".to_string(),
            64,
            None,
            opts,
            true,
            false,
            false,
        );

        assert!(worker.is_reverse());
        assert_eq!(worker.num_nodes(), 1);
    }

    #[test]
    fn test_ssh_options_with_identity_file() {
        let opts = SshOptions {
            identity_file: Some("/path/to/key".to_string()),
            ..SshOptions::default()
        };
        let cmd = opts.build_ssh_cmd("node1", "hostname");
        assert!(cmd.contains("-i /path/to/key"));
    }

    #[test]
    fn test_ssh_options_with_config_file() {
        let opts = SshOptions {
            config_file: Some("/etc/ssh/config".to_string()),
            ..SshOptions::default()
        };
        let cmd = opts.build_ssh_cmd("node1", "hostname");
        assert!(cmd.contains("-F /etc/ssh/config"));
    }

    #[test]
    fn test_ssh_options_with_control_master() {
        let opts = SshOptions {
            control_master: Some(ControlMaster::Auto),
            control_path: Some("/tmp/ssh-%r@%h:%p".to_string()),
            control_persist: Some("10m".to_string()),
            ..SshOptions::default()
        };
        let cmd = opts.build_ssh_cmd("node1", "hostname");
        assert!(cmd.contains("-oControlMaster=auto"));
        assert!(cmd.contains("-oControlPath=/tmp/ssh-%r@%h:%p"));
        assert!(cmd.contains("-oControlPersist=10m"));
    }

    #[test]
    fn test_ssh_options_with_proxy_jump() {
        let opts = SshOptions {
            proxy_jump: Some("bastion.example.com".to_string()),
            ..SshOptions::default()
        };
        let cmd = opts.build_ssh_cmd("node1", "hostname");
        assert!(cmd.contains("-J bastion.example.com"));
    }

    #[test]
    fn test_ssh_options_with_port() {
        let opts = SshOptions {
            port: Some(2222),
            ..SshOptions::default()
        };
        let ssh_cmd = opts.build_ssh_cmd("node1", "hostname");
        assert!(ssh_cmd.contains("-p 2222"));

        let scp_cmd = opts.build_scp_cmd("node1", "/src", "/dst", false, false, false);
        assert!(scp_cmd.contains("-P 2222")); // SCP uses uppercase -P
    }

    #[test]
    fn test_scp_options_with_control_master() {
        let opts = SshOptions {
            control_master: Some(ControlMaster::Auto),
            control_path: Some("/tmp/ssh-%r@%h:%p".to_string()),
            identity_file: Some("/key".to_string()),
            ..SshOptions::default()
        };
        let cmd = opts.build_scp_cmd("node1", "/src", "/dst", false, false, false);
        assert!(cmd.contains("-oControlMaster=auto"));
        assert!(cmd.contains("-oControlPath=/tmp/ssh-%r@%h:%p"));
        assert!(cmd.contains("-i /key"));
    }

    #[test]
    fn test_ssh_worker_abort() {
        let nodes = vec!["node1".to_string()];
        let mut worker = SshWorker::with_defaults(nodes, "sleep 100".to_string(), 64, None);

        worker.abort(true);
        assert_eq!(worker.state(), WorkerState::Aborted);
    }
}