Add flag to node e2e test specifying location of ssh privkey

This commit is contained in:
Jeff Grafton
2016-12-20 15:08:49 -08:00
parent 1955ed614f
commit 30a5efa33b
3 changed files with 13 additions and 1 deletions

View File

@@ -29,9 +29,11 @@ import (
var sshOptions = flag.String("ssh-options", "", "Commandline options passed to ssh.")
var sshEnv = flag.String("ssh-env", "", "Use predefined ssh options for environment. Options: gce")
var sshKey = flag.String("ssh-key", "", "Path to ssh private key.")
var sshUser = flag.String("ssh-user", "", "Use predefined user for ssh.")
var sshOptionsMap map[string]string
var sshDefaultKeyMap map[string]string
func init() {
usr, err := user.Current()
@@ -39,7 +41,10 @@ func init() {
glog.Fatal(err)
}
sshOptionsMap = map[string]string{
"gce": fmt.Sprintf("-i %s/.ssh/google_compute_engine -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o CheckHostIP=no -o StrictHostKeyChecking=no -o ServerAliveInterval=30 -o LogLevel=ERROR", usr.HomeDir),
"gce": "-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o CheckHostIP=no -o StrictHostKeyChecking=no -o ServerAliveInterval=30 -o LogLevel=ERROR",
}
sshDefaultKeyMap = map[string]string{
"gce": fmt.Sprintf("%s/.ssh/google_compute_engine", usr.HomeDir),
}
}
@@ -87,6 +92,11 @@ func SSHNoSudo(host string, cmd ...string) (string, error) {
// runSSHCommand executes the ssh or scp command, adding the flag provided --ssh-options
func runSSHCommand(cmd string, args ...string) (string, error) {
if *sshKey != "" {
args = append([]string{"-i", *sshKey}, args...)
} else if key, found := sshDefaultKeyMap[*sshEnv]; found {
args = append([]string{"-i", key}, args...)
}
if env, found := sshOptionsMap[*sshEnv]; found {
args = append(strings.Split(env, " "), args...)
}