@@ -14,31 +14,33 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- package binremote
17
+ package remote
18
18
19
19
import (
20
20
"fmt"
21
21
"path"
22
22
"path/filepath"
23
+ "strconv"
24
+ "strings"
23
25
24
26
"github.com/golang/glog"
25
27
)
26
28
27
- func (i * InstanceInfo ) UploadAndRun (archivePath , remoteWorkspace , driverRunCmd string ) error {
29
+ func (i * InstanceInfo ) UploadAndRun (archivePath , remoteWorkspace , driverRunCmd string ) ( int , error ) {
28
30
29
31
// Create the temp staging directory
30
32
glog .V (4 ).Infof ("Staging test binaries on %q" , i .name )
31
33
32
34
// Do not sudo here, so that we can use scp to copy test archive to the directdory.
33
35
if output , err := i .SSHNoSudo ("mkdir" , remoteWorkspace ); err != nil {
34
36
// Exit failure with the error
35
- return fmt .Errorf ("failed to create remoteWorkspace directory %q on i.name %q: %v output: %q" , remoteWorkspace , i .name , err , output )
37
+ return - 1 , fmt .Errorf ("failed to create remoteWorkspace directory %q on i.name %q: %v output: %q" , remoteWorkspace , i .name , err , output )
36
38
}
37
39
38
40
// Copy the archive to the staging directory
39
41
if output , err := runSSHCommand ("scp" , archivePath , fmt .Sprintf ("%s:%s/" , i .GetSSHTarget (), remoteWorkspace )); err != nil {
40
42
// Exit failure with the error
41
- return fmt .Errorf ("failed to copy test archive: %v, output: %q" , err , output )
43
+ return - 1 , fmt .Errorf ("failed to copy test archive: %v, output: %q" , err , output )
42
44
}
43
45
44
46
// Extract the archive
@@ -52,22 +54,40 @@ func (i *InstanceInfo) UploadAndRun(archivePath, remoteWorkspace, driverRunCmd s
52
54
// we want the extracted files to be owned by the current user.
53
55
if output , err := i .SSHNoSudo ("sh" , "-c" , cmd ); err != nil {
54
56
// Exit failure with the error
55
- return fmt .Errorf ("failed to extract test archive: %v, output: %q" , err , output )
57
+ return - 1 , fmt .Errorf ("failed to extract test archive: %v, output: %q" , err , output )
56
58
}
57
59
58
60
glog .V (4 ).Infof ("Starting driver on %q" , i .name )
59
61
// When the process is killed the driver should close the TCP endpoint, then we want to download the logs
60
62
output , err := i .SSH (driverRunCmd )
63
+ if err != nil {
64
+ // Exit failure with the error
65
+ return - 1 , fmt .Errorf ("failed start driver, got output: %v, error: %v" , output , err )
66
+ }
61
67
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 )
62
78
if err != nil {
63
79
// Exit failure with the error
64
- return fmt .Errorf ("failed start GCE PD driver, got output: %v, error: %v" , output , err )
80
+ return - 1 , fmt .Errorf ("failed to get PID of driver, got output: %v, error: %v" , output , err )
65
81
}
66
82
83
+ driverPID , err := strconv .Atoi (strings .Fields (driverPIDString )[1 ])
84
+ if err != nil {
85
+ return - 1 , fmt .Errorf ("failed to convert driver PID from string %s to int: %v" , driverPIDString , err )
86
+ }
67
87
// TODO: return the PID so that we can kill the driver later
68
88
// Actually just do a pkill -f my_pattern
69
89
70
- return nil
90
+ return driverPID , nil
71
91
}
72
92
73
93
func NewWorkspaceDir (workspaceDirPrefix string ) string {
0 commit comments