|
|
@ -12,11 +12,11 @@ import (
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul-net-rpc/net/rpc"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
|
|
|
|
msgpackrpc "github.com/hashicorp/consul-net-rpc/net-rpc-msgpackrpc"
|
|
|
|
msgpackrpc "github.com/hashicorp/consul-net-rpc/net-rpc-msgpackrpc"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul-net-rpc/net/rpc"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/acl"
|
|
|
|
"github.com/hashicorp/consul/acl"
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
@ -3716,21 +3716,34 @@ func TestInternal_AssignManualServiceVIPs(t *testing.T) {
|
|
|
|
require.NoError(t, msgpackrpc.CallWithCodec(codec, "Internal.AssignManualServiceVIPs", req, &resp))
|
|
|
|
require.NoError(t, msgpackrpc.CallWithCodec(codec, "Internal.AssignManualServiceVIPs", req, &resp))
|
|
|
|
|
|
|
|
|
|
|
|
type testcase struct {
|
|
|
|
type testcase struct {
|
|
|
|
name string
|
|
|
|
name string
|
|
|
|
req structs.AssignServiceManualVIPsRequest
|
|
|
|
req structs.AssignServiceManualVIPsRequest
|
|
|
|
expect structs.AssignServiceManualVIPsResponse
|
|
|
|
expect structs.AssignServiceManualVIPsResponse
|
|
|
|
expectErr string
|
|
|
|
expectAgain structs.AssignServiceManualVIPsResponse
|
|
|
|
|
|
|
|
expectErr string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
run := func(t *testing.T, tc testcase) {
|
|
|
|
|
|
|
|
|
|
|
|
run := func(t *testing.T, tc testcase, again bool) {
|
|
|
|
|
|
|
|
if tc.expectErr != "" && again {
|
|
|
|
|
|
|
|
return // we don't retest known errors
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var resp structs.AssignServiceManualVIPsResponse
|
|
|
|
var resp structs.AssignServiceManualVIPsResponse
|
|
|
|
|
|
|
|
idx1 := s1.raft.CommitIndex()
|
|
|
|
err := msgpackrpc.CallWithCodec(codec, "Internal.AssignManualServiceVIPs", tc.req, &resp)
|
|
|
|
err := msgpackrpc.CallWithCodec(codec, "Internal.AssignManualServiceVIPs", tc.req, &resp)
|
|
|
|
|
|
|
|
idx2 := s1.raft.CommitIndex()
|
|
|
|
if tc.expectErr != "" {
|
|
|
|
if tc.expectErr != "" {
|
|
|
|
require.Error(t, err)
|
|
|
|
testutil.RequireErrorContains(t, err, tc.expectErr)
|
|
|
|
require.Contains(t, err.Error(), tc.expectErr)
|
|
|
|
} else {
|
|
|
|
return
|
|
|
|
if again {
|
|
|
|
|
|
|
|
require.Equal(t, tc.expectAgain, resp)
|
|
|
|
|
|
|
|
require.Equal(t, idx1, idx2, "no raft operations occurred")
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
require.Equal(t, tc.expect, resp)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require.Equal(t, tc.expect, resp)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tcs := []testcase{
|
|
|
|
tcs := []testcase{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name: "successful manual ip assignment",
|
|
|
|
name: "successful manual ip assignment",
|
|
|
@ -3738,7 +3751,8 @@ func TestInternal_AssignManualServiceVIPs(t *testing.T) {
|
|
|
|
Service: "web",
|
|
|
|
Service: "web",
|
|
|
|
ManualVIPs: []string{"1.1.1.1", "2.2.2.2"},
|
|
|
|
ManualVIPs: []string{"1.1.1.1", "2.2.2.2"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: structs.AssignServiceManualVIPsResponse{Found: true},
|
|
|
|
expect: structs.AssignServiceManualVIPsResponse{Found: true},
|
|
|
|
|
|
|
|
expectAgain: structs.AssignServiceManualVIPsResponse{Found: true},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name: "reassign existing ip",
|
|
|
|
name: "reassign existing ip",
|
|
|
@ -3754,6 +3768,8 @@ func TestInternal_AssignManualServiceVIPs(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// When we repeat this operation the second time it's a no-op.
|
|
|
|
|
|
|
|
expectAgain: structs.AssignServiceManualVIPsResponse{Found: true},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name: "invalid ip",
|
|
|
|
name: "invalid ip",
|
|
|
@ -3767,7 +3783,14 @@ func TestInternal_AssignManualServiceVIPs(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, tc := range tcs {
|
|
|
|
for _, tc := range tcs {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
run(t, tc)
|
|
|
|
t.Run("initial", func(t *testing.T) {
|
|
|
|
|
|
|
|
run(t, tc, false)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
if tc.expectErr == "" {
|
|
|
|
|
|
|
|
t.Run("repeat", func(t *testing.T) {
|
|
|
|
|
|
|
|
run(t, tc, true) // only repeat a write if it isn't an known error
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|