From 9e9baeee5ec095d08bb4ad5d40abbd61baa7e4b3 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Mon, 23 Apr 2018 15:21:10 -0400 Subject: [PATCH] e2e: make a central, configurable, base workdir Previously, e2e tests were hard-coding the base workdir in the main_test.go file and in the config toml files. This change centralizes the base path in a top-level variable and makes it possible to specify custom values for the workdir. This can be useful if /tmp is inappropriate for this task on a particular system or if multiple e2e tests are to be run in parallel so that the caller may specify unique paths for each test. The toml files are adjusted to contain relative paths. Signed-off-by: John Mulligan --- e2e/config/1.toml | 4 ++-- e2e/config/2.toml | 4 ++-- e2e/config/3.toml | 4 ++-- e2e/config/4.toml | 4 ++-- e2e/main_test.go | 8 +++++--- e2e/utils_test.go | 22 +++++++++++++++++++++- 6 files changed, 34 insertions(+), 12 deletions(-) diff --git a/e2e/config/1.toml b/e2e/config/1.toml index fb8ec625..f3111499 100644 --- a/e2e/config/1.toml +++ b/e2e/config/1.toml @@ -1,5 +1,5 @@ -workdir = "/tmp/gd2_func_test/w1" -rundir = "/tmp/gd2_func_test/w1/run/gluster" +workdir = "w1" +rundir = "w1/run/gluster" logfile = "w1.log" peeraddress = "127.0.0.1:24008" clientaddress = "127.0.0.1:24007" diff --git a/e2e/config/2.toml b/e2e/config/2.toml index 4ccf9d2f..0844066d 100644 --- a/e2e/config/2.toml +++ b/e2e/config/2.toml @@ -1,5 +1,5 @@ -workdir = "/tmp/gd2_func_test/w2" -rundir = "/tmp/gd2_func_test/w2/run/gluster" +workdir = "w2" +rundir = "w2/run/gluster" logfile = "w2.log" peeraddress = "127.0.0.1:23008" clientaddress = "127.0.0.1:23007" diff --git a/e2e/config/3.toml b/e2e/config/3.toml index 4d91c793..29947531 100644 --- a/e2e/config/3.toml +++ b/e2e/config/3.toml @@ -1,5 +1,5 @@ -workdir = "/tmp/gd2_func_test/w3" -rundir = "/tmp/gd2_func_test/w3/run/gluster" +workdir = "w3" +rundir = "w3/run/gluster" logfile = "w3.log" peeraddress = "127.0.0.1:22008" clientaddress = "127.0.0.1:22007" diff --git a/e2e/config/4.toml b/e2e/config/4.toml index 8632a437..3b9cf581 100644 --- a/e2e/config/4.toml +++ b/e2e/config/4.toml @@ -1,5 +1,5 @@ -workdir = "/tmp/gd2_func_test/w4" -rundir = "/tmp/gd2_func_test/w4/run/gluster" +workdir = "w4" +rundir = "w4/run/gluster" logfile = "w4.log" peeraddress = "127.0.0.1:21008" clientaddress = "127.0.0.1:21007" diff --git a/e2e/main_test.go b/e2e/main_test.go index ffa27a86..eae44701 100644 --- a/e2e/main_test.go +++ b/e2e/main_test.go @@ -9,8 +9,9 @@ import ( ) var ( - binDir string - functest bool + binDir string + baseWorkdir = "/tmp/gd2_func_test" + functest bool ) func TestMain(m *testing.M) { @@ -18,6 +19,7 @@ func TestMain(m *testing.M) { flag.BoolVar(&functest, "functest", false, "Run or skip functional test") flag.StringVar(&binDir, "bindir", defBinDir, "The directory containing glusterd2 binary") + flag.StringVar(&baseWorkdir, "workdir", baseWorkdir, "The base directory for test working directories") flag.Parse() if !functest { @@ -32,7 +34,7 @@ func TestMain(m *testing.M) { } // Cleanup leftovers from previous test runs. But don't cleanup after. - os.RemoveAll("/tmp/gd2_func_test") + os.RemoveAll(baseWorkdir) v := m.Run() os.Exit(v) diff --git a/e2e/utils_test.go b/e2e/utils_test.go index 457ce730..895b7619 100644 --- a/e2e/utils_test.go +++ b/e2e/utils_test.go @@ -9,6 +9,7 @@ import ( "os" "os/exec" "path" + "path/filepath" "strings" "syscall" "time" @@ -24,6 +25,7 @@ type gdProcess struct { ClientAddress string `toml:"clientaddress"` PeerAddress string `toml:"peeraddress"` Workdir string `toml:"workdir"` + Rundir string `toml:"rundir"` uuid string } @@ -38,6 +40,17 @@ func (g *gdProcess) Stop() error { return g.Cmd.Process.Kill() } +func (g *gdProcess) UpdateDirs() { + g.Workdir = path.Clean(g.Workdir) + if !path.IsAbs(g.Workdir) { + g.Workdir = path.Join(baseWorkdir, g.Workdir) + } + g.Rundir = path.Clean(g.Rundir) + if !path.IsAbs(g.Rundir) { + g.Rundir = path.Join(baseWorkdir, g.Rundir) + } +} + func (g *gdProcess) EraseWorkdir() error { return os.RemoveAll(g.Workdir) } @@ -103,6 +116,7 @@ func spawnGlusterd(configFilePath string, cleanStart bool) (*gdProcess, error) { return nil, err } + g.UpdateDirs() if cleanStart { g.EraseWorkdir() // cleanup leftovers from previous test } @@ -111,8 +125,14 @@ func spawnGlusterd(configFilePath string, cleanStart bool) (*gdProcess, error) { return nil, err } + absConfigFilePath, err := filepath.Abs(configFilePath) + if err != nil { + return nil, err + } g.Cmd = exec.Command(path.Join(binDir, "glusterd2"), - "--config", configFilePath, + "--config", absConfigFilePath, + "--workdir", g.Workdir, + "--rundir", g.Rundir, "--logdir", path.Join(g.Workdir, "log"), "--logfile", "glusterd2.log")