Merge pull request #3138 from hashicorp/b-status-length

Search handles prefix longer than allowed UUIDs
This commit is contained in:
Alex Dadgar 2017-08-30 13:32:33 -07:00 committed by GitHub
commit c1253619ef
3 changed files with 49 additions and 1 deletions

View File

@ -1,6 +1,7 @@
## 0.6.3 (Unreleased)
BUG FIXES:
* api: Search handles prefix longer than allowed UUIDs [GH-3138]
* api: Search endpoint handles even UUID prefixes with hyphens [GH-3120]
* cli: All status commands handle even UUID prefixes with hyphens [GH-3122]
* cli: Fix autocompletion of paths that include directories on zsh [GH-3129]

View File

@ -125,9 +125,13 @@ func (s *Search) PrefixSearch(args *structs.SearchRequest,
iter, err := getResourceIter(ctx, roundUUIDDownIfOdd(args.Prefix, args.Context), ws, state)
if err != nil {
e := err.Error()
switch {
// Searching other contexts with job names raises an error, which in
// this case we want to ignore.
if !strings.Contains(err.Error(), "Invalid UUID: encoding/hex") {
case strings.Contains(e, "Invalid UUID: encoding/hex"):
case strings.Contains(e, "UUID have 36 characters"):
default:
return err
}
} else {

View File

@ -2,6 +2,7 @@ package nomad
import (
"strconv"
"strings"
"testing"
msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc"
@ -97,6 +98,48 @@ func TestSearch_PrefixSearch_All_JobWithHyphen(t *testing.T) {
assert.EqualValues(jobIndex, resp.Index)
}
func TestSearch_PrefixSearch_All_LongJob(t *testing.T) {
assert := assert.New(t)
prefix := strings.Repeat("a", 100)
t.Parallel()
s := testServer(t, func(c *Config) {
c.NumSchedulers = 0
})
defer s.Shutdown()
codec := rpcClient(t, s)
testutil.WaitForLeader(t, s.RPC)
// Register a job and an allocation
jobID := registerAndVerifyJob(s, t, prefix, 0)
alloc := mock.Alloc()
alloc.JobID = jobID
summary := mock.JobSummary(alloc.JobID)
state := s.fsm.State()
if err := state.UpsertJobSummary(999, summary); err != nil {
t.Fatalf("err: %v", err)
}
if err := state.UpsertAllocs(1000, []*structs.Allocation{alloc}); err != nil {
t.Fatalf("err: %v", err)
}
req := &structs.SearchRequest{
Prefix: prefix,
Context: structs.All,
}
var resp structs.SearchResponse
if err := msgpackrpc.CallWithCodec(codec, "Search.PrefixSearch", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}
assert.Equal(1, len(resp.Matches[structs.Jobs]))
assert.Equal(jobID, resp.Matches[structs.Jobs][0])
assert.EqualValues(jobIndex, resp.Index)
}
// truncate should limit results to 20
func TestSearch_PrefixSearch_Truncate(t *testing.T) {
assert := assert.New(t)