From 7fbccba74276fe7ab989e42ea5f420e9a9a48698 Mon Sep 17 00:00:00 2001 From: rishubhjain Date: Tue, 18 Dec 2018 11:36:39 -0500 Subject: [PATCH] Adding glustercli command for cluster options and volume options Signed-off-by: rishubhjain --- e2e/cluster_test.go | 48 +++++++++++ e2e/smartvol_ops_test.go | 9 ++ glustercli/cmd/cluster-options.go | 96 +++++++++++++++++++++ glustercli/cmd/root.go | 1 + glustercli/cmd/volume.go | 58 ++++++++----- glusterd2/commands/volumes/volume-create.go | 5 ++ glusterd2/options/cluster.go | 2 - pkg/restclient/cluster.go | 22 +++++ pkg/restclient/volume.go | 8 +- pkg/utils/utils.go | 12 +++ 10 files changed, 231 insertions(+), 30 deletions(-) create mode 100644 e2e/cluster_test.go create mode 100644 glustercli/cmd/cluster-options.go create mode 100644 pkg/restclient/cluster.go diff --git a/e2e/cluster_test.go b/e2e/cluster_test.go new file mode 100644 index 000000000..523fe868a --- /dev/null +++ b/e2e/cluster_test.go @@ -0,0 +1,48 @@ +package e2e + +import ( + "testing" + + "github.com/gluster/glusterd2/pkg/api" + + "github.com/stretchr/testify/require" +) + +func testGetClusterOptions(t *testing.T) { + r := require.New(t) + clusterOps, err := client.GetClusterOption() + r.Nil(err) + r.NotNil(clusterOps) +} + +func ClusterOptionsSet(t *testing.T) { + r := require.New(t) + optReq := api.ClusterOptionReq{ + Options: map[string]string{"cluster.brick-multiplex": "on"}, + } + err := client.ClusterOptionSet(optReq) + r.Nil(err) + clusterOps, err := client.GetClusterOption() + for _, ops := range clusterOps { + if ops.Key == "cluster.brick-multiplex" { + r.Equal(ops.Value, "on") + } + } +} + +// TestClusterOption creates a cluster +func TestClusterOption(t *testing.T) { + var err error + + r := require.New(t) + + tc, err := setupCluster(t, "./config/1.toml", "./config/2.toml", "./config/3.toml") + r.Nil(err) + defer teardownCluster(tc) + + client, err = initRestclient(tc.gds[0]) + r.Nil(err) + r.NotNil(client) + + t.Run("Get Cluster Options", testGetClusterOptions) +} diff --git a/e2e/smartvol_ops_test.go b/e2e/smartvol_ops_test.go index a5d099576..602078a9b 100644 --- a/e2e/smartvol_ops_test.go +++ b/e2e/smartvol_ops_test.go @@ -181,6 +181,15 @@ func testSmartVolumeDistribute(t *testing.T) { r.NotNil(err) r.Nil(client.VolumeDelete(smartvolname)) + + createReq = api.VolCreateReq{ + Name: "volume", + Size: 60 * gutils.MiB, + DistributeCount: 3, + } + volinfo, err = client.VolumeCreate(createReq) + r.NotNil(err) + checkZeroLvs(r) } diff --git a/glustercli/cmd/cluster-options.go b/glustercli/cmd/cluster-options.go new file mode 100644 index 000000000..f87c2f10e --- /dev/null +++ b/glustercli/cmd/cluster-options.go @@ -0,0 +1,96 @@ +package cmd + +import ( + "errors" + "fmt" + "os" + + "github.com/gluster/glusterd2/pkg/api" + + "github.com/olekukonko/tablewriter" + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" +) + +const ( + helpClusterOptionCmd = "Gluster Cluster Option Management" + helpClusterOptionSetCmd = "Set Cluster Option" + helpClusterOptionGetCmd = "Get Cluster Option" +) + +func init() { + clusterCmd.AddCommand(clusterOptionGetCmd) + clusterCmd.AddCommand(clusterOptionSetCmd) +} + +var clusterCmd = &cobra.Command{ + Use: "cluster", + Short: helpClusterOptionCmd, +} + +var clusterOptionSetCmd = &cobra.Command{ + Use: "set