mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
Added the purge API on node endpoints
This commit is contained in:
@@ -276,6 +276,71 @@ func TestHTTP_NodeDrain(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestHTTP_NodePurge(t *testing.T) {
|
||||
t.Parallel()
|
||||
httpTest(t, nil, func(s *TestAgent) {
|
||||
// Create the node
|
||||
node := mock.Node()
|
||||
args := structs.NodeRegisterRequest{
|
||||
Node: node,
|
||||
WriteRequest: structs.WriteRequest{Region: "global"},
|
||||
}
|
||||
var resp structs.NodeUpdateResponse
|
||||
if err := s.Agent.RPC("Node.Register", &args, &resp); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Add some allocations to the node
|
||||
state := s.Agent.server.State()
|
||||
alloc1 := mock.Alloc()
|
||||
alloc1.NodeID = node.ID
|
||||
if err := state.UpsertJobSummary(999, mock.JobSummary(alloc1.JobID)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err := state.UpsertAllocs(1000, []*structs.Allocation{alloc1})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Make the HTTP request to purge it
|
||||
req, err := http.NewRequest("POST", "/v1/node/"+node.ID+"/purge", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
respW := httptest.NewRecorder()
|
||||
|
||||
// Make the request
|
||||
obj, err := s.Server.NodeSpecificRequest(respW, req)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Check for the index
|
||||
if respW.HeaderMap.Get("X-Nomad-Index") == "" {
|
||||
t.Fatalf("missing index")
|
||||
}
|
||||
|
||||
// Check the response
|
||||
upd := obj.(structs.NodeUpdateResponse)
|
||||
if len(upd.EvalIDs) == 0 {
|
||||
t.Fatalf("bad: %v", upd)
|
||||
}
|
||||
|
||||
// Ensure that the node is not present anymore
|
||||
args1 := structs.NodeSpecificRequest{
|
||||
NodeID: node.ID,
|
||||
QueryOptions: structs.QueryOptions{Region: "global"},
|
||||
}
|
||||
var resp1 structs.SingleNodeResponse
|
||||
if err := s.Agent.RPC("Node.GetNode", &args1, &resp1); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if resp1.Node != nil {
|
||||
t.Fatalf("node still exists after purging: %#v", resp1.Node)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestHTTP_NodeQuery(t *testing.T) {
|
||||
t.Parallel()
|
||||
httpTest(t, nil, func(s *TestAgent) {
|
||||
|
||||
Reference in New Issue
Block a user