From 13c8381dc418a6b103283f9cdd44c47b9d05e28a Mon Sep 17 00:00:00 2001 From: Random-Liu Date: Wed, 3 Aug 2016 18:14:53 -0700 Subject: [PATCH] Move the node name initialization to first function of SynchronizedBeforeEach, so that we can pass right node name when starting e2e services. --- test/e2e_node/e2e_node_suite_test.go | 17 ++++++++++------- test/e2e_node/util.go | 1 + 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/test/e2e_node/e2e_node_suite_test.go b/test/e2e_node/e2e_node_suite_test.go index 2a93ab938bb..90b63dc5988 100644 --- a/test/e2e_node/e2e_node_suite_test.go +++ b/test/e2e_node/e2e_node_suite_test.go @@ -102,6 +102,13 @@ var _ = SynchronizedBeforeSuite(func() []byte { if *buildServices { buildGo() } + if framework.TestContext.NodeName == "" { + hostname, err := os.Hostname() + if err != nil { + glog.Fatalf("Could not get node name: %v", err) + } + framework.TestContext.NodeName = hostname + } // Pre-pull the images tests depend on so we can fail immediately if there is an image pull issue // This helps with debugging test flakes since it is hard to tell when a test failure is due to image pulling. @@ -133,6 +140,8 @@ var _ = SynchronizedBeforeSuite(func() []byte { // Reference common test to make the import valid. commontest.CurrentSuite = commontest.NodeE2E + // Share the node name with the other test nodes. + shared.NodeName = framework.TestContext.NodeName data, err := json.Marshal(shared) Expect(err).NotTo(HaveOccurred()) @@ -143,13 +152,7 @@ var _ = SynchronizedBeforeSuite(func() []byte { Expect(json.Unmarshal(data, shared)).To(Succeed()) context = *shared - if framework.TestContext.NodeName == "" { - hostname, err := os.Hostname() - if err != nil { - glog.Fatalf("Could not get node name: %v", err) - } - framework.TestContext.NodeName = hostname - } + framework.TestContext.NodeName = shared.NodeName }) // Tear down the kubelet on the node diff --git a/test/e2e_node/util.go b/test/e2e_node/util.go index 21d2c321cb4..b7bf55c83ed 100644 --- a/test/e2e_node/util.go +++ b/test/e2e_node/util.go @@ -28,5 +28,6 @@ var startServices = flag.Bool("start-services", true, "If true, start local node var stopServices = flag.Bool("stop-services", true, "If true, stop local node services after running tests") type SharedContext struct { + NodeName string PodConfigPath string }