Skip to content

Commit 716b454

Browse files
authored
Merge pull request kubernetes#85749 from SataQiu/golint-e2e-20191129
Fix golint failures of test/e2e_node/remote
2 parents bea2ca7 + 69aae3a commit 716b454

File tree

6 files changed

+30
-28
lines changed

6 files changed

+30
-28
lines changed

hack/.golint_failures

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,5 @@ staging/src/k8s.io/sample-apiserver/pkg/registry/wardle/flunder
535535
test/e2e/common
536536
test/e2e/lifecycle/bootstrap
537537
test/e2e/storage/vsphere
538-
test/e2e_node/remote
539538
test/e2e_node/runner/remote
540539
test/utils

test/e2e_node/remote/node_conformance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
// ConformanceRemote contains the specific functions in the node conformance test suite.
3535
type ConformanceRemote struct{}
3636

37+
// InitConformanceRemote initializes the node conformance test suite.
3738
func InitConformanceRemote() TestSuite {
3839
return &ConformanceRemote{}
3940
}
@@ -68,9 +69,8 @@ var timestamp = getTimestamp()
6869
func getConformanceTestImageName(systemSpecName string) string {
6970
if systemSpecName == "" {
7071
return fmt.Sprintf("%s/node-test-%s:%s", conformanceRegistry, conformanceArch, timestamp)
71-
} else {
72-
return fmt.Sprintf("%s/node-test-%s-%s:%s", conformanceRegistry, systemSpecName, conformanceArch, timestamp)
7372
}
73+
return fmt.Sprintf("%s/node-test-%s-%s:%s", conformanceRegistry, systemSpecName, conformanceArch, timestamp)
7474
}
7575

7676
// buildConformanceTest builds node conformance test image tarball into binDir.

test/e2e_node/remote/node_e2e.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
// NodeE2ERemote contains the specific functions in the node e2e test suite.
3535
type NodeE2ERemote struct{}
3636

