From 6024056834f7926e28b89fae0bc79d0059f58df2 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 24 Apr 2018 03:19:03 -0400 Subject: [PATCH 1/4] Distinguish key not found vs error accessing store Handle key not found and error accessing store and return 404 or 503 respectively in all user facing utility functions. Signed-off-by: Vishal Pandey --- glusterd2/commands/volumes/bricks-status.go | 6 ++- glusterd2/commands/volumes/volume-delete.go | 8 ++-- glusterd2/commands/volumes/volume-info.go | 6 ++- glusterd2/commands/volumes/volume-option.go | 6 ++- glusterd2/commands/volumes/volume-start.go | 8 ++-- .../commands/volumes/volume-statedump.go | 8 ++-- glusterd2/commands/volumes/volume-status.go | 8 ++-- glusterd2/commands/volumes/volume-stop.go | 8 ++-- glusterd2/volume/store-utils.go | 4 +- plugins/bitrot/rest.go | 25 ++++++++-- plugins/device/rest.go | 13 +++-- plugins/georeplication/rest.go | 48 +++++++++++++++---- plugins/glustershd/rest.go | 12 ++++- plugins/quota/rest.go | 6 ++- 14 files changed, 127 insertions(+), 39 deletions(-) diff --git a/glusterd2/commands/volumes/bricks-status.go b/glusterd2/commands/volumes/bricks-status.go index c9aea94fa..62294670f 100644 --- a/glusterd2/commands/volumes/bricks-status.go +++ b/glusterd2/commands/volumes/bricks-status.go @@ -71,7 +71,11 @@ func volumeBricksStatusHandler(w http.ResponseWriter, r *http.Request) { volname := mux.Vars(r)["volname"] vol, err := volume.GetVolume(volname) if err != nil { - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } diff --git a/glusterd2/commands/volumes/volume-delete.go b/glusterd2/commands/volumes/volume-delete.go index 8ed046d4a..06295acf5 100644 --- a/glusterd2/commands/volumes/volume-delete.go +++ b/glusterd2/commands/volumes/volume-delete.go @@ -81,9 +81,11 @@ func volumeDeleteHandler(w http.ResponseWriter, r *http.Request) { volinfo, err := volume.GetVolume(volname) if err != nil { - // TODO: Distinguish between volume not present (404) and - // store access failure (503) - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } diff --git a/glusterd2/commands/volumes/volume-info.go b/glusterd2/commands/volumes/volume-info.go index f58205d63..cd56fa07d 100644 --- a/glusterd2/commands/volumes/volume-info.go +++ b/glusterd2/commands/volumes/volume-info.go @@ -18,7 +18,11 @@ func volumeInfoHandler(w http.ResponseWriter, r *http.Request) { volname := mux.Vars(r)["volname"] v, err := volume.GetVolume(volname) if err != nil { - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } diff --git a/glusterd2/commands/volumes/volume-option.go b/glusterd2/commands/volumes/volume-option.go index 8b2a439a2..b33b84b3b 100644 --- a/glusterd2/commands/volumes/volume-option.go +++ b/glusterd2/commands/volumes/volume-option.go @@ -145,7 +145,11 @@ func volumeOptionsHandler(w http.ResponseWriter, r *http.Request) { volinfo, err := volume.GetVolume(volname) if err != nil { - restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } diff --git a/glusterd2/commands/volumes/volume-start.go b/glusterd2/commands/volumes/volume-start.go index 31843f5d3..077948b77 100644 --- a/glusterd2/commands/volumes/volume-start.go +++ b/glusterd2/commands/volumes/volume-start.go @@ -84,9 +84,11 @@ func volumeStartHandler(w http.ResponseWriter, r *http.Request) { volinfo, err := volume.GetVolume(volname) if err != nil { - // TODO: Distinguish between volume not present (404) and - // store access failure (503) - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } diff --git a/glusterd2/commands/volumes/volume-statedump.go b/glusterd2/commands/volumes/volume-statedump.go index 6772a0f7e..c32cea0e3 100644 --- a/glusterd2/commands/volumes/volume-statedump.go +++ b/glusterd2/commands/volumes/volume-statedump.go @@ -116,9 +116,11 @@ func volumeStatedumpHandler(w http.ResponseWriter, r *http.Request) { volinfo, err := volume.GetVolume(volname) if err != nil { - // TODO: Distinguish between volume not present (404) and - // store access failure (503) - restutils.SendHTTPError(ctx, w, http.StatusNotFound, gderrors.ErrVolNotFound) + if err == gderrors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, gderrors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } diff --git a/glusterd2/commands/volumes/volume-status.go b/glusterd2/commands/volumes/volume-status.go index 7d4969e4c..329f50a64 100644 --- a/glusterd2/commands/volumes/volume-status.go +++ b/glusterd2/commands/volumes/volume-status.go @@ -20,9 +20,11 @@ func volumeStatusHandler(w http.ResponseWriter, r *http.Request) { volinfo, err := volume.GetVolume(volname) if err != nil { - // TODO: Distinguish between volume not present (404) and - // store access failure (503) - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } diff --git a/glusterd2/commands/volumes/volume-stop.go b/glusterd2/commands/volumes/volume-stop.go index 68ce70322..012e032d8 100644 --- a/glusterd2/commands/volumes/volume-stop.go +++ b/glusterd2/commands/volumes/volume-stop.go @@ -91,9 +91,11 @@ func volumeStopHandler(w http.ResponseWriter, r *http.Request) { volinfo, err := volume.GetVolume(volname) if err != nil { - // TODO: Distinguish between volume not present (404) and - // store access failure (503) - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } diff --git a/glusterd2/volume/store-utils.go b/glusterd2/volume/store-utils.go index 1368d75f1..609f7681c 100644 --- a/glusterd2/volume/store-utils.go +++ b/glusterd2/volume/store-utils.go @@ -3,9 +3,9 @@ package volume import ( "context" "encoding/json" - "errors" "github.com/gluster/glusterd2/glusterd2/store" + gderror "github.com/gluster/glusterd2/pkg/errors" "github.com/coreos/etcd/clientv3" "github.com/pborman/uuid" @@ -49,7 +49,7 @@ func GetVolume(name string) (*Volinfo, error) { if resp.Count != 1 { log.WithField("volume", name).Error("volume not found") - return nil, errors.New("volume not found") + return nil, gderror.ErrVolNotFound } if e = json.Unmarshal(resp.Kvs[0].Value, &v); e != nil { diff --git a/plugins/bitrot/rest.go b/plugins/bitrot/rest.go index 6f9fec38c..b76c26105 100644 --- a/plugins/bitrot/rest.go +++ b/plugins/bitrot/rest.go @@ -28,7 +28,11 @@ func bitrotEnableHandler(w http.ResponseWriter, r *http.Request) { // Validate volume existence volinfo, err := volume.GetVolume(volName) if err != nil { - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } @@ -115,7 +119,11 @@ func bitrotDisableHandler(w http.ResponseWriter, r *http.Request) { // Validate volume existence volinfo, err := volume.GetVolume(volName) if err != nil { - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } @@ -191,7 +199,11 @@ func bitrotScrubOndemandHandler(w http.ResponseWriter, r *http.Request) { // Validate volume existence volinfo, err := volume.GetVolume(volName) if err != nil { - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } @@ -252,8 +264,11 @@ func bitrotScrubStatusHandler(w http.ResponseWriter, r *http.Request) { // Validate volume existence volinfo, err := volume.GetVolume(volName) if err != nil { - restutils.SendHTTPError(ctx, w, http.StatusNotFound, - errors.ErrVolNotFound) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } diff --git a/plugins/device/rest.go b/plugins/device/rest.go index 7b322c63b..098e528cd 100644 --- a/plugins/device/rest.go +++ b/plugins/device/rest.go @@ -33,7 +33,11 @@ func deviceAddHandler(w http.ResponseWriter, r *http.Request) { peerInfo, err := peer.GetPeer(peerID) if err != nil { logger.WithError(err).WithField("peerid", peerID).Error("Peer ID not found in store") - restutils.SendHTTPError(ctx, w, http.StatusNotFound, "Peer Id not found in store") + if err == errors.ErrPeerNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrPeerNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, "Failed to get peer from store") + } return } txn := transaction.NewTxn(ctx) @@ -68,8 +72,11 @@ func deviceAddHandler(w http.ResponseWriter, r *http.Request) { } peerInfo, err = peer.GetPeer(peerID) if err != nil { - logger.WithError(err).Error("Failed to get peer from store") - restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, "Failed to get peer from store") + if err == errors.ErrPeerNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrPeerNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, "Failed to get peer from store") + } return } restutils.SendHTTPResponse(ctx, w, http.StatusOK, peerInfo) diff --git a/plugins/georeplication/rest.go b/plugins/georeplication/rest.go index 7138d9767..5c8ae68a4 100644 --- a/plugins/georeplication/rest.go +++ b/plugins/georeplication/rest.go @@ -113,7 +113,11 @@ func georepCreateHandler(w http.ResponseWriter, r *http.Request) { // Check if Master volume exists and Matches with passed Volume ID vol, e := volume.GetVolume(req.MasterVol) if e != nil { - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } @@ -274,7 +278,11 @@ func georepActionHandler(w http.ResponseWriter, r *http.Request, action actionTy // Fetch Volume details and check if Volume is in started state vol, e := volume.GetVolume(geoSession.MasterVol) if e != nil { - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } @@ -407,7 +415,11 @@ func georepDeleteHandler(w http.ResponseWriter, r *http.Request) { // Fetch Volume details and check if Volume exists _, e := volume.GetVolume(geoSession.MasterVol) if e != nil { - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } @@ -492,7 +504,11 @@ func georepStatusHandler(w http.ResponseWriter, r *http.Request) { // Get Volume info, which is required to get the Bricks list vol, e := volume.GetVolume(geoSession.MasterVol) if e != nil { - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } @@ -745,7 +761,11 @@ func georepConfigSetHandler(w http.ResponseWriter, r *http.Request) { vol, e := volume.GetVolume(geoSession.MasterVol) if e != nil { - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } @@ -894,7 +914,11 @@ func georepConfigResetHandler(w http.ResponseWriter, r *http.Request) { vol, e := volume.GetVolume(geoSession.MasterVol) if e != nil { - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } @@ -990,7 +1014,11 @@ func georepSSHKeyGenerateHandler(w http.ResponseWriter, r *http.Request) { // Check if Volume exists vol, e := volume.GetVolume(volname) if e != nil { - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if e == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, e) + } return } @@ -1075,7 +1103,11 @@ func georepSSHKeyPushHandler(w http.ResponseWriter, r *http.Request) { // Check if Volume exists vol, e := volume.GetVolume(volname) if e != nil { - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if e == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, e) + } return } diff --git a/plugins/glustershd/rest.go b/plugins/glustershd/rest.go index e0476abaf..a62f46ed6 100644 --- a/plugins/glustershd/rest.go +++ b/plugins/glustershd/rest.go @@ -33,7 +33,11 @@ func glustershEnableHandler(w http.ResponseWriter, r *http.Request) { //validate volume name v, err := volume.GetVolume(volname) if err != nil { - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } // Store initial volinfo before changing the HealFlag @@ -116,7 +120,11 @@ func glustershDisableHandler(w http.ResponseWriter, r *http.Request) { //validate volume name v, err := volume.GetVolume(volname) if err != nil { - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } // Store initial volinfo before changing the HealFlag diff --git a/plugins/quota/rest.go b/plugins/quota/rest.go index 55d386aa7..7fa44b7c1 100644 --- a/plugins/quota/rest.go +++ b/plugins/quota/rest.go @@ -50,7 +50,11 @@ func quotaEnableHandler(w http.ResponseWriter, r *http.Request) { // Validate volume existence vol, err := volume.GetVolume(volName) if err != nil { - restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + if err == errors.ErrVolNotFound { + restutils.SendHTTPError(ctx, w, http.StatusNotFound, errors.ErrVolNotFound) + } else { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err) + } return } From 9e9baeee5ec095d08bb4ad5d40abbd61baa7e4b3 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Mon, 23 Apr 2018 15:21:10 -0400 Subject: [PATCH 2/4] 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 fb8ec6252..f31114993 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 4ccf9d2f9..0844066db 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 4d91c793b..29947531d 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 8632a437b..3b9cf5817 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 ffa27a863..eae447018 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 457ce7308..895b76191 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") From 1313ad930910fb414cd2f7c476a67acc886406f0 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Wed, 25 Apr 2018 11:33:11 +0530 Subject: [PATCH 3/4] pkgs:utils added return if failed to write to file Signed-off-by: Madhu Rajanna --- pkg/utils/statedump.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/utils/statedump.go b/pkg/utils/statedump.go index 2854e2a2a..24e57fafc 100644 --- a/pkg/utils/statedump.go +++ b/pkg/utils/statedump.go @@ -34,6 +34,7 @@ func WriteStatedump() { if err := ioutil.WriteFile(dumpPath, respBody, 0644); err != nil { log.WithError(err).WithField("file", dumpPath).Error("Failed to write statedump to file") + return } log.WithField("file", dumpPath).Info("Statedump written to file") } From 118f610ce8b590d5e754fa7b2876bb09a8dbc1e3 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 24 Apr 2018 08:47:49 -0400 Subject: [PATCH 4/4] Add Metadata as a new field in volinfo which acts like a dictionary and populate it during volume create. Signed-off-by: Vishal Pandey --- glusterd2/commands/volumes/volume-create-txn.go | 6 ++++++ glusterd2/commands/volumes/volume-create_test.go | 2 ++ glusterd2/volume/struct.go | 1 + glusterd2/volume/volume-utils.go | 1 + pkg/api/volume_req.go | 1 + pkg/api/volume_resp.go | 1 + 6 files changed, 12 insertions(+) diff --git a/glusterd2/commands/volumes/volume-create-txn.go b/glusterd2/commands/volumes/volume-create-txn.go index 4df367acf..0aa758cdb 100644 --- a/glusterd2/commands/volumes/volume-create-txn.go +++ b/glusterd2/commands/volumes/volume-create-txn.go @@ -146,6 +146,12 @@ func newVolinfo(req *api.VolCreateReq) (*volume.Volinfo, error) { return nil, err } + if req.Metadata != nil { + volinfo.Metadata = req.Metadata + } else { + volinfo.Metadata = make(map[string]string) + } + return volinfo, nil } diff --git a/glusterd2/commands/volumes/volume-create_test.go b/glusterd2/commands/volumes/volume-create_test.go index 007fe56e1..8861665d9 100644 --- a/glusterd2/commands/volumes/volume-create_test.go +++ b/glusterd2/commands/volumes/volume-create_test.go @@ -30,6 +30,8 @@ func TestCreateVolinfo(t *testing.T) { {PeerID: u.String(), Path: "/tmp/b1"}, {PeerID: u.String(), Path: "/tmp/b2"}, }}} + msg.Metadata = make(map[string]string) + msg.Metadata["owner"] = "gd2test" vol, e := newVolinfo(msg) assert.Nil(t, e) assert.NotNil(t, vol) diff --git a/glusterd2/volume/struct.go b/glusterd2/volume/struct.go index 3452873a2..e098fc3a4 100644 --- a/glusterd2/volume/struct.go +++ b/glusterd2/volume/struct.go @@ -109,6 +109,7 @@ type Volinfo struct { Auth VolAuth // TODO: should not be returned to client GraphMap map[string]string HealEnabled bool + Metadata map[string]string } // VolAuth represents username and password used by trusted/internal clients diff --git a/glusterd2/volume/volume-utils.go b/glusterd2/volume/volume-utils.go index 59728e909..fd4e9eb81 100644 --- a/glusterd2/volume/volume-utils.go +++ b/glusterd2/volume/volume-utils.go @@ -184,5 +184,6 @@ func CreateVolumeInfoResp(v *Volinfo) *api.VolumeInfo { State: api.VolState(v.State), Options: v.Options, Subvols: CreateSubvolInfo(&v.Subvols), + Metadata: v.Metadata, } } diff --git a/pkg/api/volume_req.go b/pkg/api/volume_req.go index 6216705ef..4319399ec 100644 --- a/pkg/api/volume_req.go +++ b/pkg/api/volume_req.go @@ -29,6 +29,7 @@ type VolCreateReq struct { Advanced bool `json:"advanced,omitempty"` Experimental bool `json:"experimental,omitempty"` Deprecated bool `json:"deprecated,omitempty"` + Metadata map[string]string `json:"metadata,omitempty"` } // VolOptionReq represents an incoming request to set volume options diff --git a/pkg/api/volume_resp.go b/pkg/api/volume_resp.go index c527ad5a5..311b1e6ec 100644 --- a/pkg/api/volume_resp.go +++ b/pkg/api/volume_resp.go @@ -62,6 +62,7 @@ type VolumeInfo struct { Options map[string]string `json:"options"` State VolState `json:"state"` Subvols []Subvol `json:"subvols"` + Metadata map[string]string `json:"metadata"` } // VolumeStatusResp response contains the statuses of all bricks of the volume.