Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/gluster/glusterd2 into de…
Browse files Browse the repository at this point in the history
…lete_device
  • Loading branch information
rishubhjain committed Nov 29, 2018
2 parents 054bbe0 + af5928b commit adc34f2
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
25 changes: 25 additions & 0 deletions e2e/smartvol_ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,30 @@ func testSmartVolumeDistributeDisperse(t *testing.T) {
checkZeroLvs(r)
}

func testDeviceDelete(t *testing.T) {
r := require.New(t)
peerList, err := client.Peers()
r.Nil(err)

var deviceList []deviceapi.Info
var peerID string
for _, peer := range peerList {
deviceList, err := client.DeviceList(peer.ID.String())
r.Nil(err)
if len(deviceList) > 1 {
peerID = peer.ID.String()
break
}
}

_, err := client.DeviceDelete(peerID, deviceList[0])
r.Nil(err)

newDeviceList, err := client.DeviceList(peerID)

r.NotEqual(len(deviceList), len(newDeviceList))
}

// TestSmartVolume creates a volume and starts it, runs further tests on it and
// finally deletes the volume
func TestSmartVolume(t *testing.T) {
Expand Down Expand Up @@ -355,6 +379,7 @@ func TestSmartVolume(t *testing.T) {
t.Run("Smartvol Disperse Volume", testSmartVolumeDisperse)
t.Run("Smartvol Distributed-Replicate Volume", testSmartVolumeDistributeReplicate)
t.Run("Smartvol Distributed-Disperse Volume", testSmartVolumeDistributeDisperse)
t.Run("Delete device", testDeviceDelete)

// // Device Cleanup
r.Nil(loopDevicesCleanup(t))
Expand Down
15 changes: 15 additions & 0 deletions pkg/restclient/device.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package restclient

import (
"fmt"
"net/http"

deviceapi "github.com/gluster/glusterd2/plugins/device/api"
Expand All @@ -15,3 +16,17 @@ func (c *Client) DeviceAdd(peerid string, device string) (deviceapi.AddDeviceRes
err := c.post("/v1/devices/"+peerid, req, http.StatusOK, &peerinfo)
return peerinfo, err
}

// DeviceDelete removes devices
func (c *Client) DeviceDelete(peerid string, device string) error {
url := fmt.Sprintf("/v1/devices/+%s+/+%s", peerid, device)
return c.del(url, nil, http.StatusNoContent, nil)
}

// DeviceList lists the devices
func (c *Client) DeviceList(peerid string) ([]deviceapi.Info, error) {
var deviceList deviceapi.ListDeviceResp
url := fmt.Sprintf("/v1/devices/%s", peerid)
err := c.get(url, nil, http.StatusOK, &deviceList)
return deviceList, err
}
6 changes: 3 additions & 3 deletions plugins/device/deviceutils/store-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ func IsVgExist(vgname string) bool {
}

// getDeviceAvailableSize gets the device size and vgName using device Path
func getDeviceAvailableSize(devicePath string) (string, uint64, error) {
devices, err := GetDevices()
func getDeviceAvailableSize(peerid, devicePath string) (string, uint64, error) {
devices, err := GetDevices(peerid)
if err != nil {
return "", 0, err
}
Expand Down Expand Up @@ -235,7 +235,7 @@ func CheckForAvailableVgSize(expansionSize uint64, bricksInfo []brick.Brickinfo)
// Check in the map prepared in last step by looking through devices names and device available size of bricks from current node.
for _, b := range bricksInfo {
// retrieve device available size by device Name and return the vgName and available device Size.
vgName, deviceSize, err := getDeviceAvailableSize(b.MountInfo.DevicePath)
vgName, deviceSize, err := getDeviceAvailableSize(b.PeerID.String(), b.MountInfo.DevicePath)
if err != nil {
return map[string]string{}, false, err
}
Expand Down
2 changes: 0 additions & 2 deletions plugins/device/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ func (p *Plugin) RestRoutes() route.Routes {
Version: 1,
ResponseType: utils.GetTypeString((*deviceapi.ListDeviceResp)(nil)),
HandlerFunc: listAllDevicesHandler},
// device name is passed as query param in url.
// example: /devices/{peerid}?device="/device/path"
route.Route{
Name: "DeviceDelete",
Method: "DELETE",
Expand Down
4 changes: 4 additions & 0 deletions plugins/device/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package device
import (
"fmt"
"net/http"
"strings"

"github.com/gluster/glusterd2/glusterd2/gdctx"
"github.com/gluster/glusterd2/glusterd2/peer"
Expand Down Expand Up @@ -183,6 +184,9 @@ func deviceDeleteHandler(w http.ResponseWriter, r *http.Request) {
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, "Device name not provided in URL")
return
}
if !strings.HasPrefix(deviceName, "/") {
deviceName = "/" + deviceName
}

txn, err := transaction.NewTxnWithLocks(ctx, peerID+deviceName)
if err != nil {
Expand Down

0 comments on commit adc34f2

Please sign in to comment.