mirror of
https://github.com/gluster/glusterd2.git
synced 2026-02-05 12:45:38 +01:00
'--advanced' in the CLI and REST API during volume create doesn't intuitively and clearly indicate that it's for the volume options. A new user may read this as creation of an "advanced volume" which isn't true. The flags have now been prepended with 'allow' in the fields of request structs. The API has been renamed as 'allow-<type>-options'. Also, created 'VolOptionFlags' struct for flags of options and embeded it in all request structs. Signed-off-by: Prashanth Pai <ppai@redhat.com>
132 lines
3.0 KiB
Go
132 lines
3.0 KiB
Go
package e2e
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"path"
|
|
"testing"
|
|
|
|
"github.com/gluster/glusterd2/pkg/api"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestQuota creates a volume and starts it, runs further quota enable on it
|
|
// and finally deletes the volume
|
|
func TestQuota(t *testing.T) {
|
|
var err error
|
|
var brickPaths []string
|
|
r := require.New(t)
|
|
|
|
tc, err := setupCluster(t, "./config/1.toml", "./config/2.toml")
|
|
r.Nil(err)
|
|
defer teardownCluster(tc)
|
|
|
|
brickDir := testTempDir(t, "bricks")
|
|
defer os.RemoveAll(brickDir)
|
|
|
|
volumeName := formatVolName(t.Name())
|
|
|
|
for i := 1; i <= 4; i++ {
|
|
brickPath, err := ioutil.TempDir(brickDir, "brick")
|
|
r.Nil(err)
|
|
brickPaths = append(brickPaths, brickPath)
|
|
}
|
|
|
|
client, err := initRestclient(tc.gds[0])
|
|
r.Nil(err)
|
|
r.NotNil(client)
|
|
|
|
// create 2x2 dist-rep volume
|
|
createReq := api.VolCreateReq{
|
|
Name: volumeName,
|
|
Subvols: []api.SubvolReq{
|
|
{
|
|
ReplicaCount: 2,
|
|
Type: "replicate",
|
|
Bricks: []api.BrickReq{
|
|
{PeerID: tc.gds[0].PeerID(), Path: brickPaths[0]},
|
|
{PeerID: tc.gds[1].PeerID(), Path: brickPaths[1]},
|
|
},
|
|
},
|
|
{
|
|
Type: "replicate",
|
|
ReplicaCount: 2,
|
|
Bricks: []api.BrickReq{
|
|
{PeerID: tc.gds[0].PeerID(), Path: brickPaths[2]},
|
|
{PeerID: tc.gds[1].PeerID(), Path: brickPaths[3]},
|
|
},
|
|
},
|
|
},
|
|
Force: true,
|
|
}
|
|
|
|
_, err = client.VolumeCreate(createReq)
|
|
r.Nil(err)
|
|
|
|
// test Quota on dist-rep volume
|
|
t.Run("Quota-enable", tc.wrap(testQuotaEnable))
|
|
|
|
r.Nil(client.VolumeDelete(volumeName))
|
|
}
|
|
|
|
func testQuotaEnable(t *testing.T, tc *testCluster) {
|
|
var err error
|
|
r := require.New(t)
|
|
|
|
// form the pidfile path
|
|
pidpath := path.Join(tc.gds[0].Rundir, "quotad.pid")
|
|
|
|
quotaKey := "quota.enable"
|
|
var optionReqOff api.VolOptionReq
|
|
optionReqOff.AllowAdvanced = true
|
|
|
|
optionReqOff.Options = map[string]string{quotaKey: "off"}
|
|
|
|
// Quota not enabled: no quotad should be there
|
|
err = client.VolumeSet(volname, optionReqOff)
|
|
r.Contains(err.Error(), "quotad is not enabled")
|
|
|
|
// Checking if the quotad is not running
|
|
r.False(isProcessRunning(pidpath))
|
|
|
|
var optionReqOn api.VolOptionReq
|
|
optionReqOn.AllowAdvanced = true
|
|
|
|
// Enable quota
|
|
quotaKey = "quota.enable"
|
|
optionReqOn.Options = map[string]string{quotaKey: "on"}
|
|
// Quotad should be there
|
|
r.Nil(client.VolumeSet(volname, optionReqOn))
|
|
|
|
// Checking if the quotad is running
|
|
r.True(isProcessRunning(pidpath))
|
|
|
|
// check the error for enabling it again
|
|
err = client.VolumeSet(volname, optionReqOn)
|
|
r.Contains(err.Error(), "process is already running")
|
|
|
|
// Checking if the quotad is running
|
|
r.True(isProcessRunning(pidpath))
|
|
|
|
// Disable quota
|
|
r.Nil(client.VolumeSet(volname, optionReqOff))
|
|
|
|
// Checking if the quotad is not running
|
|
r.False(isProcessRunning(pidpath))
|
|
|
|
// Check the error for disabling it again.
|
|
err = client.VolumeSet(volname, optionReqOff)
|
|
r.Contains(err.Error(), "quotad is not enabled")
|
|
|
|
// Checking if the quotad is not running
|
|
r.False(isProcessRunning(pidpath))
|
|
|
|
// Stop Volume
|
|
r.Nil(client.VolumeStop(volname), "Volume stop failed")
|
|
// delete volume
|
|
err = client.VolumeDelete(volname)
|
|
r.Nil(err)
|
|
|
|
}
|