37+
// InitNodeE2ERemote initializes the node e2e test suite.
3738
func InitNodeE2ERemote() TestSuite {
3839
// TODO: Register flags.
3940
return &NodeE2ERemote{}

test/e2e_node/remote/remote.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@ import (
3131
"k8s.io/klog"
3232
)
3333

34-
var testTimeoutSeconds = flag.Duration("test-timeout", 45*time.Minute, "How long (in golang duration format) to wait for ginkgo tests to complete.")
34+
var testTimeout = flag.Duration("test-timeout", 45*time.Minute, "How long (in golang duration format) to wait for ginkgo tests to complete.")
3535
var resultsDir = flag.String("results-dir", "/tmp/", "Directory to scp test results to.")
3636

3737
const archiveName = "e2e_node_test.tar.gz"
3838

39+
// CreateTestArchive creates the archive package for the node e2e test.
3940
func CreateTestArchive(suite TestSuite, systemSpecName string) (string, error) {
4041
klog.V(2).Infof("Building archive...")
4142
tardir, err := ioutil.TempDir("", "node-e2e-archive")
4243
if err != nil {
43-
return "", fmt.Errorf("failed to create temporary directory %v.", err)
44+
return "", fmt.Errorf("failed to create temporary directory %v", err)
4445
}
4546
defer os.RemoveAll(tardir)
4647

@@ -58,12 +59,12 @@ func CreateTestArchive(suite TestSuite, systemSpecName string) (string, error) {
5859

5960
dir, err := os.Getwd()
6061
if err != nil {
61-
return "", fmt.Errorf("failed to get working directory %v.", err)
62+
return "", fmt.Errorf("failed to get working directory %v", err)
6263
}
6364
return filepath.Join(dir, archiveName), nil
6465
}
6566

66-
// Returns the command output, whether the exit was ok, and any errors
67+
// RunRemote returns the command output, whether the exit was ok, and any errors
6768
// TODO(random-liu): junitFilePrefix is not prefix actually, the file name is junit-junitFilePrefix.xml. Change the variable name.
6869
func RunRemote(suite TestSuite, archive string, host string, cleanup bool, imageDesc, junitFilePrefix string, testArgs string, ginkgoArgs string, systemSpecName string, extraEnvs string) (string, bool, error) {
6970
// Create the temp staging directory
@@ -84,7 +85,7 @@ func RunRemote(suite TestSuite, archive string, host string, cleanup bool, image
8485
}
8586

8687
// Copy the archive to the staging directory
87-
if output, err := runSSHCommand("scp", archive, fmt.Sprintf("%s:%s/", GetHostnameOrIp(host), workspace)); err != nil {
88+
if output, err := runSSHCommand("scp", archive, fmt.Sprintf("%s:%s/", GetHostnameOrIP(host), workspace)); err != nil {
8889
// Exit failure with the error
8990
return "", false, fmt.Errorf("failed to copy test archive: %v, output: %q", err, output)
9091
}
@@ -110,7 +111,7 @@ func RunRemote(suite TestSuite, archive string, host string, cleanup bool, image
110111
}
111112

112113
klog.V(2).Infof("Running test on %q", host)
113-
output, err := suite.RunTest(host, workspace, resultDir, imageDesc, junitFilePrefix, testArgs, ginkgoArgs, systemSpecName, extraEnvs, *testTimeoutSeconds)
114+
output, err := suite.RunTest(host, workspace, resultDir, imageDesc, junitFilePrefix, testArgs, ginkgoArgs, systemSpecName, extraEnvs, *testTimeout)
114115

115116
aggErrs := []error{}
116117
// Do not log the output here, let the caller deal with the test output.
@@ -143,7 +144,7 @@ func newWorkspaceDir() string {
143144
return filepath.Join("/tmp", workspaceDirPrefix+getTimestamp())
144145
}
145146

146-
// Parses the workspace directory name and gets the timestamp part of it.
147+
// GetTimestampFromWorkspaceDir parses the workspace directory name and gets the timestamp part of it.
147148
// This can later be used to name other artifacts (such as the
148149
// kubelet-${instance}.service systemd transient service used to launch
149150
// Kubelet) so that they can be matched to each other.
@@ -163,18 +164,18 @@ func getTestArtifacts(host, testDir string) error {
163164
return fmt.Errorf("failed to create log directory %q: %v", logPath, err)
164165
}
165166
// Copy logs to artifacts/hostname
166-
if _, err := runSSHCommand("scp", "-r", fmt.Sprintf("%s:%s/results/*.log", GetHostnameOrIp(host), testDir), logPath); err != nil {
167+
if _, err := runSSHCommand("scp", "-r", fmt.Sprintf("%s:%s/results/*.log", GetHostnameOrIP(host), testDir), logPath); err != nil {
167168
return err
168169
}
169170
// Copy json files (if any) to artifacts.
170171
if _, err := SSH(host, "ls", fmt.Sprintf("%s/results/*.json", testDir)); err == nil {
171-
if _, err = runSSHCommand("scp", "-r", fmt.Sprintf("%s:%s/results/*.json", GetHostnameOrIp(host), testDir), *resultsDir); err != nil {
172+
if _, err = runSSHCommand("scp", "-r", fmt.Sprintf("%s:%s/results/*.json", GetHostnameOrIP(host), testDir), *resultsDir); err != nil {
172173
return err
173174
}
174175
}
175176
if _, err := SSH(host, "ls", fmt.Sprintf("%s/results/junit*", testDir)); err == nil {
176177
// Copy junit (if any) to the top of artifacts
177-
if _, err = runSSHCommand("scp", fmt.Sprintf("%s:%s/results/junit*", GetHostnameOrIp(host), testDir), *resultsDir); err != nil {
178+
if _, err = runSSHCommand("scp", fmt.Sprintf("%s:%s/results/junit*", GetHostnameOrIP(host), testDir), *resultsDir); err != nil {
178179
return err
179180
}
180181
}
@@ -200,7 +201,7 @@ func collectSystemLog(host string) {
200201
// it could've be been removed if the node was rebooted.
201202
if output, err := SSH(host, "sh", "-c", fmt.Sprintf("'journalctl --system --all > %s'", logPath)); err == nil {
202203
klog.V(2).Infof("Got the system logs from journald; copying it back...")
203-
if output, err := runSSHCommand("scp", fmt.Sprintf("%s:%s", GetHostnameOrIp(host), logPath), destPath); err != nil {
204+
if output, err := runSSHCommand("scp", fmt.Sprintf("%s:%s", GetHostnameOrIP(host), logPath), destPath); err != nil {
204205
klog.V(2).Infof("Failed to copy the log: err: %v, output: %q", err, output)
205206
}
206207
} else {

test/e2e_node/remote/ssh.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,24 @@ func init() {
4848
}
4949
}
5050

51-
var hostnameIpOverrides = struct {
51+
var hostnameIPOverrides = struct {
5252
sync.RWMutex
5353
m map[string]string
5454
}{m: make(map[string]string)}
5555

56-
func AddHostnameIp(hostname, ip string) {
57-
hostnameIpOverrides.Lock()
58-
defer hostnameIpOverrides.Unlock()
59-
hostnameIpOverrides.m[hostname] = ip
56+
// AddHostnameIP adds <hostname,ip> pair into hostnameIPOverrides map.
57+
func AddHostnameIP(hostname, ip string) {
58+
hostnameIPOverrides.Lock()
59+
defer hostnameIPOverrides.Unlock()
60+
hostnameIPOverrides.m[hostname] = ip
6061
}
6162

62-
// GetHostnameOrIp converts hostname into ip and apply user if necessary.
63-
func GetHostnameOrIp(hostname string) string {
64-
hostnameIpOverrides.RLock()
65-
defer hostnameIpOverrides.RUnlock()
63+
// GetHostnameOrIP converts hostname into ip and apply user if necessary.
64+
func GetHostnameOrIP(hostname string) string {
65+
hostnameIPOverrides.RLock()
66+
defer hostnameIPOverrides.RUnlock()
6667
host := hostname
67-
if ip, found := hostnameIpOverrides.m[hostname]; found {
68+
if ip, found := hostnameIPOverrides.m[hostname]; found {
6869
host = ip
6970
}
7071
if *sshUser != "" {
@@ -81,13 +82,13 @@ func getSSHCommand(sep string, args ...string) string {
8182
// SSH executes ssh command with runSSHCommand as root. The `sudo` makes sure that all commands
8283
// are executed by root, so that there won't be permission mismatch between different commands.
8384
func SSH(host string, cmd ...string) (string, error) {
84-
return runSSHCommand("ssh", append([]string{GetHostnameOrIp(host), "--", "sudo"}, cmd...)...)
85+
return runSSHCommand("ssh", append([]string{GetHostnameOrIP(host), "--", "sudo"}, cmd...)...)
8586
}
8687

8788
// SSHNoSudo executes ssh command with runSSHCommand as normal user. Sometimes we need this,
8889
// for example creating a directory that we'll copy files there with scp.
8990
func SSHNoSudo(host string, cmd ...string) (string, error) {
90-
return runSSHCommand("ssh", append([]string{GetHostnameOrIp(host), "--"}, cmd...)...)
91+
return runSSHCommand("ssh", append([]string{GetHostnameOrIP(host), "--"}, cmd...)...)
9192
}
9293

9394
// runSSHCommand executes the ssh or scp command, adding the flag provided --ssh-options

test/e2e_node/runner/remote/run_remote.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ func testHost(host string, deleteFiles bool, imageDesc, junitFilePrefix, ginkgoF
437437
}
438438
externalIp := getExternalIp(instance)
439439
if len(externalIp) > 0 {
440-
remote.AddHostnameIp(host, externalIp)
440+
remote.AddHostnameIP(host, externalIp)
441441
}
442442

443443
path, err := arc.getArchive()
@@ -648,7 +648,7 @@ func createInstance(imageConfig *internalGCEImage) (string, error) {
648648
}
649649
externalIp := getExternalIp(instance)
650650
if len(externalIp) > 0 {
651-
remote.AddHostnameIp(name, externalIp)
651+
remote.AddHostnameIP(name, externalIp)
652652
}
653653
// TODO(random-liu): Remove the docker version check. Use some other command to check
654654
// instance readiness.

0 commit comments

Comments
 (0)