mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
functional-tester/etcd-agent: configurable log path
This commit is contained in:
parent
2cd1cc4111
commit
e2b5b1cd1a
@ -36,12 +36,14 @@ const (
|
||||
type Agent struct {
|
||||
state string // the state of etcd process
|
||||
|
||||
cmd *exec.Cmd
|
||||
logfile *os.File
|
||||
l net.Listener
|
||||
cmd *exec.Cmd
|
||||
logfile *os.File
|
||||
etcdLogPath string
|
||||
|
||||
l net.Listener
|
||||
}
|
||||
|
||||
func newAgent(etcd string) (*Agent, error) {
|
||||
func newAgent(etcd, etcdLogPath string) (*Agent, error) {
|
||||
// check if the file exists
|
||||
_, err := os.Stat(etcd)
|
||||
if err != nil {
|
||||
@ -50,12 +52,12 @@ func newAgent(etcd string) (*Agent, error) {
|
||||
|
||||
c := exec.Command(etcd)
|
||||
|
||||
f, err := os.Create("etcd.log")
|
||||
f, err := os.Create(etcdLogPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Agent{state: stateUninitialized, cmd: c, logfile: f}, nil
|
||||
return &Agent{state: stateUninitialized, cmd: c, logfile: f, etcdLogPath: etcdLogPath}, nil
|
||||
}
|
||||
|
||||
// start starts a new etcd process with the given args.
|
||||
@ -112,10 +114,10 @@ func (a *Agent) cleanup() error {
|
||||
a.state = stateUninitialized
|
||||
|
||||
a.logfile.Close()
|
||||
if err := archiveLogAndDataDir("etcd.log", a.dataDir()); err != nil {
|
||||
if err := archiveLogAndDataDir(a.etcdLogPath, a.dataDir()); err != nil {
|
||||
return err
|
||||
}
|
||||
f, err := os.Create("etcd.log")
|
||||
f, err := os.Create(a.etcdLogPath)
|
||||
a.logfile = f
|
||||
return err
|
||||
}
|
||||
|
@ -17,10 +17,11 @@ package main
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const etcdPath = "./etcd"
|
||||
const etcdPath = filepath.Join(os.Getenv("GOPATH"), "bin/etcd")
|
||||
|
||||
func TestAgentStart(t *testing.T) {
|
||||
defer os.Remove("etcd.log")
|
||||
@ -77,7 +78,7 @@ func TestAgentTerminate(t *testing.T) {
|
||||
|
||||
// newTestAgent creates a test agent and with a temp data directory.
|
||||
func newTestAgent(t *testing.T) (*Agent, string) {
|
||||
a, err := newAgent(etcdPath)
|
||||
a, err := newAgent(etcdPath, "etcd.log")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -23,10 +23,11 @@ import (
|
||||
|
||||
func main() {
|
||||
etcdPath := flag.String("etcd-path", filepath.Join(os.Getenv("GOPATH"), "bin/etcd"), "the path to etcd binary")
|
||||
etcdLogPath := flag.String("etcd-log-path", "etcd.log", "the path to etcd log")
|
||||
port := flag.String("port", ":9027", "port to serve agent server")
|
||||
flag.Parse()
|
||||
|
||||
a, err := newAgent(*etcdPath)
|
||||
a, err := newAgent(*etcdPath, *etcdLogPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user