terratest
terratest copied to clipboard
SSH to public host "hostname" returned an error: dial tcp: lookup "hostname": no such host. Sleeping for 5s and will try again
Getting this error using the ssh go script. Any ideas on how to resolve this ?
SH to public host "hostip" returned an error: dial tcp: lookup "hostip": no such host. Sleeping for 5s and will try again
I am also facing similar issue
end2end_test.go:80: Cannot establish SSH connection to vm-linux-1 public IP address: dial tcp: lookup "52.148.xxx.xx": no such host
Impossible to say without more context: i.e., your implementation code, your test code, the full log output. Without that, the only thing I can do is blindly guess: e.g., if you happen to be trying to SSH to an EC2 instance you just deployed (e.g. via terraform apply
), then it takes ~1 minute for the instance to boot and be able to accept SSH connections, and until then, you'll get connection errors. Therefore, we typically do SSH connections in a retry loop using the retry
package.
I am facing something similar...
func executeCmd(t *testing.T, command, hostname string, port string, config *ssh.ClientConfig) string {
conn, err := ssh.Dial("tcp", fmt.Sprintf("%s:%s", hostname, port), config)
if err != nil {
t.Fatalf("Cannot establish SSH connection to the vm public IP address: %v", err)
}
...
Called with:
output := executeCmd(t, command, vmPublicIPAddress, "22", sshConfig)
The VM is up and running, I can ssh into without problems. Yet Terratest says:
--- FAIL: TestEndToEndDeploymentScenario (1129.75s)
end2end_test.go:86: Cannot establish SSH connection to the vm public IP address: dial tcp: lookup "40.113.19.17": no such host
Similar code, executed outside of Terratest, works fine:
package main
import (
"bytes"
"fmt"
"golang.org/x/crypto/ssh"
)
func main() {
kkk := `-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----`
signer, err := ssh.ParsePrivateKey([]byte(kkk))
if err != nil {
fmt.Printf("Unable to parse key: %v", err)
}
sshConfig := &ssh.ClientConfig{
User: "azureuser",
Auth: []ssh.AuthMethod{
ssh.PublicKeys(signer),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}
conn, err := ssh.Dial("tcp", "40.113.19.17:22", sshConfig)
if err != nil {
fmt.Printf("Cannot establish SSH connection to the vm public IP address: %v", err)
}
session, err := conn.NewSession()
if err != nil {
fmt.Printf("Cannot create SSH session to the vm public IP address: %v", err)
}
defer session.Close()
defer conn.Close()
var stdoutBuf bytes.Buffer
session.Stdout = &stdoutBuf
err = session.Run("uname -a")
if err != nil {
fmt.Printf("Cannot execute SSH command: %v", err)
}
fmt.Printf(stdoutBuf.String())
}
This could be a bug in Terratest, or perhaps some issue with the way Go resolves DNS. @anouarchattouna, I think you hit something similar... Did you ever get it figured out?
This could be a bug in Terratest, or perhaps some issue with the way Go resolves DNS. @anouarchattouna, I think you hit something similar... Did you ever get it figured out?
Unfortunately not, I switched to a fresh environment with recent version of Go and I had no error
Same here, I updated my dependencies to the latest version of the Terratest module and also upgraded from Go 1.15 to 1.16. It's working fine now...
After updating the Go version i am getting same error message: " Cannot establish SSH connection to vm-linux-1 public IP address: dial tcp: lookup XX.XX.XX.XX: no such host.
Same here, I updated my dependencies to the latest version of the Terratest module and also upgraded from Go 1.15 to 1.16. It's working fine now...
@tomconte do you remember which specific Go version 1.16.x worked for you? Currently having the same problem with go 1.17.1 and planning to downgrade to a stable 1.16.x version. This is the error message I'm getting: "end2end_test.go:83: Cannot establish SSH connection to vm-linux-1 public IP address: dial tcp: lookup "XX.XXX.XX.XXX": no such host"
any fix for this?