Merge pull request #5960 from shvar/master

take NodeID from url in api for node eligibility
This commit is contained in:
Lang Martin 2019-07-16 16:09:12 -04:00 committed by GitHub
commit 47e725011f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -166,6 +166,10 @@ func (s *HTTPServer) nodeToggleEligibility(resp http.ResponseWriter, req *http.R
if err := decodeBody(req, &eligibilityRequest); err != nil {
return nil, CodedError(400, err.Error())
}
if eligibilityRequest.NodeID == "" {
eligibilityRequest.NodeID = nodeID
}
s.parseWriteRequest(req, &eligibilityRequest.WriteRequest)
var out structs.NodeEligibilityUpdateResponse

View File

@ -370,13 +370,12 @@ func TestHTTP_NodeEligible(t *testing.T) {
var resp structs.NodeUpdateResponse
require.Nil(s.Agent.RPC("Node.Register", &args, &resp))
drainReq := api.NodeUpdateEligibilityRequest{
NodeID: node.ID,
eligibilityReq := api.NodeUpdateEligibilityRequest{
Eligibility: structs.NodeSchedulingIneligible,
}
// Make the HTTP request
buf := encodeReq(drainReq)
buf := encodeReq(eligibilityReq)
req, err := http.NewRequest("POST", "/v1/node/"+node.ID+"/eligibility", buf)
require.Nil(err)
respW := httptest.NewRecorder()
@ -399,8 +398,8 @@ func TestHTTP_NodeEligible(t *testing.T) {
require.Equal(structs.NodeSchedulingIneligible, out.SchedulingEligibility)
// Make the HTTP request to set something invalid
drainReq.Eligibility = "foo"
buf = encodeReq(drainReq)
eligibilityReq.Eligibility = "foo"
buf = encodeReq(eligibilityReq)
req, err = http.NewRequest("POST", "/v1/node/"+node.ID+"/eligibility", buf)
require.Nil(err)
respW = httptest.NewRecorder()