From e2b5b1cd1a67ade786ecfa1df36a2be4766dc673 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Fri, 5 Feb 2016 09:37:24 -0800 Subject: [PATCH] functional-tester/etcd-agent: configurable log path --- tools/functional-tester/etcd-agent/agent.go | 18 ++++++++++-------- .../functional-tester/etcd-agent/agent_test.go | 5 +++-- tools/functional-tester/etcd-agent/main.go | 3 ++- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/tools/functional-tester/etcd-agent/agent.go b/tools/functional-tester/etcd-agent/agent.go index b0969fa0c..778277c15 100644 --- a/tools/functional-tester/etcd-agent/agent.go +++ b/tools/functional-tester/etcd-agent/agent.go @@ -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 } diff --git a/tools/functional-tester/etcd-agent/agent_test.go b/tools/functional-tester/etcd-agent/agent_test.go index 4d8ea24f6..ffefd850c 100644 --- a/tools/functional-tester/etcd-agent/agent_test.go +++ b/tools/functional-tester/etcd-agent/agent_test.go @@ -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) } diff --git a/tools/functional-tester/etcd-agent/main.go b/tools/functional-tester/etcd-agent/main.go index 8da3d89d5..0c0d464ce 100644 --- a/tools/functional-tester/etcd-agent/main.go +++ b/tools/functional-tester/etcd-agent/main.go @@ -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) }