1
1
/*
2
- Copyright 2016 The Kubernetes Authors.
2
+ Copyright 2018 The Kubernetes Authors.
3
3
4
4
Licensed under the Apache License, Version 2.0 (the "License");
5
5
you may not use this file except in compliance with the License.
@@ -18,46 +18,46 @@ package binremote
18
18
19
19
import (
20
20
"fmt"
21
+ "path"
21
22
"path/filepath"
22
23
23
24
"github.com/golang/glog"
24
25
)
25
26
26
- func (i * InstanceInfo ) UploadAndRun (archivePath , archiveName , instanceName , port string ) error {
27
- endpoint := fmt .Sprintf ("tcp://localhost:%s" , port )
28
- workspace := newWorkspaceDir ()
27
+ func (i * InstanceInfo ) UploadAndRun (archivePath , remoteWorkspace , driverRunCmd string ) error {
29
28
30
29
// Create the temp staging directory
31
- glog .V (2 ).Infof ("Staging test binaries on %q" , i .name )
30
+ glog .V (4 ).Infof ("Staging test binaries on %q" , i .name )
32
31
33
32
// Do not sudo here, so that we can use scp to copy test archive to the directdory.
34
- if output , err := i .SSHNoSudo ("mkdir" , workspace ); err != nil {
33
+ if output , err := i .SSHNoSudo ("mkdir" , remoteWorkspace ); err != nil {
35
34
// Exit failure with the error
36
- return fmt .Errorf ("failed to create workspace directory %q on i.name %q: %v output: %q" , workspace , i .name , err , output )
35
+ return fmt .Errorf ("failed to create remoteWorkspace directory %q on i.name %q: %v output: %q" , remoteWorkspace , i .name , err , output )
37
36
}
38
37
39
38
// Copy the archive to the staging directory
40
- if output , err := runSSHCommand ("scp" , archivePath , fmt .Sprintf ("%s:%s/" , i .GetSSHTarget (), workspace )); err != nil {
39
+ if output , err := runSSHCommand ("scp" , archivePath , fmt .Sprintf ("%s:%s/" , i .GetSSHTarget (), remoteWorkspace )); err != nil {
41
40
// Exit failure with the error
42
41
return fmt .Errorf ("failed to copy test archive: %v, output: %q" , err , output )
43
42
}
44
43
45
44
// Extract the archive
45
+ archiveName := path .Base (archivePath )
46
46
cmd := getSSHCommand (" && " ,
47
- fmt .Sprintf ("cd %s" , workspace ),
47
+ fmt .Sprintf ("cd %s" , remoteWorkspace ),
48
48
fmt .Sprintf ("tar -xzvf ./%s" , archiveName ),
49
49
)
50
- glog .V (2 ).Infof ("Extracting tar on %q" , i .name )
50
+ glog .V (4 ).Infof ("Extracting tar on %q" , i .name )
51
51
// Do not use sudo here, because `sudo tar -x` will recover the file ownership inside the tar ball, but
52
52
// we want the extracted files to be owned by the current user.
53
53
if output , err := i .SSHNoSudo ("sh" , "-c" , cmd ); err != nil {
54
54
// Exit failure with the error
55
55
return fmt .Errorf ("failed to extract test archive: %v, output: %q" , err , output )
56
56
}
57
57
58
- glog .V (2 ).Infof ("Starting driver on %q" , i .name )
58
+ glog .V (4 ).Infof ("Starting driver on %q" , i .name )
59
59
// When the process is killed the driver should close the TCP endpoint, then we want to download the logs
60
- output , err := i .SSH (fmt . Sprintf ( "sh -c '/usr/bin/nohup %s/gce-pd-csi-driver --endpoint=%s --nodeid=%s > %s/prog.out 2> %s/prog.err < /dev/null &'" , workspace , endpoint , instanceName , workspace , workspace ) )
60
+ output , err := i .SSH (driverRunCmd )
61
61
62
62
if err != nil {
63
63
// Exit failure with the error
@@ -70,6 +70,6 @@ func (i *InstanceInfo) UploadAndRun(archivePath, archiveName, instanceName, port
70
70
return nil
71
71
}
72
72
73
- func newWorkspaceDir ( ) string {
73
+ func NewWorkspaceDir ( workspaceDirPrefix string ) string {
74
74
return filepath .Join ("/tmp" , workspaceDirPrefix + getTimestamp ())
75
75
}
0 commit comments