This repository has been archived by the owner on Mar 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
API to remove device #1120
Open
rishubhjain
wants to merge
4
commits into
gluster:master
Choose a base branch
from
rishubhjain:delete_device
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
API to remove device #1120
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
17496a8
API to remove device
rishubhjain fb3f69a
Merge branch 'master' of https://github.com/gluster/glusterd2 into de…
rishubhjain 11efa13
Merge branch 'master' of https://github.com/gluster/glusterd2 into de…
rishubhjain c4d3db0
Merge branch 'master' of https://github.com/gluster/glusterd2 into de…
rishubhjain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
package e2e | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gluster/glusterd2/pkg/api" | ||
gutils "github.com/gluster/glusterd2/pkg/utils" | ||
deviceapi "github.com/gluster/glusterd2/plugins/device/api" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func editDevice(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(), "") | ||
if len(deviceList) > 0 { | ||
peerID = peer.ID.String() | ||
break | ||
} | ||
} | ||
|
||
device := deviceList[0] | ||
if device.State == "enabled" { | ||
err = client.DeviceEdit(peerID, device.Device, "disabled") | ||
r.Nil(err) | ||
} else if device.State == "disabled" { | ||
err = client.DeviceEdit(peerID, device.Device, "enabled") | ||
r.Nil(err) | ||
} | ||
newDeviceList, err := client.DeviceList(peerID, "") | ||
r.Nil(err) | ||
for _, newDevice := range newDeviceList { | ||
if newDevice.Device == device.Device { | ||
r.NotEqual(newDevice.State, device.State) | ||
} | ||
} | ||
|
||
for _, peer := range peerList { | ||
deviceList, err := client.DeviceList(peer.ID.String(), "") | ||
r.Nil(err) | ||
for _, device := range deviceList { | ||
if device.State == "enabled" { | ||
err = client.DeviceEdit(peer.ID.String(), device.Device, "disabled") | ||
r.Nil(err) | ||
} | ||
} | ||
} | ||
smartvolname := formatVolName(t.Name()) | ||
|
||
// create Distribute Replicate(2x3) Volume | ||
createReq := api.VolCreateReq{ | ||
Name: smartvolname, | ||
Size: 40 * gutils.MiB, | ||
DistributeCount: 2, | ||
ReplicaCount: 3, | ||
SubvolZonesOverlap: true, | ||
} | ||
_, err = client.VolumeCreate(createReq) | ||
r.NotNil(err) | ||
|
||
for _, peer := range peerList { | ||
deviceList, err := client.DeviceList(peer.ID.String(), "") | ||
r.Nil(err) | ||
for _, device := range deviceList { | ||
if device.State == "disabled" { | ||
err = client.DeviceEdit(peer.ID.String(), device.Device, "enabled") | ||
r.Nil(err) | ||
} | ||
} | ||
} | ||
|
||
_, err = client.VolumeCreate(createReq) | ||
r.Nil(err) | ||
|
||
r.Nil(client.VolumeDelete(smartvolname)) | ||
} | ||
|
||
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) > 0 { | ||
peerID = peer.ID.String() | ||
break | ||
} | ||
} | ||
|
||
smartvolname := formatVolName(t.Name()) | ||
// create Distribute 3 Volume | ||
createReq := api.VolCreateReq{ | ||
Name: smartvolname, | ||
Size: 60 * gutils.MiB, | ||
DistributeCount: 3, | ||
} | ||
|
||
_, err = client.VolumeCreate(createReq) | ||
r.Nil(err) | ||
|
||
err = client.DeviceDelete(peerID, deviceList[0].Device) | ||
r.Nil(err) | ||
|
||
newDeviceList, err := client.DeviceList(peerID, "") | ||
r.Nil(err) | ||
|
||
r.Equal(len(deviceList)-1, len(newDeviceList)) | ||
} | ||
|
||
// TestDevice creates devices in the test environment | ||
// finally deletes the devices | ||
func TestDevice(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) | ||
|
||
devicesDir := testTempDir(t, "devices") | ||
|
||
// Device Setup | ||
// Around 150MB will be reserved during pv/vg creation, create device with more size | ||
r.Nil(prepareLoopDevice(devicesDir+"/gluster_dev1.img", "1", "250M")) | ||
r.Nil(prepareLoopDevice(devicesDir+"/gluster_dev2.img", "2", "250M")) | ||
r.Nil(prepareLoopDevice(devicesDir+"/gluster_dev3.img", "3", "250M")) | ||
|
||
_, err = client.DeviceAdd(tc.gds[0].PeerID(), "/dev/gluster_loop1") | ||
r.Nil(err) | ||
dev, err := client.DeviceList(tc.gds[0].PeerID(), "/dev/gluster_loop1") | ||
r.Nil(err) | ||
r.Equal(dev[0].Device, "/dev/gluster_loop1") | ||
|
||
_, err = client.DeviceAdd(tc.gds[1].PeerID(), "/dev/gluster_loop2") | ||
r.Nil(err) | ||
dev, err = client.DeviceList(tc.gds[1].PeerID(), "/dev/gluster_loop2") | ||
r.Nil(err) | ||
r.Equal(dev[0].Device, "/dev/gluster_loop2") | ||
|
||
_, err = client.DeviceAdd(tc.gds[2].PeerID(), "/dev/gluster_loop3") | ||
r.Nil(err) | ||
dev, err = client.DeviceList(tc.gds[2].PeerID(), "/dev/gluster_loop3") | ||
r.Nil(err) | ||
r.Equal(dev[0].Device, "/dev/gluster_loop3") | ||
|
||
t.Run("Edit device", editDevice) | ||
t.Run("Delete device", testDeviceDelete) | ||
|
||
// // Device Cleanup | ||
r.Nil(loopDevicesCleanup(t)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move this after device add? even if the device remove or device list fails, these block fo code won't get hit. it's good to do cleanup in
defer()
.@aravindavk let me know your thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move all the clean up task to defer? Like deleting and stopping volume etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is also called in main_test.go, so should be fine