diff --git a/hack/.golint_failures b/hack/.golint_failures index 9038c00c361..d6c40f9e3dc 100644 --- a/hack/.golint_failures +++ b/hack/.golint_failures @@ -534,6 +534,5 @@ staging/src/k8s.io/sample-apiserver/pkg/registry/wardle/flunder test/e2e/common test/e2e/lifecycle/bootstrap test/e2e/storage/vsphere -test/e2e_node/remote test/e2e_node/runner/remote test/utils diff --git a/test/e2e_node/remote/node_conformance.go b/test/e2e_node/remote/node_conformance.go index d8ecc2c46fb..6174bfbb77e 100644 --- a/test/e2e_node/remote/node_conformance.go +++ b/test/e2e_node/remote/node_conformance.go @@ -34,6 +34,7 @@ import ( // ConformanceRemote contains the specific functions in the node conformance test suite. type ConformanceRemote struct{} +// InitConformanceRemote initializes the node conformance test suite. func InitConformanceRemote() TestSuite { return &ConformanceRemote{} } @@ -68,9 +69,8 @@ var timestamp = getTimestamp() func getConformanceTestImageName(systemSpecName string) string { if systemSpecName == "" { return fmt.Sprintf("%s/node-test-%s:%s", conformanceRegistry, conformanceArch, timestamp) - } else { - return fmt.Sprintf("%s/node-test-%s-%s:%s", conformanceRegistry, systemSpecName, conformanceArch, timestamp) } + return fmt.Sprintf("%s/node-test-%s-%s:%s", conformanceRegistry, systemSpecName, conformanceArch, timestamp) } // buildConformanceTest builds node conformance test image tarball into binDir. diff --git a/test/e2e_node/remote/node_e2e.go b/test/e2e_node/remote/node_e2e.go index 2e5751b168f..0987fa6f30a 100644 --- a/test/e2e_node/remote/node_e2e.go +++ b/test/e2e_node/remote/node_e2e.go @@ -34,6 +34,7 @@ import ( // NodeE2ERemote contains the specific functions in the node e2e test suite. type NodeE2ERemote struct{} +// InitNodeE2ERemote initializes the node e2e test suite. func InitNodeE2ERemote() TestSuite { // TODO: Register flags. return &NodeE2ERemote{} diff --git a/test/e2e_node/remote/remote.go b/test/e2e_node/remote/remote.go index 0037d773021..c891ae07808 100644 --- a/test/e2e_node/remote/remote.go +++ b/test/e2e_node/remote/remote.go @@ -31,16 +31,17 @@ import ( "k8s.io/klog" ) -var testTimeoutSeconds = flag.Duration("test-timeout", 45*time.Minute, "How long (in golang duration format) to wait for ginkgo tests to complete.") +var testTimeout = flag.Duration("test-timeout", 45*time.Minute, "How long (in golang duration format) to wait for ginkgo tests to complete.") var resultsDir = flag.String("results-dir", "/tmp/", "Directory to scp test results to.") const archiveName = "e2e_node_test.tar.gz" +// CreateTestArchive creates the archive package for the node e2e test. func CreateTestArchive(suite TestSuite, systemSpecName string) (string, error) { klog.V(2).Infof("Building archive...") tardir, err := ioutil.TempDir("", "node-e2e-archive") if err != nil { - return "", fmt.Errorf("failed to create temporary directory %v.", err) + return "", fmt.Errorf("failed to create temporary directory %v", err) } defer os.RemoveAll(tardir) @@ -58,12 +59,12 @@ func CreateTestArchive(suite TestSuite, systemSpecName string) (string, error) { dir, err := os.Getwd() if err != nil { - return "", fmt.Errorf("failed to get working directory %v.", err) + return "", fmt.Errorf("failed to get working directory %v", err) } return filepath.Join(dir, archiveName), nil } -// Returns the command output, whether the exit was ok, and any errors +// RunRemote returns the command output, whether the exit was ok, and any errors // TODO(random-liu): junitFilePrefix is not prefix actually, the file name is junit-junitFilePrefix.xml. Change the variable name. func RunRemote(suite TestSuite, archive string, host string, cleanup bool, imageDesc, junitFilePrefix string, testArgs string, ginkgoArgs string, systemSpecName string, extraEnvs string) (string, bool, error) { // Create the temp staging directory @@ -84,7 +85,7 @@ func RunRemote(suite TestSuite, archive string, host string, cleanup bool, image } // Copy the archive to the staging directory - if output, err := runSSHCommand("scp", archive, fmt.Sprintf("%s:%s/", GetHostnameOrIp(host), workspace)); err != nil { + if output, err := runSSHCommand("scp", archive, fmt.Sprintf("%s:%s/", GetHostnameOrIP(host), workspace)); err != nil { // Exit failure with the error return "", false, fmt.Errorf("failed to copy test archive: %v, output: %q", err, output) } @@ -110,7 +111,7 @@ func RunRemote(suite TestSuite, archive string, host string, cleanup bool, image } klog.V(2).Infof("Running test on %q", host) - output, err := suite.RunTest(host, workspace, resultDir, imageDesc, junitFilePrefix, testArgs, ginkgoArgs, systemSpecName, extraEnvs, *testTimeoutSeconds) + output, err := suite.RunTest(host, workspace, resultDir, imageDesc, junitFilePrefix, testArgs, ginkgoArgs, systemSpecName, extraEnvs, *testTimeout) aggErrs := []error{} // Do not log the output here, let the caller deal with the test output. @@ -143,7 +144,7 @@ func newWorkspaceDir() string { return filepath.Join("/tmp", workspaceDirPrefix+getTimestamp()) } -// Parses the workspace directory name and gets the timestamp part of it. +// GetTimestampFromWorkspaceDir parses the workspace directory name and gets the timestamp part of it. // This can later be used to name other artifacts (such as the // kubelet-${instance}.service systemd transient service used to launch // Kubelet) so that they can be matched to each other. @@ -163,18 +164,18 @@ func getTestArtifacts(host, testDir string) error { return fmt.Errorf("failed to create log directory %q: %v", logPath, err) } // Copy logs to artifacts/hostname - if _, err := runSSHCommand("scp", "-r", fmt.Sprintf("%s:%s/results/*.log", GetHostnameOrIp(host), testDir), logPath); err != nil { + if _, err := runSSHCommand("scp", "-r", fmt.Sprintf("%s:%s/results/*.log", GetHostnameOrIP(host), testDir), logPath); err != nil { return err } // Copy json files (if any) to artifacts. if _, err := SSH(host, "ls", fmt.Sprintf("%s/results/*.json", testDir)); err == nil { - if _, err = runSSHCommand("scp", "-r", fmt.Sprintf("%s:%s/results/*.json", GetHostnameOrIp(host), testDir), *resultsDir); err != nil { + if _, err = runSSHCommand("scp", "-r", fmt.Sprintf("%s:%s/results/*.json", GetHostnameOrIP(host), testDir), *resultsDir); err != nil { return err } } if _, err := SSH(host, "ls", fmt.Sprintf("%s/results/junit*", testDir)); err == nil { // Copy junit (if any) to the top of artifacts - if _, err = runSSHCommand("scp", fmt.Sprintf("%s:%s/results/junit*", GetHostnameOrIp(host), testDir), *resultsDir); err != nil { + if _, err = runSSHCommand("scp", fmt.Sprintf("%s:%s/results/junit*", GetHostnameOrIP(host), testDir), *resultsDir); err != nil { return err } } @@ -200,7 +201,7 @@ func collectSystemLog(host string) { // it could've be been removed if the node was rebooted. if output, err := SSH(host, "sh", "-c", fmt.Sprintf("'journalctl --system --all > %s'", logPath)); err == nil { klog.V(2).Infof("Got the system logs from journald; copying it back...") - if output, err := runSSHCommand("scp", fmt.Sprintf("%s:%s", GetHostnameOrIp(host), logPath), destPath); err != nil { + if output, err := runSSHCommand("scp", fmt.Sprintf("%s:%s", GetHostnameOrIP(host), logPath), destPath); err != nil { klog.V(2).Infof("Failed to copy the log: err: %v, output: %q", err, output) } } else { diff --git a/test/e2e_node/remote/ssh.go b/test/e2e_node/remote/ssh.go index 4a4f0d82bd0..233f63be695 100644 --- a/test/e2e_node/remote/ssh.go +++ b/test/e2e_node/remote/ssh.go @@ -48,23 +48,24 @@ func init() { } } -var hostnameIpOverrides = struct { +var hostnameIPOverrides = struct { sync.RWMutex m map[string]string }{m: make(map[string]string)} -func AddHostnameIp(hostname, ip string) { - hostnameIpOverrides.Lock() - defer hostnameIpOverrides.Unlock() - hostnameIpOverrides.m[hostname] = ip +// AddHostnameIP adds pair into hostnameIPOverrides map. +func AddHostnameIP(hostname, ip string) { + hostnameIPOverrides.Lock() + defer hostnameIPOverrides.Unlock() + hostnameIPOverrides.m[hostname] = ip } -// GetHostnameOrIp converts hostname into ip and apply user if necessary. -func GetHostnameOrIp(hostname string) string { - hostnameIpOverrides.RLock() - defer hostnameIpOverrides.RUnlock() +// GetHostnameOrIP converts hostname into ip and apply user if necessary. +func GetHostnameOrIP(hostname string) string { + hostnameIPOverrides.RLock() + defer hostnameIPOverrides.RUnlock() host := hostname - if ip, found := hostnameIpOverrides.m[hostname]; found { + if ip, found := hostnameIPOverrides.m[hostname]; found { host = ip } if *sshUser != "" { @@ -81,13 +82,13 @@ func getSSHCommand(sep string, args ...string) string { // SSH executes ssh command with runSSHCommand as root. The `sudo` makes sure that all commands // are executed by root, so that there won't be permission mismatch between different commands. func SSH(host string, cmd ...string) (string, error) { - return runSSHCommand("ssh", append([]string{GetHostnameOrIp(host), "--", "sudo"}, cmd...)...) + return runSSHCommand("ssh", append([]string{GetHostnameOrIP(host), "--", "sudo"}, cmd...)...) } // SSHNoSudo executes ssh command with runSSHCommand as normal user. Sometimes we need this, // for example creating a directory that we'll copy files there with scp. func SSHNoSudo(host string, cmd ...string) (string, error) { - return runSSHCommand("ssh", append([]string{GetHostnameOrIp(host), "--"}, cmd...)...) + return runSSHCommand("ssh", append([]string{GetHostnameOrIP(host), "--"}, cmd...)...) } // runSSHCommand executes the ssh or scp command, adding the flag provided --ssh-options diff --git a/test/e2e_node/runner/remote/run_remote.go b/test/e2e_node/runner/remote/run_remote.go index 8459f045e1f..94e0cf553e8 100644 --- a/test/e2e_node/runner/remote/run_remote.go +++ b/test/e2e_node/runner/remote/run_remote.go @@ -437,7 +437,7 @@ func testHost(host string, deleteFiles bool, imageDesc, junitFilePrefix, ginkgoF } externalIp := getExternalIp(instance) if len(externalIp) > 0 { - remote.AddHostnameIp(host, externalIp) + remote.AddHostnameIP(host, externalIp) } path, err := arc.getArchive() @@ -648,7 +648,7 @@ func createInstance(imageConfig *internalGCEImage) (string, error) { } externalIp := getExternalIp(instance) if len(externalIp) > 0 { - remote.AddHostnameIp(name, externalIp) + remote.AddHostnameIP(name, externalIp) } // TODO(random-liu): Remove the docker version check. Use some other command to check // instance readiness.