Merge pull request #4432 from gyuho/f0

functional-tester/etcd-agent: configurable log path
This commit is contained in:
Gyu-Ho Lee 2016-02-05 10:22:20 -08:00
commit c3fd2f95f0
3 changed files with 15 additions and 11 deletions

View File

@ -36,12 +36,14 @@ const (
type Agent struct { type Agent struct {
state string // the state of etcd process state string // the state of etcd process
cmd *exec.Cmd cmd *exec.Cmd
logfile *os.File logfile *os.File
l net.Listener etcdLogPath string
l net.Listener
} }
func newAgent(etcd string) (*Agent, error) { func newAgent(etcd, etcdLogPath string) (*Agent, error) {
// check if the file exists // check if the file exists
_, err := os.Stat(etcd) _, err := os.Stat(etcd)
if err != nil { if err != nil {
@ -50,12 +52,12 @@ func newAgent(etcd string) (*Agent, error) {
c := exec.Command(etcd) c := exec.Command(etcd)
f, err := os.Create("etcd.log") f, err := os.Create(etcdLogPath)
if err != nil { if err != nil {
return nil, err 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. // start starts a new etcd process with the given args.
@ -112,10 +114,10 @@ func (a *Agent) cleanup() error {
a.state = stateUninitialized a.state = stateUninitialized
a.logfile.Close() a.logfile.Close()
if err := archiveLogAndDataDir("etcd.log", a.dataDir()); err != nil { if err := archiveLogAndDataDir(a.etcdLogPath, a.dataDir()); err != nil {
return err return err
} }
f, err := os.Create("etcd.log") f, err := os.Create(a.etcdLogPath)
a.logfile = f a.logfile = f
return err return err
} }

View File

@ -17,10 +17,11 @@ package main
import ( import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath"
"testing" "testing"
) )
const etcdPath = "./etcd" const etcdPath = filepath.Join(os.Getenv("GOPATH"), "bin/etcd")
func TestAgentStart(t *testing.T) { func TestAgentStart(t *testing.T) {
defer os.Remove("etcd.log") 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. // newTestAgent creates a test agent and with a temp data directory.
func newTestAgent(t *testing.T) (*Agent, string) { func newTestAgent(t *testing.T) (*Agent, string) {
a, err := newAgent(etcdPath) a, err := newAgent(etcdPath, "etcd.log")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -23,10 +23,11 @@ import (
func main() { func main() {
etcdPath := flag.String("etcd-path", filepath.Join(os.Getenv("GOPATH"), "bin/etcd"), "the path to etcd binary") 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") port := flag.String("port", ":9027", "port to serve agent server")
flag.Parse() flag.Parse()
a, err := newAgent(*etcdPath) a, err := newAgent(*etcdPath, *etcdLogPath)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }