diff options
| author | Taras Madan <tarasmadan@google.com> | 2025-03-26 16:29:08 +0100 |
|---|---|---|
| committer | Taras Madan <tarasmadan@google.com> | 2025-03-27 10:07:16 +0000 |
| commit | b181c36d588da8d6007a23c0ad7305893758cec5 (patch) | |
| tree | 610856168965d1f7c9ed219327c507ce46f5e22c /vm/isolated/isolated.go | |
| parent | f2f5b9669a4d459e13b12f9e7616ca3c5ddb26e0 (diff) | |
vm: use SSHOptions instead of 4 params
It reduces WaitForSSH parameter count from 9 to 6.
Diffstat (limited to 'vm/isolated/isolated.go')
| -rwxr-xr-x | vm/isolated/isolated.go | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/vm/isolated/isolated.go b/vm/isolated/isolated.go index 2e5ce50a9..eb70cf369 100755 --- a/vm/isolated/isolated.go +++ b/vm/isolated/isolated.go @@ -46,15 +46,12 @@ type Pool struct { } type instance struct { - cfg *Config + cfg *Config + vmimpl.SSHOptions os string - targetAddr string - targetPort int index int closed chan bool debug bool - sshUser string - sshKey string forwardPort int timeouts targets.Timeouts } @@ -97,16 +94,18 @@ func (pool *Pool) Count() int { func (pool *Pool) Create(workdir string, index int) (vmimpl.Instance, error) { targetAddr, targetPort, _ := splitTargetPort(pool.cfg.Targets[index]) inst := &instance{ - cfg: pool.cfg, - os: pool.env.OS, - targetAddr: targetAddr, - targetPort: targetPort, - index: index, - closed: make(chan bool), - debug: pool.env.Debug, - sshUser: pool.env.SSHUser, - sshKey: pool.env.SSHKey, - timeouts: pool.env.Timeouts, + cfg: pool.cfg, + os: pool.env.OS, + SSHOptions: vmimpl.SSHOptions{ + Addr: targetAddr, + Port: targetPort, + User: pool.env.SSHUser, + Key: pool.env.SSHKey, + }, + index: index, + closed: make(chan bool), + debug: pool.env.Debug, + timeouts: pool.env.Timeouts, } closeInst := inst defer func() { @@ -158,8 +157,8 @@ func (inst *instance) ssh(command string) error { } // TODO(dvyukov): who is closing rpipe? - args := append(vmimpl.SSHArgs(inst.debug, inst.sshKey, inst.targetPort, inst.cfg.SystemSSHCfg), - inst.sshUser+"@"+inst.targetAddr, command) + args := append(vmimpl.SSHArgs(inst.debug, inst.Key, inst.Port, inst.cfg.SystemSSHCfg), + inst.User+"@"+inst.Addr, command) if inst.debug { log.Logf(0, "running command: ssh %#v", args) } @@ -255,8 +254,7 @@ func (inst *instance) repair() error { } func (inst *instance) waitForSSH(timeout time.Duration) error { - return vmimpl.WaitForSSH(inst.debug, timeout, inst.targetAddr, inst.sshKey, inst.sshUser, - inst.os, inst.targetPort, nil, inst.cfg.SystemSSHCfg) + return vmimpl.WaitForSSH(timeout, inst.SSHOptions, inst.os, nil, inst.cfg.SystemSSHCfg, inst.debug) } func (inst *instance) waitForReboot(timeout int) error { @@ -286,8 +284,8 @@ func (inst *instance) Copy(hostSrc string) (string, error) { baseName := filepath.Base(hostSrc) vmDst := filepath.Join(inst.cfg.TargetDir, baseName) inst.ssh("pkill -9 '" + baseName + "'; rm -f '" + vmDst + "'") - args := append(vmimpl.SCPArgs(inst.debug, inst.sshKey, inst.targetPort, inst.cfg.SystemSSHCfg), - hostSrc, inst.sshUser+"@"+inst.targetAddr+":"+vmDst) + args := append(vmimpl.SCPArgs(inst.debug, inst.Key, inst.Port, inst.cfg.SystemSSHCfg), + hostSrc, inst.User+"@"+inst.Addr+":"+vmDst) cmd := osutil.Command("scp", args...) if inst.debug { log.Logf(0, "running command: scp %#v", args) @@ -315,8 +313,8 @@ func (inst *instance) Copy(hostSrc string) (string, error) { func (inst *instance) Run(timeout time.Duration, stop <-chan bool, command string) ( <-chan []byte, <-chan error, error) { - args := append(vmimpl.SSHArgs(inst.debug, inst.sshKey, inst.targetPort, inst.cfg.SystemSSHCfg), - inst.sshUser+"@"+inst.targetAddr) + args := append(vmimpl.SSHArgs(inst.debug, inst.Key, inst.Port, inst.cfg.SystemSSHCfg), + inst.User+"@"+inst.Addr) dmesg, err := vmimpl.OpenRemoteConsole("ssh", args...) if err != nil { return nil, nil, err @@ -328,12 +326,12 @@ func (inst *instance) Run(timeout time.Duration, stop <-chan bool, command strin return nil, nil, err } - args = vmimpl.SSHArgsForward(inst.debug, inst.sshKey, inst.targetPort, inst.forwardPort, inst.cfg.SystemSSHCfg) + args = vmimpl.SSHArgsForward(inst.debug, inst.Key, inst.Port, inst.forwardPort, inst.cfg.SystemSSHCfg) if inst.cfg.Pstore { args = append(args, "-o", "ServerAliveInterval=6") args = append(args, "-o", "ServerAliveCountMax=5") } - args = append(args, inst.sshUser+"@"+inst.targetAddr, "cd "+inst.cfg.TargetDir+" && exec "+command) + args = append(args, inst.User+"@"+inst.Addr, "cd "+inst.cfg.TargetDir+" && exec "+command) if inst.debug { log.Logf(0, "running command: ssh %#v", args) } @@ -367,8 +365,8 @@ func (inst *instance) Run(timeout time.Duration, stop <-chan bool, command strin func (inst *instance) readPstoreContents() ([]byte, error) { log.Logf(0, "reading pstore contents") - args := append(vmimpl.SSHArgs(inst.debug, inst.sshKey, inst.targetPort, inst.cfg.SystemSSHCfg), - inst.sshUser+"@"+inst.targetAddr, "cat "+pstoreConsoleFile+" && rm "+pstoreConsoleFile) + args := append(vmimpl.SSHArgs(inst.debug, inst.Key, inst.Port, inst.cfg.SystemSSHCfg), + inst.User+"@"+inst.Addr, "cat "+pstoreConsoleFile+" && rm "+pstoreConsoleFile) if inst.debug { log.Logf(0, "running command: ssh %#v", args) } |
