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

Commit 585b080

Browse files
committed
Merge branch 'master' of https://github.com/gluster/glusterd2 into delete_device
2 parents 054bbe0 + af5928b commit 585b080

5 files changed

Lines changed: 35 additions & 5 deletions

File tree

e2e/smartvol_ops_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,18 @@ func testSmartVolumeDistributeDisperse(t *testing.T) {
316316
checkZeroLvs(r)
317317
}
318318

319+
func testDeviceDelete(t *testing.T) {
320+
r := require.New(t)
321+
deviceList, err := client.DeviceList(tc.gds[0].PeerID())
322+
323+
_, err := client.DeviceDelete(tc.gds[0].PeerID(), "/dev/gluster_loop1")
324+
r.Nil(err)
325+
326+
newDeviceList, err := client.DeviceList(tc.gds[0].PeerID())
327+
328+
r.NotEqual(len(deviceList), len(newDeviceList))
329+
}
330+
319331
// TestSmartVolume creates a volume and starts it, runs further tests on it and
320332
// finally deletes the volume
321333
func TestSmartVolume(t *testing.T) {
@@ -355,6 +367,7 @@ func TestSmartVolume(t *testing.T) {
355367
t.Run("Smartvol Disperse Volume", testSmartVolumeDisperse)
356368
t.Run("Smartvol Distributed-Replicate Volume", testSmartVolumeDistributeReplicate)
357369
t.Run("Smartvol Distributed-Disperse Volume", testSmartVolumeDistributeDisperse)
370+
t.Run("Delete device", testDeviceDelete)
358371

359372
// // Device Cleanup
360373
r.Nil(loopDevicesCleanup(t))

pkg/restclient/device.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package restclient
22

33
import (
4+
"fmt"
45
"net/http"
56

67
deviceapi "github.com/gluster/glusterd2/plugins/device/api"
@@ -15,3 +16,17 @@ func (c *Client) DeviceAdd(peerid string, device string) (deviceapi.AddDeviceRes
1516
err := c.post("/v1/devices/"+peerid, req, http.StatusOK, &peerinfo)
1617
return peerinfo, err
1718
}
19+
20+
// DeviceDelete removes devices
21+
func (c *Client) DeviceDelete(peerid string, device string) error {
22+
url := fmt.Sprintf("/v1/devices/+%s+/+%s", peerid, device)
23+
return c.del(url, nil, http.StatusNoContent, nil)
24+
}
25+
26+
// DeviceList lists the devices
27+
func (c *Client) DeviceList(peerid string) ([]deviceapi.Info, error) {
28+
var deviceList deviceapi.ListDeviceResp
29+
url := fmt.Sprintf("/v1/devices/%s", peerid)
30+
err := c.get(url, nil, http.StatusOK, &deviceList)
31+
return deviceList, err
32+
}

plugins/device/deviceutils/store-utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ func IsVgExist(vgname string) bool {
199199
}
200200

201201
// getDeviceAvailableSize gets the device size and vgName using device Path
202-
func getDeviceAvailableSize(devicePath string) (string, uint64, error) {
203-
devices, err := GetDevices()
202+
func getDeviceAvailableSize(peerid, devicePath string) (string, uint64, error) {
203+
devices, err := GetDevices(peerid)
204204
if err != nil {
205205
return "", 0, err
206206
}
@@ -235,7 +235,7 @@ func CheckForAvailableVgSize(expansionSize uint64, bricksInfo []brick.Brickinfo)
235235
// Check in the map prepared in last step by looking through devices names and device available size of bricks from current node.
236236
for _, b := range bricksInfo {
237237
// retrieve device available size by device Name and return the vgName and available device Size.
238-
vgName, deviceSize, err := getDeviceAvailableSize(b.MountInfo.DevicePath)
238+
vgName, deviceSize, err := getDeviceAvailableSize(b.PeerID.String(), b.MountInfo.DevicePath)
239239
if err != nil {
240240
return map[string]string{}, false, err
241241
}

plugins/device/init.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ func (p *Plugin) RestRoutes() route.Routes {
4848
Version: 1,
4949
ResponseType: utils.GetTypeString((*deviceapi.ListDeviceResp)(nil)),
5050
HandlerFunc: listAllDevicesHandler},
51-
// device name is passed as query param in url.
52-
// example: /devices/{peerid}?device="/device/path"
5351
route.Route{
5452
Name: "DeviceDelete",
5553
Method: "DELETE",

plugins/device/rest.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package device
33
import (
44
"fmt"
55
"net/http"
6+
"strings"
67

78
"github.com/gluster/glusterd2/glusterd2/gdctx"
89
"github.com/gluster/glusterd2/glusterd2/peer"
@@ -183,6 +184,9 @@ func deviceDeleteHandler(w http.ResponseWriter, r *http.Request) {
183184
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, "Device name not provided in URL")
184185
return
185186
}
187+
if !strings.HasPrefix(deviceName, "/") {
188+
deviceName = "/" + deviceName
189+
}
186190

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

0 commit comments

Comments
 (0)