Add the monitorParent option when starting services, and set

monitorParent to false when stop-services=false.
This commit is contained in:
Random-Liu 2016-09-13 16:47:45 -07:00
parent 0d3befd7ea
commit f501acebab
3 changed files with 31 additions and 18 deletions

View File

@ -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 {

View File

@ -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()

View File

@ -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()
}