From f501acebab747f3951341f5a8071a3c7899a01fe Mon Sep 17 00:00:00 2001 From: Random-Liu Date: Tue, 13 Sep 2016 16:47:45 -0700 Subject: [PATCH] Add the monitorParent option when starting services, and set monitorParent to false when stop-services=false. --- test/e2e_node/e2e_node_suite_test.go | 4 +++- test/e2e_node/services/server.go | 29 +++++++++++++++++----------- test/e2e_node/services/services.go | 16 +++++++++------ 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/test/e2e_node/e2e_node_suite_test.go b/test/e2e_node/e2e_node_suite_test.go index 172d806f7d3..73a539893a9 100644 --- a/test/e2e_node/e2e_node_suite_test.go +++ b/test/e2e_node/e2e_node_suite_test.go @@ -114,7 +114,9 @@ var _ = SynchronizedBeforeSuite(func() []byte { maskLocksmithdOnCoreos() if *startServices { - e2es = services.NewE2EServices() + // If the services are expected to stop after test, they should monitor the test process. + // If the services are expected to keep running after test, they should not monitor the test process. + e2es = services.NewE2EServices(*stopServices) Expect(e2es.Start()).To(Succeed(), "should be able to start node services.") glog.Infof("Node services started. Running tests...") } else { diff --git a/test/e2e_node/services/server.go b/test/e2e_node/services/server.go index 1ed3ddb9ea2..18a9d0a31eb 100644 --- a/test/e2e_node/services/server.go +++ b/test/e2e_node/services/server.go @@ -54,6 +54,9 @@ type server struct { // outFilename is the name of the log file. The stdout and stderr of the server // will be redirected to this file. outFilename string + // monitorParent determines whether the server should watch its parent process and exit + // if its parent is gone. + monitorParent bool // restartOnExit determines whether a restart loop is launched with the server restartOnExit bool // Writing to this channel, if it is not nil, stops the restart loop. @@ -65,7 +68,7 @@ type server struct { // newServer returns a new server with the given name, commands, health check // URLs, etc. -func newServer(name string, start, kill, restart *exec.Cmd, urls []string, outputFileName string, restartOnExit bool) *server { +func newServer(name string, start, kill, restart *exec.Cmd, urls []string, outputFileName string, monitorParent, restartOnExit bool) *server { return &server{ name: name, startCommand: start, @@ -73,6 +76,7 @@ func newServer(name string, start, kill, restart *exec.Cmd, urls []string, outpu restartCommand: restart, healthCheckUrls: urls, outFilename: outputFileName, + monitorParent: monitorParent, restartOnExit: restartOnExit, } } @@ -177,17 +181,20 @@ func (s *server) start() error { s.startCommand.Stdout = outfile s.startCommand.Stderr = outfile - // Death of this test process should kill the server as well. - attrs := &syscall.SysProcAttr{} - // Hack to set linux-only field without build tags. - deathSigField := reflect.ValueOf(attrs).Elem().FieldByName("Pdeathsig") - if deathSigField.IsValid() { - deathSigField.Set(reflect.ValueOf(syscall.SIGTERM)) - } else { - errCh <- fmt.Errorf("failed to set Pdeathsig field (non-linux build)") - return + // If monitorParent is set, set Pdeathsig when starting the server. + if s.monitorParent { + // Death of this test process should kill the server as well. + attrs := &syscall.SysProcAttr{} + // Hack to set linux-only field without build tags. + deathSigField := reflect.ValueOf(attrs).Elem().FieldByName("Pdeathsig") + if deathSigField.IsValid() { + deathSigField.Set(reflect.ValueOf(syscall.SIGTERM)) + } else { + errCh <- fmt.Errorf("failed to set Pdeathsig field (non-linux build)") + return + } + s.startCommand.SysProcAttr = attrs } - s.startCommand.SysProcAttr = attrs // Start the command err = s.startCommand.Start() diff --git a/test/e2e_node/services/services.go b/test/e2e_node/services/services.go index 80f97f1f3bd..7fa3aa85e6e 100644 --- a/test/e2e_node/services/services.go +++ b/test/e2e_node/services/services.go @@ -37,9 +37,12 @@ import ( // E2EServices starts and stops e2e services in a separate process. The test // uses it to start and stop all e2e services. type E2EServices struct { - services *server - kubelet *server - logFiles map[string]logFileData + // monitorParent determines whether the sub-processes should watch and die with the current + // process. + monitorParent bool + services *server + kubelet *server + logFiles map[string]logFileData } // logFileData holds data about logfiles to fetch with a journalctl command or @@ -50,8 +53,9 @@ type logFileData struct { } // NewE2EServices returns a new E2EServices instance. -func NewE2EServices() *E2EServices { +func NewE2EServices(monitorParent bool) *E2EServices { return &E2EServices{ + monitorParent: monitorParent, // Special log files that need to be collected for additional debugging. logFiles: map[string]logFileData{ "kern.log": {[]string{"/var/log/kern.log"}, []string{"-k"}}, @@ -151,7 +155,7 @@ func (e *E2EServices) startInternalServices() (*server, error) { "--logtostderr", "--vmodule=*="+LOG_VERBOSITY_LEVEL, ) - server := newServer("services", startCmd, nil, nil, getServicesHealthCheckURLs(), servicesLogFile, false) + server := newServer("services", startCmd, nil, nil, getServicesHealthCheckURLs(), servicesLogFile, e.monitorParent, false) return server, server.start() } @@ -206,7 +210,6 @@ func (e *E2EServices) startKubelet() (*server, error) { "--eviction-hard", framework.TestContext.EvictionHard, "--eviction-pressure-transition-period", "30s", "--feature-gates", framework.TestContext.FeatureGates, - "--runtime-integration-type", framework.TestContext.RuntimeIntegrationType, "--v", LOG_VERBOSITY_LEVEL, "--logtostderr", ) if framework.TestContext.RuntimeIntegrationType != "" { @@ -238,6 +241,7 @@ func (e *E2EServices) startKubelet() (*server, error) { restartCommand, []string{kubeletHealthCheckURL}, "kubelet.log", + e.monitorParent, true /* restartOnExit */) return server, server.start() }