-
Notifications
You must be signed in to change notification settings - Fork 82
Conversation
4e15ee9
to
62ac746
Compare
@rishubhjain I have some questions related to device EDIT, 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? |
0a9af25
to
980b933
Compare
@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. |
What is the usecase for editing device name(what is device name?)? |
plugins/device/rest.go
Outdated
@@ -148,6 +148,12 @@ func deviceEditHandler(w http.ResponseWriter, r *http.Request) { | |||
return | |||
} | |||
|
|||
deviceName := r.URL.Query().Get("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.
any issues while using requestBody? why query param?
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? |
+1 |
plugins/device/rest.go
Outdated
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, "Device name not provided in URL") | ||
return | ||
} | ||
|
||
txn, err := transaction.NewTxnWithLocks(ctx, peerID) |
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.
lock peer + device before editing it, so it won't be considered for brick/volume creation during device edit.
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 will be taken up after #998
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.
lock peer+device similar to delete device
TODO list
|
eb5c3d5
to
1249790
Compare
@aravindavk @prashanthpai I have changed it to device instead of device name. |
plugins/device/rest.go
Outdated
@@ -151,6 +151,12 @@ func deviceEditHandler(w http.ResponseWriter, r *http.Request) { | |||
return | |||
} | |||
|
|||
device := r.URL.Query().Get("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.
Query parameters are mostly used for optional parameters. Please add device to URL itself or request body.
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.
Use as part of url itself
Fixes: #1283 |
@rishubhjain Ping! What's pending on this PR? |
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.
Also add Metadata adding support
plugins/device/init.go
Outdated
@@ -37,7 +37,7 @@ func (p *Plugin) RestRoutes() route.Routes { | |||
route.Route{ | |||
Name: "DeviceEdit", | |||
Method: "POST", | |||
Pattern: "/devices/{peerid}", | |||
Pattern: "/devices/{peerid}/edit", |
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.
/devices/edit/{peerid}/{device:.*}
plugins/device/rest.go
Outdated
@@ -151,6 +151,12 @@ func deviceEditHandler(w http.ResponseWriter, r *http.Request) { | |||
return | |||
} | |||
|
|||
device := r.URL.Query().Get("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.
Use as part of url itself
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.
Please add restclient function and add tests
plugins/device/rest.go
Outdated
@@ -151,6 +151,12 @@ func deviceEditHandler(w http.ResponseWriter, r *http.Request) { | |||
return | |||
} | |||
|
|||
device := mux.Vars(r)["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.
Move this before Unmarshal
plugins/device/rest.go
Outdated
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, "Device name not provided in URL") | ||
return | ||
} | ||
|
||
txn, err := transaction.NewTxnWithLocks(ctx, peerID) |
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.
lock peer+device similar to delete device
174ecbe
to
cfabd20
Compare
e2e/smartvol_ops_test.go
Outdated
} | ||
} | ||
|
||
if len(deviceList) > 0 { |
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.
testing with this condition is not good idea. Tests will pass if for some failure reason len(deviceList)
is zero.
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 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?
e2e/smartvol_ops_test.go
Outdated
err = client.DeviceEdit(peerID, device.Name, "disabled") | ||
r.Nil(err) | ||
} else if device.State == "disabled" { | ||
err = client.DeviceEdit(peerID, device.Name, "enabled") |
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 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.
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.
@aravindavk ^^
pkg/restclient/device.go
Outdated
} | ||
|
||
// DeviceEdit edits devices | ||
func (c *Client) DeviceEdit(peerid string, device string, state string) error { |
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.
(peerid string, device string, state string)
to (peerid, device, state string)
pkg/restclient/device.go
Outdated
return deviceList, err | ||
} | ||
|
||
// DeviceEdit edits devices |
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.
/devices to /device
plugins/device/rest.go
Outdated
return | ||
} | ||
|
||
if !strings.HasPrefix(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.
do we need this check? as part of URL, I don't think we will get devices with /
.
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.
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
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.
please test this scenario, I think //
will be converted into /
by HTTP framework,
7b13d3c
to
922f434
Compare
Please squash all commits into one. |
func editDevice(t *testing.T) { | ||
r := require.New(t) | ||
peerList, err := client.Peers() | ||
r.Nil(err) |
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
SubvolZonesOverlap: true, | ||
} | ||
_, err = client.VolumeCreate(createReq) | ||
r.NotNil(err) |
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.
enable the devices and create the volume, the volume creation should be successful.
922f434
to
bfa74cc
Compare
|
8cf80da
to
849d943
Compare
@rishubhjain PR is having conflicts, please resolve. |
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.
resolve conflicts
63219db
to
6bba9f0
Compare
retest this please |
1 similar comment
retest this please |
Getting device name from user in URL instead of request body during device edit.