@@ -18,15 +18,14 @@ package remote
18
18
19
19
import (
20
20
"fmt"
21
- "path"
22
21
"path/filepath"
23
22
"strconv"
24
23
"strings"
25
24
26
25
"k8s.io/klog/v2"
27
26
)
28
27
29
- func (i * InstanceInfo ) UploadAndRun (archivePath , remoteWorkspace , driverRunCmd string ) (int , error ) {
28
+ func (i * InstanceInfo ) UploadAndRun (archiveName , archivePath , remoteWorkspace , driverRunCmd , pkgPath string ) (int , error ) {
30
29
31
30
// Create the temp staging directory
32
31
klog .V (4 ).Infof ("Staging test binaries on %q" , i .cfg .Name )
@@ -37,53 +36,54 @@ func (i *InstanceInfo) UploadAndRun(archivePath, remoteWorkspace, driverRunCmd s
37
36
return - 1 , fmt .Errorf ("failed to create remoteWorkspace directory %q on instance %q: %v output: %q" , remoteWorkspace , i .cfg .Name , err .Error (), output )
38
37
}
39
38
40
- // Copy the archive to the staging directory
41
- if output , err := runSSHCommand ("scp" , archivePath , fmt .Sprintf ("%s:%s/" , i .GetSSHTarget (), remoteWorkspace )); err != nil {
39
+ // Copy the setup script to the staging directory
40
+ if output , err := runSSHCommand ("scp" , fmt . Sprintf ( "%s/test/e2e/utils/setup-remote.sh" , pkgPath ) , fmt .Sprintf ("%s:%s/" , i .GetSSHTarget (), remoteWorkspace )); err != nil {
42
41
// Exit failure with the error
43
42
return - 1 , fmt .Errorf ("failed to copy test archive: %v, output: %q" , err .Error (), output )
44
43
}
45
44
46
- // Extract the archive
47
- archiveName := path .Base (archivePath )
48
- cmd := getSSHCommand (" && " ,
49
- fmt .Sprintf ("cd %s" , remoteWorkspace ),
50
- fmt .Sprintf ("tar -xzvf ./%s" , archiveName ),
51
- )
52
- klog .V (4 ).Infof ("Extracting tar on %q" , i .cfg .Name )
53
- // Do not use sudo here, because `sudo tar -x` will recover the file ownership inside the tar ball, but
54
- // we want the extracted files to be owned by the current user.
55
- if output , err := i .SSHNoSudo ("sh" , "-c" , cmd ); err != nil {
56
- // Exit failure with the error
57
- return - 1 , fmt .Errorf ("failed to extract test archive: %v, output: %q" , err .Error (), output )
45
+ // Set up the VM env with docker and make
46
+ if output , err := i .SSH ("sh" , "-c" , fmt .Sprintf ("%s/setup-remote.sh" , remoteWorkspace )); err != nil {
47
+ return - 1 , fmt .Errorf ("failed to setup VM environment: %v, output: %q" , err .Error (), output )
48
+ }
49
+
50
+ // Upload local image to remote
51
+ if output , err := runSSHCommand ("scp" , archivePath , fmt .Sprintf ("%s:%s/" , i .GetSSHTarget (), remoteWorkspace )); err != nil {
52
+ return - 1 , fmt .Errorf ("failed to copy image archive: %v, output: %q" , err , output )
58
53
}
59
54
55
+ // Run PD CSI driver as a container
60
56
klog .V (4 ).Infof ("Starting driver on %q" , i .cfg .Name )
61
- // When the process is killed the driver should close the TCP endpoint, then we want to download the logs
62
- output , err := i .SSH (driverRunCmd )
57
+ cmd := getSSHCommand (" && " ,
58
+ fmt .Sprintf ("docker load -i %v/%v" , remoteWorkspace , archiveName ),
59
+ driverRunCmd ,
60
+ )
61
+ output , err := i .SSH ("sh" , "-c" , cmd )
63
62
if err != nil {
64
- // Exit failure with the error
65
- return - 1 , fmt .Errorf ("failed start driver, got output: %v, error: %v" , output , err .Error ())
63
+ return - 1 , fmt .Errorf ("failed to load or run docker image: %v, output: %q" , err , output )
66
64
}
67
65
68
- // Get the driver PID
69
- // ps -aux | grep /tmp/gce-pd-e2e-0180801T114407/gce-pd-csi-driver | awk '{print $2}'
70
- driverPIDCmd := getSSHCommand (" | " ,
71
- "ps -aux" ,
72
- fmt .Sprintf ("grep %s" , remoteWorkspace ),
73
- "grep -v grep" ,
74
- // All ye who try to deal with escaped/non-escaped quotes with exec beware.
75
- //`awk "{print \$2}"`,
76
- )
77
- driverPIDString , err := i .SSHNoSudo ("sh" , "-c" , driverPIDCmd )
66
+ // Grab the container ID from `docker run` output
67
+ driverRunOutputs := strings .Split (output , "\n " )
68
+ numSplits := len (driverRunOutputs )
69
+ if numSplits < 2 {
70
+ return - 1 , fmt .Errorf ("failed to get driver container ID from driver run outputs, outputs are: %v" , output )
71
+ }
72
+ // Grabbing the second last split because it contains an empty string
73
+ driverContainerID := driverRunOutputs [len (driverRunOutputs )- 2 ]
74
+
75
+ // Grab driver PID from container ID
76
+ driverPIDStr , err := i .SSH (fmt .Sprintf ("docker inspect -f {{.State.Pid}} %v" , driverContainerID ))
78
77
if err != nil {
79
78
// Exit failure with the error
80
- return - 1 , fmt .Errorf ("failed to get PID of driver, got output: %v, error: %v" , output , err .Error ())
79
+ return - 1 , fmt .Errorf ("failed to get PID of driver, got output: %v, error: %v" , driverPIDStr , err .Error ())
81
80
}
82
-
83
- driverPID , err := strconv .Atoi (strings . Fields ( driverPIDString )[ 1 ] )
81
+ driverPIDStr = strings . TrimSpace ( driverPIDStr )
82
+ driverPID , err := strconv .Atoi (driverPIDStr )
84
83
if err != nil {
85
- return - 1 , fmt .Errorf ("failed to convert driver PID from string %s to int: %v" , driverPIDString , err .Error ())
84
+ return - 1 , fmt .Errorf ("failed to convert driver PID from string %s to int: %v" , driverPIDStr , err .Error ())
86
85
}
86
+ klog .V (4 ).Infof ("Driver PID is: %v" , driverPID )
87
87
88
88
return driverPID , nil
89
89
}
0 commit comments