1
0
mirror of https://github.com/gluster/glusterd2.git synced 2026-02-05 21:45:43 +01:00

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 <jmulligan@redhat.com>
This commit is contained in:
John Mulligan
2018-04-23 15:21:10 -04:00
parent 93571c35e9
commit 9e9baeee5e
6 changed files with 34 additions and 12 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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