mirror of
https://github.com/kemko/nomad.git
synced 2026-01-02 08:25:43 +03:00
alloc lifecycle: 404 when attempting to stop non-existent allocation
This commit is contained in:
@@ -119,8 +119,15 @@ func (s *HTTPServer) allocStop(allocID string, resp http.ResponseWriter, req *ht
|
||||
s.parseWriteRequest(req, &sr.WriteRequest)
|
||||
|
||||
var out structs.AllocStopResponse
|
||||
err := s.agent.RPC("Alloc.Stop", &sr, &out)
|
||||
return &out, err
|
||||
rpcErr := s.agent.RPC("Alloc.Stop", &sr, &out)
|
||||
|
||||
if rpcErr != nil {
|
||||
if structs.IsErrUnknownAllocation(rpcErr) {
|
||||
rpcErr = CodedError(404, allocNotFoundErr)
|
||||
}
|
||||
}
|
||||
|
||||
return &out, rpcErr
|
||||
}
|
||||
|
||||
func (s *HTTPServer) ClientAllocRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||
|
||||
@@ -424,17 +424,16 @@ func TestHTTP_AllocStop(t *testing.T) {
|
||||
// Test that we 404 when the allocid is invalid
|
||||
{
|
||||
// Make the HTTP request
|
||||
req, err := http.NewRequest("POST", "/v1/allocation/"+alloc.ID+"/stop", nil)
|
||||
req, err := http.NewRequest("POST", "/v1/allocation/"+uuid.Generate()+"/stop", nil)
|
||||
require.NoError(err)
|
||||
respW := httptest.NewRecorder()
|
||||
|
||||
// Make the request
|
||||
obj, err := s.Server.AllocSpecificRequest(respW, req)
|
||||
require.NoError(err)
|
||||
|
||||
a := obj.(*structs.AllocStopResponse)
|
||||
require.NotEmpty(a.EvalID, "missing eval")
|
||||
require.NotEmpty(a.Index, "missing index")
|
||||
_, err = s.Server.AllocSpecificRequest(respW, req)
|
||||
require.NotNil(err)
|
||||
if !strings.Contains(err.Error(), allocNotFoundErr) {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user