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

Edit device #1118

Merged
merged 2 commits into from
Dec 5, 2018
Merged

Edit device #1118

merged 2 commits into from
Dec 5, 2018

Conversation

rishubhjain
Copy link
Contributor

Getting device name from user in URL instead of request body during device edit.

@Madhu-1
Copy link
Member

Madhu-1 commented Aug 3, 2018

@rishubhjain I have some questions related to device EDIT,
if the current device state and the requested device state doesn't match then we need to update device state

IMO if device state is already disabled we don't need to go and disable it again?

I think we are missing this check in device EDIT API can you confirm on this?

@rishubhjain rishubhjain force-pushed the edit_device branch 2 times, most recently from 0a9af25 to 980b933 Compare August 3, 2018 05:49
@rishubhjain
Copy link
Contributor Author

@prashanthpai @aravindavk If the current state of the device is same as the requested state, then I am returning without updating etcd instead of throwing an error.

@aravindavk
Copy link
Member

What is the usecase for editing device name(what is device name?)?

@@ -148,6 +148,12 @@ func deviceEditHandler(w http.ResponseWriter, r *http.Request) {
return
}

deviceName := r.URL.Query().Get("device")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any issues while using requestBody? why query param?

@Madhu-1
Copy link
Member

Madhu-1 commented Aug 6, 2018

why can't we return an error if device state is already set, currently if the volume is already started we are returning an error saying already started, why can't we follow the same approach here?
@rishubhjain @prashanthpai @aravindavk need your thought on this.

@prashanthpai
Copy link
Contributor

What is the usecase for editing device name(what is device name?)?

+1

restutils.SendHTTPError(ctx, w, http.StatusBadRequest, "Device name not provided in URL")
return
}

txn, err := transaction.NewTxnWithLocks(ctx, peerID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lock peer + device before editing it, so it won't be considered for brick/volume creation during device edit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be taken up after #998

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lock peer+device similar to delete device

@Madhu-1
Copy link
Member

Madhu-1 commented Aug 7, 2018

TODO list

  • CLI
  • rest API
  • e2e test cases
  • endpoint update

@rishubhjain
Copy link
Contributor Author

rishubhjain commented Aug 16, 2018

@aravindavk @prashanthpai I have changed it to device instead of device name.

@@ -151,6 +151,12 @@ func deviceEditHandler(w http.ResponseWriter, r *http.Request) {
return
}

device := r.URL.Query().Get("device")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query parameters are mostly used for optional parameters. Please add device to URL itself or request body.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use as part of url itself

@rishubhjain
Copy link
Contributor Author

Fixes: #1283

@atinmu
Copy link
Contributor

atinmu commented Nov 10, 2018

@rishubhjain Ping! What's pending on this PR?

Copy link
Member

@aravindavk aravindavk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add Metadata adding support

@@ -37,7 +37,7 @@ func (p *Plugin) RestRoutes() route.Routes {
route.Route{
Name: "DeviceEdit",
Method: "POST",
Pattern: "/devices/{peerid}",
Pattern: "/devices/{peerid}/edit",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/devices/edit/{peerid}/{device:.*}

@@ -151,6 +151,12 @@ func deviceEditHandler(w http.ResponseWriter, r *http.Request) {
return
}

device := r.URL.Query().Get("device")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use as part of url itself

@ghost ghost assigned rishubhjain Nov 29, 2018
@ghost ghost added the in progress label Nov 29, 2018
Copy link
Member

@aravindavk aravindavk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add restclient function and add tests

@@ -151,6 +151,12 @@ func deviceEditHandler(w http.ResponseWriter, r *http.Request) {
return
}

device := mux.Vars(r)["device"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this before Unmarshal

restutils.SendHTTPError(ctx, w, http.StatusBadRequest, "Device name not provided in URL")
return
}

txn, err := transaction.NewTxnWithLocks(ctx, peerID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lock peer+device similar to delete device

@rishubhjain rishubhjain force-pushed the edit_device branch 2 times, most recently from 174ecbe to cfabd20 Compare November 29, 2018 15:47
}
}

if len(deviceList) > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testing with this condition is not good idea. Tests will pass if for some failure reason len(deviceList) is zero.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as this is part of smart-volume test cases, we already have devices attached to the nodes, why can't we fail the test if there are not devices in attached to peers?

err = client.DeviceEdit(peerID, device.Name, "disabled")
r.Nil(err)
} else if device.State == "disabled" {
err = client.DeviceEdit(peerID, device.Name, "enabled")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see below-listed tests in this PR

  • Disable device and check devices state is disabled
  • when all devices are disabled, the volume creation should fail
  • Enable all the devices, and check devices is enabled
  • when all the devices are enabled, the volume creation should pass.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

// DeviceEdit edits devices
func (c *Client) DeviceEdit(peerid string, device string, state string) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(peerid string, device string, state string) to (peerid, device, state string)

return deviceList, err
}

// DeviceEdit edits devices
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/devices to /device

return
}

if !strings.HasPrefix(device, "/") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this check? as part of URL, I don't think we will get devices with /.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a possibility that user provides extra slashes /v1/devices/{peerid}//dev/vdb/, to be on the safer side we can check for a slash before adding another slash

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please test this scenario, I think // will be converted into / by HTTP framework,

@aravindavk
Copy link
Member

Please squash all commits into one.

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

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.

Copy link
Contributor Author

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.

Copy link
Member

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

SubvolZonesOverlap: true,
}
_, err = client.VolumeCreate(createReq)
r.NotNil(err)
Copy link
Member

Choose a reason for hiding this comment

The 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.

@Madhu-1
Copy link
Member

Madhu-1 commented Dec 3, 2018

09:02:32 --- FAIL: TestSmartVolume/Edit_device (0.07s)
09:02:32 require.go:765:
09:02:32 Error Trace: smartvol_ops_test.go:374
09:02:32 Error: Expected nil, but got: &errors.errorString{s:"volume not found"}
09:02:32 Test: TestSmartVolume/Edit_device
@rishubhjain CI failure

@rishubhjain rishubhjain force-pushed the edit_device branch 2 times, most recently from 8cf80da to 849d943 Compare December 4, 2018 08:27
@Madhu-1
Copy link
Member

Madhu-1 commented Dec 4, 2018

@rishubhjain PR is having conflicts, please resolve.

Copy link
Member

@Madhu-1 Madhu-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolve conflicts

@ghost ghost assigned aravindavk Dec 4, 2018
@rishubhjain
Copy link
Contributor Author

retest this please

1 similar comment
@aravindavk
Copy link
Member

retest this please

@aravindavk aravindavk merged commit 3d9707a into gluster:master Dec 5, 2018
@ghost ghost removed the in progress label Dec 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants