9
9
"fmt"
10
10
"io/fs"
11
11
"os"
12
+ "strings"
12
13
"time"
13
14
14
15
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
@@ -27,7 +28,7 @@ import (
27
28
const (
28
29
// Waiting for only 10s as we expect remote to be ready when provisioning
29
30
sshRetryInterval = 2 * time .Second
30
- sshMaxRetries = 5
31
+ sshMaxRetries = 20
31
32
)
32
33
33
34
// RemoteHost represents a remote host
@@ -43,21 +44,33 @@ var _ e2e.Initializable = &RemoteHost{}
43
44
// Init is called by e2e test Suite after the component is provisioned.
44
45
func (h * RemoteHost ) Init (ctx e2e.Context ) error {
45
46
h .context = ctx
46
- return h .ReconnectSSH ()
47
+ return h .reconnectSSH ()
47
48
}
48
49
49
50
// Execute executes a command and returns an error if any.
50
51
func (h * RemoteHost ) Execute (command string , options ... ExecuteOption ) (string , error ) {
52
+ var err error
53
+ var output string
54
+
51
55
params , err := optional .MakeParams (options ... )
52
56
if err != nil {
53
57
return "" , err
54
58
}
59
+
55
60
cmd := h .buildEnvVariables (command , params .EnvVariables )
61
+ output , err = clients .ExecuteCommand (h .client , cmd )
56
62
57
- output , err := clients .ExecuteCommand (h .client , cmd )
63
+ if err != nil && strings .Contains (err .Error (), "failed to create session:" ) {
64
+ err = h .reconnectSSH ()
65
+ if err != nil {
66
+ return "" , err
67
+ }
68
+ output , err = clients .ExecuteCommand (h .client , cmd )
69
+ }
58
70
if err != nil {
59
71
return "" , fmt .Errorf ("%v: %v" , output , err )
60
72
}
73
+
61
74
return output , nil
62
75
}
63
76
@@ -130,9 +143,9 @@ func (h *RemoteHost) RemoveAll(path string) error {
130
143
return clients .RemoveAll (h .client , path )
131
144
}
132
145
133
- // ReconnectSSH recreate the SSH connection to the VM. Should be used only after VM reboot to restore the SSH connection.
146
+ // reconnectSSH recreate the SSH connection to the VM. Should be used only after VM reboot to restore the SSH connection.
134
147
// Returns an error if the VM is not reachable after retries.
135
- func (h * RemoteHost ) ReconnectSSH () error {
148
+ func (h * RemoteHost ) reconnectSSH () error {
136
149
h .context .T ().Logf ("connecting to remote VM at %s@%s" , h .Username , h .Address )
137
150
138
151
if h .client != nil {
0 commit comments