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
Edit device #1118
Merged
+116
−10
Merged
Edit device #1118
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
|
||
"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" | ||
) | ||
|
@@ -316,6 +317,77 @@ func testSmartVolumeDistributeDisperse(t *testing.T) { | |
checkZeroLvs(r) | ||
} | ||
|
||
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.Name, "disabled") | ||
r.Nil(err) | ||
} else if device.State == "disabled" { | ||
err = client.DeviceEdit(peerID, device.Name, "enabled") | ||
r.Nil(err) | ||
} | ||
newDeviceList, err := client.DeviceList(peerID) | ||
r.Nil(err) | ||
for _, newDevice := range newDeviceList { | ||
if newDevice.Name == device.Name { | ||
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.Name, "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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. enable the devices and create the volume, the volume creation should be successful. |
||
|
||
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.Name, "enabled") | ||
r.Nil(err) | ||
} | ||
} | ||
} | ||
|
||
_, err = client.VolumeCreate(createReq) | ||
r.Nil(err) | ||
|
||
r.Nil(client.VolumeDelete(smartvolname)) | ||
} | ||
|
||
// TestSmartVolume creates a volume and starts it, runs further tests on it and | ||
// finally deletes the volume | ||
func TestSmartVolume(t *testing.T) { | ||
|
@@ -355,6 +427,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("Edit device", editDevice) | ||
|
||
// // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,38 @@ | ||
package restclient | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
|
||
deviceapi "github.com/gluster/glusterd2/plugins/device/api" | ||
) | ||
|
||
// DeviceAdd registers devices | ||
func (c *Client) DeviceAdd(peerid string, device string) (deviceapi.AddDeviceResp, error) { | ||
// DeviceAdd registers device | ||
func (c *Client) DeviceAdd(peerid, device string) (deviceapi.AddDeviceResp, error) { | ||
var peerinfo deviceapi.AddDeviceResp | ||
req := deviceapi.AddDeviceReq{ | ||
Device: device, | ||
} | ||
err := c.post("/v1/devices/"+peerid, req, http.StatusOK, &peerinfo) | ||
return peerinfo, err | ||
} | ||
|
||
// 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 | ||
} | ||
|
||
// DeviceEdit edits device | ||
func (c *Client) DeviceEdit(peerid, device, state string) error { | ||
req := deviceapi.EditDeviceReq{ | ||
State: state, | ||
} | ||
device = strings.TrimLeft(device, "/") | ||
url := fmt.Sprintf("/v1/devices/%s/%s", peerid, device) | ||
err := c.post(url, req, http.StatusOK, nil) | ||
return err | ||
} |
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
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.
if peerList len is zero fail the test case.
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.
I think this should be done in the test case of peerList and not in the edit-device.
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.
as this is dependent on the peer list, no harm in having one more higher level check