2022-07-08 17:01:13 +00:00
|
|
|
package peerstream
|
|
|
|
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
import (
|
2022-08-01 21:06:18 +00:00
|
|
|
"bytes"
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
"context"
|
2022-05-19 21:37:52 +00:00
|
|
|
"fmt"
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
"io"
|
2022-07-08 17:01:13 +00:00
|
|
|
"net"
|
2022-05-19 21:37:52 +00:00
|
|
|
"sort"
|
2022-07-08 17:01:13 +00:00
|
|
|
"sync"
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-08-01 21:06:18 +00:00
|
|
|
"github.com/golang/protobuf/proto"
|
2022-06-10 16:10:46 +00:00
|
|
|
"github.com/hashicorp/go-uuid"
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"google.golang.org/genproto/googleapis/rpc/code"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
2022-08-01 21:06:18 +00:00
|
|
|
newproto "google.golang.org/protobuf/proto"
|
2022-07-15 20:03:40 +00:00
|
|
|
"google.golang.org/protobuf/types/known/anypb"
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
|
2022-06-13 17:52:28 +00:00
|
|
|
"github.com/hashicorp/consul/acl"
|
2022-07-18 17:20:04 +00:00
|
|
|
"github.com/hashicorp/consul/agent/cache"
|
2022-05-25 17:37:44 +00:00
|
|
|
"github.com/hashicorp/consul/agent/connect"
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
"github.com/hashicorp/consul/agent/consul/state"
|
|
|
|
"github.com/hashicorp/consul/agent/consul/stream"
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2022-06-21 18:04:08 +00:00
|
|
|
"github.com/hashicorp/consul/lib"
|
2022-08-01 21:06:18 +00:00
|
|
|
"github.com/hashicorp/consul/logging"
|
2022-06-13 17:52:28 +00:00
|
|
|
"github.com/hashicorp/consul/proto/pbcommon"
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
"github.com/hashicorp/consul/proto/pbpeering"
|
2022-07-08 17:01:13 +00:00
|
|
|
"github.com/hashicorp/consul/proto/pbpeerstream"
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
"github.com/hashicorp/consul/proto/pbservice"
|
|
|
|
"github.com/hashicorp/consul/proto/pbstatus"
|
|
|
|
"github.com/hashicorp/consul/proto/prototest"
|
2022-07-08 17:01:13 +00:00
|
|
|
"github.com/hashicorp/consul/sdk/freeport"
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
"github.com/hashicorp/consul/sdk/testutil"
|
|
|
|
"github.com/hashicorp/consul/sdk/testutil/retry"
|
2022-06-13 17:52:28 +00:00
|
|
|
"github.com/hashicorp/consul/types"
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
)
|
|
|
|
|
2022-08-01 14:33:18 +00:00
|
|
|
const (
|
|
|
|
testPeerID = "caf067a6-f112-4907-9101-d45857d2b149"
|
|
|
|
testPendingStreamSecretID = "522c0daf-2ef2-4dab-bc78-5e04e3daf552"
|
|
|
|
testEstablishmentSecretID = "f6569d37-1c5b-4415-aae5-26f4594f7f60"
|
|
|
|
)
|
|
|
|
|
2022-05-23 18:30:58 +00:00
|
|
|
func TestStreamResources_Server_Follower(t *testing.T) {
|
2022-07-08 17:01:13 +00:00
|
|
|
srv, _ := newTestServer(t, func(c *Config) {
|
|
|
|
backend := c.Backend.(*testStreamBackend)
|
|
|
|
backend.leader = func() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
backend.leaderAddr = "expected:address"
|
|
|
|
})
|
2022-05-23 18:30:58 +00:00
|
|
|
|
|
|
|
client := NewMockClient(context.Background())
|
|
|
|
|
|
|
|
errCh := make(chan error, 1)
|
|
|
|
client.ErrCh = errCh
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
// Pass errors from server handler into ErrCh so that they can be seen by the client on Recv().
|
|
|
|
// This matches gRPC's behavior when an error is returned by a server.
|
|
|
|
err := srv.StreamResources(client.ReplicationStream)
|
|
|
|
if err != nil {
|
|
|
|
errCh <- err
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2022-06-06 17:00:38 +00:00
|
|
|
// expect error
|
2022-05-23 18:30:58 +00:00
|
|
|
msg, err := client.Recv()
|
|
|
|
require.Nil(t, msg)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.EqualError(t, err, "rpc error: code = FailedPrecondition desc = cannot establish a peering stream on a follower node")
|
2022-06-06 17:00:38 +00:00
|
|
|
|
|
|
|
// expect a status error
|
|
|
|
st, ok := status.FromError(err)
|
|
|
|
require.True(t, ok, "need to get back a grpc status error")
|
|
|
|
deets := st.Details()
|
|
|
|
|
|
|
|
// expect a LeaderAddress message
|
2022-07-08 17:01:13 +00:00
|
|
|
exp := []interface{}{&pbpeerstream.LeaderAddress{Address: "expected:address"}}
|
2022-06-06 17:00:38 +00:00
|
|
|
prototest.AssertDeepEqual(t, exp, deets)
|
2022-05-23 18:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestStreamResources_Server_LeaderBecomesFollower simulates a srv that is a leader when the
|
|
|
|
// subscription request is sent but loses leadership status for subsequent messages.
|
|
|
|
func TestStreamResources_Server_LeaderBecomesFollower(t *testing.T) {
|
2022-07-08 17:01:13 +00:00
|
|
|
srv, store := newTestServer(t, func(c *Config) {
|
|
|
|
backend := c.Backend.(*testStreamBackend)
|
|
|
|
|
|
|
|
first := true
|
|
|
|
backend.leader = func() bool {
|
|
|
|
if first {
|
|
|
|
first = false
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
2022-05-23 18:30:58 +00:00
|
|
|
}
|
2022-05-25 17:37:44 +00:00
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
backend.leaderAddr = "expected:address"
|
|
|
|
})
|
2022-05-23 18:30:58 +00:00
|
|
|
|
2022-07-15 20:03:40 +00:00
|
|
|
p := writePeeringToBeDialed(t, store, 1, "my-peer")
|
|
|
|
require.Empty(t, p.PeerID, "should be empty if being dialed")
|
|
|
|
|
|
|
|
// Set the initial roots and CA configuration.
|
|
|
|
_, _ = writeInitialRootsAndCA(t, store)
|
|
|
|
|
2022-05-23 18:30:58 +00:00
|
|
|
client := NewMockClient(context.Background())
|
|
|
|
|
|
|
|
errCh := make(chan error, 1)
|
|
|
|
client.ErrCh = errCh
|
|
|
|
|
|
|
|
go func() {
|
2022-07-15 20:03:40 +00:00
|
|
|
// Pass errors from server handler into ErrCh so that they can be seen by the client on Recv().
|
|
|
|
// This matches gRPC's behavior when an error is returned by a server.
|
|
|
|
if err := srv.StreamResources(client.ReplicationStream); err != nil {
|
2022-05-23 18:30:58 +00:00
|
|
|
errCh <- err
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2022-07-15 20:03:40 +00:00
|
|
|
// Receive a subscription from a peer. This message arrives while the
|
|
|
|
// server is a leader and should work.
|
2022-09-29 19:37:19 +00:00
|
|
|
testutil.RunStep(t, "send subscription request to leader and consume its four requests", func(t *testing.T) {
|
2022-07-15 20:03:40 +00:00
|
|
|
sub := &pbpeerstream.ReplicationMessage{
|
2022-08-01 14:33:18 +00:00
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Open_{
|
|
|
|
Open: &pbpeerstream.ReplicationMessage_Open{
|
|
|
|
PeerID: testPeerID,
|
|
|
|
StreamSecretID: testPendingStreamSecretID,
|
2022-07-15 20:03:40 +00:00
|
|
|
},
|
2022-05-23 18:30:58 +00:00
|
|
|
},
|
2022-07-15 20:03:40 +00:00
|
|
|
}
|
|
|
|
err := client.Send(sub)
|
|
|
|
require.NoError(t, err)
|
2022-05-23 18:30:58 +00:00
|
|
|
|
2022-07-15 20:03:40 +00:00
|
|
|
msg1, err := client.Recv()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, msg1)
|
2022-05-23 18:30:58 +00:00
|
|
|
|
2022-07-15 20:03:40 +00:00
|
|
|
msg2, err := client.Recv()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, msg2)
|
2022-08-22 14:22:11 +00:00
|
|
|
|
|
|
|
msg3, err := client.Recv()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, msg3)
|
2022-09-29 19:37:19 +00:00
|
|
|
|
|
|
|
msg4, err := client.Recv()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, msg4)
|
2022-07-15 20:03:40 +00:00
|
|
|
})
|
2022-05-26 19:24:09 +00:00
|
|
|
|
2022-07-15 20:03:40 +00:00
|
|
|
// The ACK will be a new request but at this point the server is not the
|
|
|
|
// leader in the test and this should fail.
|
|
|
|
testutil.RunStep(t, "ack fails with non leader", func(t *testing.T) {
|
|
|
|
ack := &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Request_{
|
|
|
|
Request: &pbpeerstream.ReplicationMessage_Request{
|
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
|
|
|
ResponseNonce: "1",
|
|
|
|
},
|
2022-05-23 18:30:58 +00:00
|
|
|
},
|
2022-07-15 20:03:40 +00:00
|
|
|
}
|
2022-05-23 18:30:58 +00:00
|
|
|
|
2022-07-15 20:03:40 +00:00
|
|
|
err := client.Send(ack)
|
|
|
|
require.NoError(t, err)
|
2022-05-23 18:30:58 +00:00
|
|
|
|
2022-07-15 20:03:40 +00:00
|
|
|
// expect error
|
|
|
|
msg, err := client.Recv()
|
|
|
|
require.Nil(t, msg)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.EqualError(t, err, "rpc error: code = FailedPrecondition desc = node is not a leader anymore; cannot continue streaming")
|
2022-06-06 17:00:38 +00:00
|
|
|
|
2022-07-15 20:03:40 +00:00
|
|
|
// expect a status error
|
|
|
|
st, ok := status.FromError(err)
|
|
|
|
require.True(t, ok, "need to get back a grpc status error")
|
2022-06-06 17:00:38 +00:00
|
|
|
|
2022-07-15 20:03:40 +00:00
|
|
|
// expect a LeaderAddress message
|
|
|
|
expect := []interface{}{
|
|
|
|
&pbpeerstream.LeaderAddress{Address: "expected:address"},
|
|
|
|
}
|
|
|
|
prototest.AssertDeepEqual(t, expect, st.Details())
|
|
|
|
})
|
2022-05-23 18:30:58 +00:00
|
|
|
}
|
|
|
|
|
2022-08-01 14:33:18 +00:00
|
|
|
func TestStreamResources_Server_ActiveSecretValidation(t *testing.T) {
|
2022-08-08 07:41:00 +00:00
|
|
|
type testSeed struct {
|
|
|
|
peering *pbpeering.Peering
|
|
|
|
secrets []*pbpeering.SecretsWriteRequest
|
|
|
|
}
|
2022-08-01 14:33:18 +00:00
|
|
|
type testCase struct {
|
|
|
|
name string
|
2022-08-08 07:41:00 +00:00
|
|
|
seed *testSeed
|
2022-08-01 14:33:18 +00:00
|
|
|
input *pbpeerstream.ReplicationMessage
|
|
|
|
wantErr error
|
|
|
|
}
|
|
|
|
|
|
|
|
peeringWithoutSecrets := "35bf39d2-836c-4f66-945f-85f20b17c3db"
|
|
|
|
|
|
|
|
run := func(t *testing.T, tc testCase) {
|
|
|
|
srv, store := newTestServer(t, nil)
|
|
|
|
|
|
|
|
// Write a seed peering.
|
2022-08-08 07:41:00 +00:00
|
|
|
if tc.seed != nil {
|
|
|
|
require.NoError(t, store.PeeringWrite(1, &pbpeering.PeeringWriteRequest{Peering: tc.seed.peering}))
|
|
|
|
|
|
|
|
for _, s := range tc.seed.secrets {
|
|
|
|
require.NoError(t, store.PeeringSecretsWrite(1, s))
|
|
|
|
}
|
|
|
|
}
|
2022-08-01 14:33:18 +00:00
|
|
|
|
|
|
|
// Set the initial roots and CA configuration.
|
|
|
|
_, _ = writeInitialRootsAndCA(t, store)
|
|
|
|
|
|
|
|
client := NewMockClient(context.Background())
|
|
|
|
|
|
|
|
errCh := make(chan error, 1)
|
|
|
|
client.ErrCh = errCh
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
// Pass errors from server handler into ErrCh so that they can be seen by the client on Recv().
|
|
|
|
// This matches gRPC's behavior when an error is returned by a server.
|
|
|
|
err := srv.StreamResources(client.ReplicationStream)
|
|
|
|
if err != nil {
|
|
|
|
errCh <- err
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
err := client.Send(tc.input)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = client.Recv()
|
|
|
|
if tc.wantErr != nil {
|
|
|
|
require.Error(t, err)
|
|
|
|
require.EqualError(t, err, tc.wantErr.Error())
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
2022-08-08 07:41:00 +00:00
|
|
|
|
|
|
|
client.Close()
|
2022-08-01 14:33:18 +00:00
|
|
|
}
|
|
|
|
tt := []testCase{
|
|
|
|
{
|
|
|
|
name: "no secret for peering",
|
2022-08-08 07:41:00 +00:00
|
|
|
seed: &testSeed{
|
|
|
|
peering: &pbpeering.Peering{
|
2022-08-01 14:33:18 +00:00
|
|
|
Name: "foo",
|
|
|
|
ID: peeringWithoutSecrets,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
input: &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Open_{
|
|
|
|
Open: &pbpeerstream.ReplicationMessage_Open{
|
|
|
|
PeerID: peeringWithoutSecrets,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: status.Error(codes.Internal, "unable to authorize connection, peering must be re-established"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown secret",
|
2022-08-08 07:41:00 +00:00
|
|
|
seed: &testSeed{
|
|
|
|
peering: &pbpeering.Peering{
|
2022-08-01 14:33:18 +00:00
|
|
|
Name: "foo",
|
|
|
|
ID: testPeerID,
|
|
|
|
},
|
2022-08-08 07:41:00 +00:00
|
|
|
secrets: []*pbpeering.SecretsWriteRequest{
|
|
|
|
{
|
2022-08-02 22:20:07 +00:00
|
|
|
PeerID: testPeerID,
|
2022-08-08 07:41:00 +00:00
|
|
|
Request: &pbpeering.SecretsWriteRequest_GenerateToken{
|
|
|
|
GenerateToken: &pbpeering.SecretsWriteRequest_GenerateTokenRequest{
|
|
|
|
EstablishmentSecret: testEstablishmentSecretID,
|
|
|
|
},
|
2022-08-02 22:20:07 +00:00
|
|
|
},
|
2022-08-01 14:33:18 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
input: &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Open_{
|
|
|
|
Open: &pbpeerstream.ReplicationMessage_Open{
|
|
|
|
PeerID: testPeerID,
|
|
|
|
StreamSecretID: "unknown-secret",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: status.Error(codes.PermissionDenied, "invalid peering stream secret"),
|
|
|
|
},
|
|
|
|
{
|
2022-08-08 07:41:00 +00:00
|
|
|
name: "known pending secret",
|
|
|
|
seed: &testSeed{
|
|
|
|
peering: &pbpeering.Peering{
|
2022-08-01 14:33:18 +00:00
|
|
|
Name: "foo",
|
|
|
|
ID: testPeerID,
|
|
|
|
},
|
2022-08-08 07:41:00 +00:00
|
|
|
secrets: []*pbpeering.SecretsWriteRequest{
|
|
|
|
{
|
2022-08-02 22:20:07 +00:00
|
|
|
PeerID: testPeerID,
|
2022-08-08 07:41:00 +00:00
|
|
|
Request: &pbpeering.SecretsWriteRequest_GenerateToken{
|
|
|
|
GenerateToken: &pbpeering.SecretsWriteRequest_GenerateTokenRequest{
|
|
|
|
EstablishmentSecret: testEstablishmentSecretID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
PeerID: testPeerID,
|
|
|
|
Request: &pbpeering.SecretsWriteRequest_ExchangeSecret{
|
|
|
|
ExchangeSecret: &pbpeering.SecretsWriteRequest_ExchangeSecretRequest{
|
2022-08-08 15:06:07 +00:00
|
|
|
EstablishmentSecret: testEstablishmentSecretID,
|
2022-08-08 07:41:00 +00:00
|
|
|
PendingStreamSecret: testPendingStreamSecretID,
|
|
|
|
},
|
2022-08-02 22:20:07 +00:00
|
|
|
},
|
2022-08-01 14:33:18 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
input: &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Open_{
|
|
|
|
Open: &pbpeerstream.ReplicationMessage_Open{
|
|
|
|
PeerID: testPeerID,
|
2022-08-08 07:41:00 +00:00
|
|
|
StreamSecretID: testPendingStreamSecretID,
|
2022-08-01 14:33:18 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-08-08 07:41:00 +00:00
|
|
|
name: "known active secret",
|
|
|
|
seed: &testSeed{
|
|
|
|
peering: &pbpeering.Peering{
|
2022-08-01 14:33:18 +00:00
|
|
|
Name: "foo",
|
|
|
|
ID: testPeerID,
|
|
|
|
},
|
2022-08-08 07:41:00 +00:00
|
|
|
secrets: []*pbpeering.SecretsWriteRequest{
|
|
|
|
{
|
|
|
|
PeerID: testPeerID,
|
|
|
|
Request: &pbpeering.SecretsWriteRequest_GenerateToken{
|
|
|
|
GenerateToken: &pbpeering.SecretsWriteRequest_GenerateTokenRequest{
|
|
|
|
EstablishmentSecret: testEstablishmentSecretID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-08-02 22:20:07 +00:00
|
|
|
PeerID: testPeerID,
|
2022-08-08 07:41:00 +00:00
|
|
|
Request: &pbpeering.SecretsWriteRequest_ExchangeSecret{
|
|
|
|
ExchangeSecret: &pbpeering.SecretsWriteRequest_ExchangeSecretRequest{
|
2022-08-08 15:06:07 +00:00
|
|
|
EstablishmentSecret: testEstablishmentSecretID,
|
2022-08-08 07:41:00 +00:00
|
|
|
PendingStreamSecret: testPendingStreamSecretID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
PeerID: testPeerID,
|
|
|
|
Request: &pbpeering.SecretsWriteRequest_PromotePending{
|
|
|
|
PromotePending: &pbpeering.SecretsWriteRequest_PromotePendingRequest{
|
|
|
|
// Pending gets promoted to active.
|
|
|
|
ActiveStreamSecret: testPendingStreamSecretID,
|
|
|
|
},
|
2022-08-02 22:20:07 +00:00
|
|
|
},
|
2022-08-01 14:33:18 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
input: &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Open_{
|
|
|
|
Open: &pbpeerstream.ReplicationMessage_Open{
|
|
|
|
PeerID: testPeerID,
|
|
|
|
StreamSecretID: testPendingStreamSecretID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range tt {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
run(t, tc)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStreamResources_Server_PendingSecretPromotion(t *testing.T) {
|
|
|
|
srv, store := newTestServer(t, nil)
|
|
|
|
_ = writePeeringToBeDialed(t, store, 1, "my-peer")
|
|
|
|
|
|
|
|
client := NewMockClient(context.Background())
|
|
|
|
|
|
|
|
errCh := make(chan error, 1)
|
|
|
|
client.ErrCh = errCh
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
// Pass errors from server handler into ErrCh so that they can be seen by the client on Recv().
|
|
|
|
// This matches gRPC's behavior when an error is returned by a server.
|
|
|
|
err := srv.StreamResources(client.ReplicationStream)
|
|
|
|
if err != nil {
|
|
|
|
errCh <- err
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
err := client.Send(&pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Open_{
|
|
|
|
Open: &pbpeerstream.ReplicationMessage_Open{
|
|
|
|
PeerID: testPeerID,
|
|
|
|
StreamSecretID: testPendingStreamSecretID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
retry.Run(t, func(r *retry.R) {
|
|
|
|
// Upon presenting a known pending secret ID, it should be promoted to active.
|
|
|
|
secrets, err := store.PeeringSecretsRead(nil, testPeerID)
|
|
|
|
require.NoError(r, err)
|
|
|
|
require.Empty(r, secrets.GetStream().GetPendingSecretID())
|
|
|
|
require.Equal(r, testPendingStreamSecretID, secrets.GetStream().GetActiveSecretID())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
func TestStreamResources_Server_FirstRequest(t *testing.T) {
|
|
|
|
type testCase struct {
|
|
|
|
name string
|
2022-07-08 17:01:13 +00:00
|
|
|
input *pbpeerstream.ReplicationMessage
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
wantErr error
|
|
|
|
}
|
|
|
|
|
|
|
|
run := func(t *testing.T, tc testCase) {
|
2022-07-08 17:01:13 +00:00
|
|
|
srv, _ := newTestServer(t, nil)
|
2022-05-12 21:04:44 +00:00
|
|
|
|
|
|
|
client := NewMockClient(context.Background())
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
|
|
|
|
errCh := make(chan error, 1)
|
2022-05-12 21:04:44 +00:00
|
|
|
client.ErrCh = errCh
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
|
|
|
|
go func() {
|
2022-05-12 21:04:44 +00:00
|
|
|
// Pass errors from server handler into ErrCh so that they can be seen by the client on Recv().
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
// This matches gRPC's behavior when an error is returned by a server.
|
2022-05-12 21:04:44 +00:00
|
|
|
err := srv.StreamResources(client.ReplicationStream)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
if err != nil {
|
|
|
|
errCh <- err
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
err := client.Send(tc.input)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
msg, err := client.Recv()
|
|
|
|
require.Nil(t, msg)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.EqualError(t, err, tc.wantErr.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
tt := []testCase{
|
|
|
|
{
|
|
|
|
name: "unexpected response",
|
2022-07-08 17:01:13 +00:00
|
|
|
input: &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Response_{
|
|
|
|
Response: &pbpeerstream.ReplicationMessage_Response{
|
2022-07-15 20:03:40 +00:00
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
ResourceID: "api-service",
|
|
|
|
Nonce: "2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-08-01 14:33:18 +00:00
|
|
|
wantErr: status.Error(codes.InvalidArgument, "first message when initiating a peering must be: Open"),
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
|
|
|
{
|
2022-08-01 14:33:18 +00:00
|
|
|
name: "unexpected request",
|
2022-07-08 17:01:13 +00:00
|
|
|
input: &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Request_{
|
|
|
|
Request: &pbpeerstream.ReplicationMessage_Request{
|
2022-08-01 14:33:18 +00:00
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-08-01 14:33:18 +00:00
|
|
|
wantErr: status.Error(codes.InvalidArgument, "first message when initiating a peering must be: Open"),
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
|
|
|
{
|
2022-08-01 14:33:18 +00:00
|
|
|
name: "missing peer id",
|
2022-07-08 17:01:13 +00:00
|
|
|
input: &pbpeerstream.ReplicationMessage{
|
2022-08-01 14:33:18 +00:00
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Open_{
|
|
|
|
Open: &pbpeerstream.ReplicationMessage_Open{},
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
|
|
|
},
|
2022-08-01 14:33:18 +00:00
|
|
|
wantErr: status.Error(codes.InvalidArgument, "initial subscription request must specify a PeerID"),
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
2022-05-12 21:04:44 +00:00
|
|
|
{
|
|
|
|
name: "unknown peer",
|
2022-07-08 17:01:13 +00:00
|
|
|
input: &pbpeerstream.ReplicationMessage{
|
2022-08-01 14:33:18 +00:00
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Open_{
|
|
|
|
Open: &pbpeerstream.ReplicationMessage_Open{
|
|
|
|
PeerID: "63b60245-c475-426b-b314-4588d210859d",
|
2022-05-12 21:04:44 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: status.Error(codes.InvalidArgument, "initial subscription for unknown PeerID: 63b60245-c475-426b-b314-4588d210859d"),
|
|
|
|
},
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
}
|
|
|
|
for _, tc := range tt {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
run(t, tc)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStreamResources_Server_Terminate(t *testing.T) {
|
|
|
|
it := incrementalTime{
|
|
|
|
base: time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC),
|
|
|
|
}
|
2022-07-08 17:01:13 +00:00
|
|
|
|
2022-08-29 20:32:26 +00:00
|
|
|
srv, store := newTestServer(t, nil)
|
|
|
|
srv.Tracker.setClock(it.Now)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
|
2022-07-13 15:00:35 +00:00
|
|
|
p := writePeeringToBeDialed(t, store, 1, "my-peer")
|
|
|
|
require.Empty(t, p.PeerID, "should be empty if being dialed")
|
2022-05-12 21:04:44 +00:00
|
|
|
|
2022-05-25 17:37:44 +00:00
|
|
|
// Set the initial roots and CA configuration.
|
2022-05-26 19:24:09 +00:00
|
|
|
_, _ = writeInitialRootsAndCA(t, store)
|
2022-05-25 17:37:44 +00:00
|
|
|
|
2022-08-01 14:33:18 +00:00
|
|
|
client := makeClient(t, srv, testPeerID)
|
2022-05-26 19:24:09 +00:00
|
|
|
|
2022-09-29 19:37:19 +00:00
|
|
|
client.DrainStream(t)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
|
2022-05-10 20:25:51 +00:00
|
|
|
testutil.RunStep(t, "new stream gets tracked", func(t *testing.T) {
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
retry.Run(t, func(r *retry.R) {
|
2022-08-01 14:33:18 +00:00
|
|
|
status, ok := srv.StreamStatus(testPeerID)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
require.True(r, ok)
|
|
|
|
require.True(r, status.Connected)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-05-10 20:25:51 +00:00
|
|
|
testutil.RunStep(t, "terminate the stream", func(t *testing.T) {
|
2022-08-01 14:33:18 +00:00
|
|
|
done := srv.ConnectedStreams()[testPeerID]
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
close(done)
|
|
|
|
|
|
|
|
retry.Run(t, func(r *retry.R) {
|
2022-08-01 14:33:18 +00:00
|
|
|
_, ok := srv.StreamStatus(testPeerID)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
require.False(r, ok)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
receivedTerm, err := client.Recv()
|
|
|
|
require.NoError(t, err)
|
2022-07-08 17:01:13 +00:00
|
|
|
expect := &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Terminated_{
|
|
|
|
Terminated: &pbpeerstream.ReplicationMessage_Terminated{},
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
prototest.AssertDeepEqual(t, expect, receivedTerm)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStreamResources_Server_StreamTracker(t *testing.T) {
|
|
|
|
it := incrementalTime{
|
|
|
|
base: time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC),
|
|
|
|
}
|
2022-07-08 17:01:13 +00:00
|
|
|
|
2022-08-29 20:32:26 +00:00
|
|
|
srv, store := newTestServer(t, nil)
|
|
|
|
srv.Tracker.setClock(it.Now)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
|
2022-05-26 19:24:09 +00:00
|
|
|
// Set the initial roots and CA configuration.
|
2022-09-29 19:37:19 +00:00
|
|
|
writeInitialRootsAndCA(t, store)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
|
2022-07-13 15:00:35 +00:00
|
|
|
p := writePeeringToBeDialed(t, store, 1, "my-peer")
|
|
|
|
require.Empty(t, p.PeerID, "should be empty if being dialed")
|
2022-05-12 21:04:44 +00:00
|
|
|
|
2022-08-01 14:33:18 +00:00
|
|
|
client := makeClient(t, srv, testPeerID)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
|
2022-05-10 20:25:51 +00:00
|
|
|
testutil.RunStep(t, "new stream gets tracked", func(t *testing.T) {
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
retry.Run(t, func(r *retry.R) {
|
2022-08-01 14:33:18 +00:00
|
|
|
status, ok := srv.StreamStatus(testPeerID)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
require.True(r, ok)
|
|
|
|
require.True(r, status.Connected)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-08-26 20:49:03 +00:00
|
|
|
var lastSendAck time.Time
|
2022-10-10 19:18:08 +00:00
|
|
|
var lastSendSuccess time.Time
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
|
2022-09-29 19:37:19 +00:00
|
|
|
client.DrainStream(t)
|
|
|
|
|
2022-10-10 19:18:08 +00:00
|
|
|
// Manually grab the last success time from sending the trust bundle or exported services list.
|
|
|
|
status, ok := srv.StreamStatus(testPeerID)
|
|
|
|
require.True(t, ok)
|
|
|
|
lastSendSuccess = status.LastSendSuccess
|
|
|
|
|
2022-05-10 20:25:51 +00:00
|
|
|
testutil.RunStep(t, "ack tracked as success", func(t *testing.T) {
|
2022-07-08 17:01:13 +00:00
|
|
|
ack := &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Request_{
|
|
|
|
Request: &pbpeerstream.ReplicationMessage_Request{
|
2022-08-01 14:33:18 +00:00
|
|
|
PeerID: testPeerID,
|
2022-07-15 20:03:40 +00:00
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
2022-07-13 15:00:35 +00:00
|
|
|
ResponseNonce: "1",
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
|
|
|
|
// Acks do not have an Error populated in the request
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-07-15 20:03:40 +00:00
|
|
|
|
2022-08-26 20:49:03 +00:00
|
|
|
lastSendAck = it.FutureNow(1)
|
2022-10-10 19:18:08 +00:00
|
|
|
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
err := client.Send(ack)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
expect := Status{
|
2022-09-29 19:37:19 +00:00
|
|
|
Connected: true,
|
2022-10-10 19:18:08 +00:00
|
|
|
LastSendSuccess: lastSendSuccess,
|
2022-09-29 19:37:19 +00:00
|
|
|
LastAck: lastSendAck,
|
|
|
|
ExportedServices: []string{},
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
retry.Run(t, func(r *retry.R) {
|
2022-08-25 23:32:59 +00:00
|
|
|
rStatus, ok := srv.StreamStatus(testPeerID)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
require.True(r, ok)
|
2022-08-25 23:32:59 +00:00
|
|
|
require.Equal(r, expect, rStatus)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
var lastNack time.Time
|
|
|
|
var lastNackMsg string
|
|
|
|
|
2022-05-10 20:25:51 +00:00
|
|
|
testutil.RunStep(t, "nack tracked as error", func(t *testing.T) {
|
2022-07-08 17:01:13 +00:00
|
|
|
nack := &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Request_{
|
|
|
|
Request: &pbpeerstream.ReplicationMessage_Request{
|
2022-08-01 14:33:18 +00:00
|
|
|
PeerID: testPeerID,
|
2022-07-15 20:03:40 +00:00
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
2022-07-13 15:00:35 +00:00
|
|
|
ResponseNonce: "2",
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
Error: &pbstatus.Status{
|
|
|
|
Code: int32(code.Code_UNAVAILABLE),
|
|
|
|
Message: "bad bad not good",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-07-15 20:03:40 +00:00
|
|
|
|
2022-08-26 20:49:03 +00:00
|
|
|
lastNack = it.FutureNow(1)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
err := client.Send(nack)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
lastNackMsg = "client peer was unable to apply resource: bad bad not good"
|
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
expect := Status{
|
2022-09-29 19:37:19 +00:00
|
|
|
Connected: true,
|
2022-10-10 19:18:08 +00:00
|
|
|
LastSendSuccess: lastSendSuccess,
|
2022-09-29 19:37:19 +00:00
|
|
|
LastAck: lastSendAck,
|
|
|
|
LastNack: lastNack,
|
|
|
|
LastNackMessage: lastNackMsg,
|
|
|
|
ExportedServices: []string{},
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
retry.Run(t, func(r *retry.R) {
|
2022-08-25 23:32:59 +00:00
|
|
|
rStatus, ok := srv.StreamStatus(testPeerID)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
require.True(r, ok)
|
2022-08-25 23:32:59 +00:00
|
|
|
require.Equal(r, expect, rStatus)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-07-25 21:27:53 +00:00
|
|
|
var lastRecvResourceSuccess time.Time
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
|
2022-05-10 20:25:51 +00:00
|
|
|
testutil.RunStep(t, "response applied locally", func(t *testing.T) {
|
2022-07-08 17:01:13 +00:00
|
|
|
resp := &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Response_{
|
|
|
|
Response: &pbpeerstream.ReplicationMessage_Response{
|
2022-07-15 20:03:40 +00:00
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
ResourceID: "api",
|
|
|
|
Nonce: "21",
|
2022-07-08 17:01:13 +00:00
|
|
|
Operation: pbpeerstream.Operation_OPERATION_UPSERT,
|
2022-07-15 20:03:40 +00:00
|
|
|
Resource: makeAnyPB(t, &pbpeerstream.ExportedService{}),
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-07-25 21:27:53 +00:00
|
|
|
lastRecvResourceSuccess = it.FutureNow(1)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
err := client.Send(resp)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
expectAck := &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Request_{
|
|
|
|
Request: &pbpeerstream.ReplicationMessage_Request{
|
2022-07-15 20:03:40 +00:00
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
2022-07-13 15:00:35 +00:00
|
|
|
ResponseNonce: "21",
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-09-29 19:37:19 +00:00
|
|
|
retry.Run(t, func(r *retry.R) {
|
|
|
|
msg, err := client.Recv()
|
|
|
|
require.NoError(r, err)
|
|
|
|
req := msg.GetRequest()
|
|
|
|
require.NotNil(r, req)
|
|
|
|
require.Equal(r, pbpeerstream.TypeURLExportedService, req.ResourceURL)
|
|
|
|
prototest.AssertDeepEqual(t, expectAck, msg)
|
|
|
|
})
|
2022-07-15 19:43:24 +00:00
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
expect := Status{
|
2022-07-25 23:08:03 +00:00
|
|
|
Connected: true,
|
2022-10-10 19:18:08 +00:00
|
|
|
LastSendSuccess: lastSendSuccess,
|
2022-08-25 23:32:59 +00:00
|
|
|
LastAck: lastSendAck,
|
2022-07-25 23:08:03 +00:00
|
|
|
LastNack: lastNack,
|
|
|
|
LastNackMessage: lastNackMsg,
|
|
|
|
LastRecvResourceSuccess: lastRecvResourceSuccess,
|
2022-09-29 19:37:19 +00:00
|
|
|
ExportedServices: []string{},
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
retry.Run(t, func(r *retry.R) {
|
2022-08-01 14:33:18 +00:00
|
|
|
status, ok := srv.StreamStatus(testPeerID)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
require.True(r, ok)
|
|
|
|
require.Equal(r, expect, status)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
var lastRecvError time.Time
|
|
|
|
var lastRecvErrorMsg string
|
|
|
|
|
2022-05-10 20:25:51 +00:00
|
|
|
testutil.RunStep(t, "response fails to apply locally", func(t *testing.T) {
|
2022-07-08 17:01:13 +00:00
|
|
|
resp := &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Response_{
|
|
|
|
Response: &pbpeerstream.ReplicationMessage_Response{
|
2022-07-15 20:03:40 +00:00
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
ResourceID: "web",
|
|
|
|
Nonce: "24",
|
|
|
|
|
|
|
|
// Unknown operation gets NACKed
|
2022-07-08 17:01:13 +00:00
|
|
|
Operation: pbpeerstream.Operation_OPERATION_UNSPECIFIED,
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-07-15 20:03:40 +00:00
|
|
|
lastRecvError = it.FutureNow(1)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
err := client.Send(resp)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
ack, err := client.Recv()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
expectNack := &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Request_{
|
|
|
|
Request: &pbpeerstream.ReplicationMessage_Request{
|
2022-07-15 20:03:40 +00:00
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
2022-07-13 15:00:35 +00:00
|
|
|
ResponseNonce: "24",
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
Error: &pbstatus.Status{
|
|
|
|
Code: int32(code.Code_INVALID_ARGUMENT),
|
2022-07-08 17:01:13 +00:00
|
|
|
Message: `unsupported operation: "OPERATION_UNSPECIFIED"`,
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
prototest.AssertDeepEqual(t, expectNack, ack)
|
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
lastRecvErrorMsg = `unsupported operation: "OPERATION_UNSPECIFIED"`
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
expect := Status{
|
2022-07-25 23:08:03 +00:00
|
|
|
Connected: true,
|
2022-10-10 19:18:08 +00:00
|
|
|
LastSendSuccess: lastSendSuccess,
|
2022-08-25 23:32:59 +00:00
|
|
|
LastAck: lastSendAck,
|
2022-07-25 23:08:03 +00:00
|
|
|
LastNack: lastNack,
|
|
|
|
LastNackMessage: lastNackMsg,
|
|
|
|
LastRecvResourceSuccess: lastRecvResourceSuccess,
|
|
|
|
LastRecvError: lastRecvError,
|
|
|
|
LastRecvErrorMessage: lastRecvErrorMsg,
|
2022-09-29 19:37:19 +00:00
|
|
|
ExportedServices: []string{},
|
2022-07-25 21:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
retry.Run(t, func(r *retry.R) {
|
2022-08-01 14:33:18 +00:00
|
|
|
status, ok := srv.StreamStatus(testPeerID)
|
2022-07-25 21:27:53 +00:00
|
|
|
require.True(r, ok)
|
|
|
|
require.Equal(r, expect, status)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-07-25 23:08:03 +00:00
|
|
|
var lastRecvHeartbeat time.Time
|
2022-07-25 21:27:53 +00:00
|
|
|
testutil.RunStep(t, "receives heartbeat", func(t *testing.T) {
|
|
|
|
resp := &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Heartbeat_{
|
|
|
|
Heartbeat: &pbpeerstream.ReplicationMessage_Heartbeat{},
|
|
|
|
},
|
|
|
|
}
|
2022-07-25 23:08:03 +00:00
|
|
|
lastRecvHeartbeat = it.FutureNow(1)
|
2022-07-25 21:27:53 +00:00
|
|
|
err := client.Send(resp)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
expect := Status{
|
2022-07-25 23:08:03 +00:00
|
|
|
Connected: true,
|
2022-10-10 19:18:08 +00:00
|
|
|
LastSendSuccess: lastSendSuccess,
|
2022-08-25 23:32:59 +00:00
|
|
|
LastAck: lastSendAck,
|
2022-07-25 23:08:03 +00:00
|
|
|
LastNack: lastNack,
|
|
|
|
LastNackMessage: lastNackMsg,
|
|
|
|
LastRecvResourceSuccess: lastRecvResourceSuccess,
|
|
|
|
LastRecvError: lastRecvError,
|
|
|
|
LastRecvErrorMessage: lastRecvErrorMsg,
|
|
|
|
LastRecvHeartbeat: lastRecvHeartbeat,
|
2022-09-29 19:37:19 +00:00
|
|
|
ExportedServices: []string{},
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
retry.Run(t, func(r *retry.R) {
|
2022-08-01 14:33:18 +00:00
|
|
|
status, ok := srv.StreamStatus(testPeerID)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
require.True(r, ok)
|
|
|
|
require.Equal(r, expect, status)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-05-10 20:25:51 +00:00
|
|
|
testutil.RunStep(t, "client disconnect marks stream as disconnected", func(t *testing.T) {
|
2022-07-15 20:03:40 +00:00
|
|
|
lastRecvError = it.FutureNow(1)
|
|
|
|
disconnectTime := it.FutureNow(2)
|
2022-07-29 20:04:32 +00:00
|
|
|
lastRecvErrorMsg = "stream ended unexpectedly"
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
|
2022-07-15 20:03:40 +00:00
|
|
|
client.Close()
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
expect := Status{
|
2022-07-25 23:08:03 +00:00
|
|
|
Connected: false,
|
2022-07-29 20:04:32 +00:00
|
|
|
DisconnectErrorMessage: lastRecvErrorMsg,
|
2022-10-10 19:18:08 +00:00
|
|
|
LastSendSuccess: lastSendSuccess,
|
2022-08-25 23:32:59 +00:00
|
|
|
LastAck: lastSendAck,
|
2022-07-25 23:08:03 +00:00
|
|
|
LastNack: lastNack,
|
|
|
|
LastNackMessage: lastNackMsg,
|
|
|
|
DisconnectTime: disconnectTime,
|
|
|
|
LastRecvResourceSuccess: lastRecvResourceSuccess,
|
|
|
|
LastRecvError: lastRecvError,
|
|
|
|
LastRecvErrorMessage: lastRecvErrorMsg,
|
|
|
|
LastRecvHeartbeat: lastRecvHeartbeat,
|
2022-09-29 19:37:19 +00:00
|
|
|
ExportedServices: []string{},
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
retry.Run(t, func(r *retry.R) {
|
2022-08-01 14:33:18 +00:00
|
|
|
status, ok := srv.StreamStatus(testPeerID)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
require.True(r, ok)
|
|
|
|
require.Equal(r, expect, status)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStreamResources_Server_ServiceUpdates(t *testing.T) {
|
2022-07-08 17:01:13 +00:00
|
|
|
srv, store := newTestServer(t, nil)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
|
|
|
|
// Create a peering
|
|
|
|
var lastIdx uint64 = 1
|
2022-07-13 15:00:35 +00:00
|
|
|
p := writePeeringToBeDialed(t, store, lastIdx, "my-peering")
|
|
|
|
require.Empty(t, p.PeerID, "should be empty if being dialed")
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
|
2022-05-25 17:37:44 +00:00
|
|
|
// Set the initial roots and CA configuration.
|
2022-05-26 19:24:09 +00:00
|
|
|
_, _ = writeInitialRootsAndCA(t, store)
|
2022-05-25 15:13:23 +00:00
|
|
|
|
2022-07-13 15:00:35 +00:00
|
|
|
client := makeClient(t, srv, p.ID)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
|
|
|
|
// Register a service that is not yet exported
|
|
|
|
mysql := &structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{Node: "foo", Address: "10.0.0.1"},
|
|
|
|
Service: &structs.NodeService{ID: "mysql-1", Service: "mysql", Port: 5000},
|
|
|
|
}
|
|
|
|
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, store.EnsureNode(lastIdx, mysql.Node))
|
|
|
|
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, store.EnsureService(lastIdx, "foo", mysql.Service))
|
|
|
|
|
2022-06-27 19:37:18 +00:00
|
|
|
mongoSvcDefaults := &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "mongo",
|
|
|
|
Protocol: "grpc",
|
|
|
|
}
|
|
|
|
require.NoError(t, mongoSvcDefaults.Normalize())
|
|
|
|
require.NoError(t, mongoSvcDefaults.Validate())
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(lastIdx, mongoSvcDefaults))
|
|
|
|
|
|
|
|
// NOTE: for this test we'll just live in a fantasy realm where we assume
|
|
|
|
// that mongo understands gRPC
|
2022-05-19 21:37:52 +00:00
|
|
|
var (
|
|
|
|
mongoSN = structs.NewServiceName("mongo", nil).String()
|
|
|
|
mongoProxySN = structs.NewServiceName("mongo-sidecar-proxy", nil).String()
|
|
|
|
mysqlSN = structs.NewServiceName("mysql", nil).String()
|
|
|
|
mysqlProxySN = structs.NewServiceName("mysql-sidecar-proxy", nil).String()
|
|
|
|
)
|
|
|
|
|
2022-05-10 20:25:51 +00:00
|
|
|
testutil.RunStep(t, "exporting mysql leads to an UPSERT event", func(t *testing.T) {
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
entry := &structs.ExportedServicesConfigEntry{
|
|
|
|
Name: "default",
|
|
|
|
Services: []structs.ExportedService{
|
|
|
|
{
|
|
|
|
Name: "mysql",
|
|
|
|
Consumers: []structs.ServiceConsumer{
|
2022-10-04 18:46:15 +00:00
|
|
|
{Peer: "my-peering"},
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Mongo does not get pushed because it does not have instances registered.
|
|
|
|
Name: "mongo",
|
|
|
|
Consumers: []structs.ServiceConsumer{
|
2022-10-04 18:46:15 +00:00
|
|
|
{Peer: "my-peering"},
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-06-27 19:37:18 +00:00
|
|
|
require.NoError(t, entry.Normalize())
|
|
|
|
require.NoError(t, entry.Validate())
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
lastIdx++
|
2022-05-19 21:37:52 +00:00
|
|
|
require.NoError(t, store.EnsureConfigEntry(lastIdx, entry))
|
|
|
|
|
|
|
|
expectReplEvents(t, client,
|
2022-09-29 19:37:19 +00:00
|
|
|
func(t *testing.T, msg *pbpeerstream.ReplicationMessage) {
|
|
|
|
require.Equal(t, pbpeerstream.TypeURLPeeringServerAddresses, msg.GetRequest().ResourceURL)
|
|
|
|
},
|
2022-07-08 17:01:13 +00:00
|
|
|
func(t *testing.T, msg *pbpeerstream.ReplicationMessage) {
|
2022-07-15 20:03:40 +00:00
|
|
|
require.Equal(t, pbpeerstream.TypeURLPeeringTrustBundle, msg.GetResponse().ResourceURL)
|
2022-05-26 19:24:09 +00:00
|
|
|
// Roots tested in TestStreamResources_Server_CARootUpdates
|
|
|
|
},
|
2022-07-08 17:01:13 +00:00
|
|
|
func(t *testing.T, msg *pbpeerstream.ReplicationMessage) {
|
2022-06-09 16:05:18 +00:00
|
|
|
// no mongo instances exist
|
2022-07-15 20:03:40 +00:00
|
|
|
require.Equal(t, pbpeerstream.TypeURLExportedService, msg.GetResponse().ResourceURL)
|
2022-05-19 21:37:52 +00:00
|
|
|
require.Equal(t, mongoSN, msg.GetResponse().ResourceID)
|
2022-09-29 19:37:19 +00:00
|
|
|
require.Equal(t, pbpeerstream.Operation_OPERATION_UPSERT, msg.GetResponse().Operation)
|
|
|
|
|
|
|
|
var nodes pbpeerstream.ExportedService
|
|
|
|
require.NoError(t, msg.GetResponse().Resource.UnmarshalTo(&nodes))
|
|
|
|
require.Len(t, nodes.Nodes, 0)
|
2022-05-19 21:37:52 +00:00
|
|
|
},
|
2022-07-08 17:01:13 +00:00
|
|
|
func(t *testing.T, msg *pbpeerstream.ReplicationMessage) {
|
2022-06-09 16:05:18 +00:00
|
|
|
// proxies can't export because no mesh gateway exists yet
|
2022-07-15 20:03:40 +00:00
|
|
|
require.Equal(t, pbpeerstream.TypeURLExportedService, msg.GetResponse().ResourceURL)
|
2022-05-19 21:37:52 +00:00
|
|
|
require.Equal(t, mongoProxySN, msg.GetResponse().ResourceID)
|
2022-09-29 19:37:19 +00:00
|
|
|
require.Equal(t, pbpeerstream.Operation_OPERATION_UPSERT, msg.GetResponse().Operation)
|
|
|
|
|
|
|
|
var nodes pbpeerstream.ExportedService
|
|
|
|
require.NoError(t, msg.GetResponse().Resource.UnmarshalTo(&nodes))
|
|
|
|
require.Len(t, nodes.Nodes, 0)
|
2022-05-19 21:37:52 +00:00
|
|
|
},
|
2022-07-08 17:01:13 +00:00
|
|
|
func(t *testing.T, msg *pbpeerstream.ReplicationMessage) {
|
2022-07-15 20:03:40 +00:00
|
|
|
require.Equal(t, pbpeerstream.TypeURLExportedService, msg.GetResponse().ResourceURL)
|
2022-05-19 21:37:52 +00:00
|
|
|
require.Equal(t, mysqlSN, msg.GetResponse().ResourceID)
|
2022-07-08 17:01:13 +00:00
|
|
|
require.Equal(t, pbpeerstream.Operation_OPERATION_UPSERT, msg.GetResponse().Operation)
|
2022-05-19 21:37:52 +00:00
|
|
|
|
2022-07-15 20:03:40 +00:00
|
|
|
var nodes pbpeerstream.ExportedService
|
|
|
|
require.NoError(t, msg.GetResponse().Resource.UnmarshalTo(&nodes))
|
2022-05-19 21:37:52 +00:00
|
|
|
require.Len(t, nodes.Nodes, 1)
|
|
|
|
},
|
2022-07-08 17:01:13 +00:00
|
|
|
func(t *testing.T, msg *pbpeerstream.ReplicationMessage) {
|
2022-06-09 16:05:18 +00:00
|
|
|
// proxies can't export because no mesh gateway exists yet
|
2022-07-15 20:03:40 +00:00
|
|
|
require.Equal(t, pbpeerstream.TypeURLExportedService, msg.GetResponse().ResourceURL)
|
2022-06-09 16:05:18 +00:00
|
|
|
require.Equal(t, mysqlProxySN, msg.GetResponse().ResourceID)
|
2022-09-29 19:37:19 +00:00
|
|
|
require.Equal(t, pbpeerstream.Operation_OPERATION_UPSERT, msg.GetResponse().Operation)
|
|
|
|
|
|
|
|
var nodes pbpeerstream.ExportedService
|
|
|
|
require.NoError(t, msg.GetResponse().Resource.UnmarshalTo(&nodes))
|
|
|
|
require.Len(t, nodes.Nodes, 0)
|
|
|
|
},
|
|
|
|
// This event happens because this is the first test case and there are
|
|
|
|
// no exported services when replication is initially set up.
|
|
|
|
func(t *testing.T, msg *pbpeerstream.ReplicationMessage) {
|
|
|
|
require.Equal(t, pbpeerstream.TypeURLExportedServiceList, msg.GetResponse().ResourceURL)
|
|
|
|
require.Equal(t, subExportedServiceList, msg.GetResponse().ResourceID)
|
|
|
|
require.Equal(t, pbpeerstream.Operation_OPERATION_UPSERT, msg.GetResponse().Operation)
|
|
|
|
|
|
|
|
var exportedServices pbpeerstream.ExportedServiceList
|
|
|
|
require.NoError(t, msg.GetResponse().Resource.UnmarshalTo(&exportedServices))
|
|
|
|
require.ElementsMatch(t, []string{}, exportedServices.Services)
|
|
|
|
},
|
|
|
|
func(t *testing.T, msg *pbpeerstream.ReplicationMessage) {
|
|
|
|
require.Equal(t, pbpeerstream.TypeURLExportedServiceList, msg.GetResponse().ResourceURL)
|
|
|
|
require.Equal(t, subExportedServiceList, msg.GetResponse().ResourceID)
|
|
|
|
require.Equal(t, pbpeerstream.Operation_OPERATION_UPSERT, msg.GetResponse().Operation)
|
|
|
|
|
|
|
|
var exportedServices pbpeerstream.ExportedServiceList
|
|
|
|
require.NoError(t, msg.GetResponse().Resource.UnmarshalTo(&exportedServices))
|
|
|
|
require.ElementsMatch(t,
|
|
|
|
[]string{structs.ServiceName{Name: "mongo"}.String(), structs.ServiceName{Name: "mysql"}.String()},
|
|
|
|
exportedServices.Services)
|
2022-06-09 16:05:18 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
testutil.RunStep(t, "register mesh gateway to send proxy updates", func(t *testing.T) {
|
|
|
|
gateway := &structs.CheckServiceNode{Node: &structs.Node{Node: "mgw", Address: "10.1.1.1"},
|
|
|
|
Service: &structs.NodeService{ID: "gateway-1", Kind: structs.ServiceKindMeshGateway, Service: "gateway", Port: 8443},
|
|
|
|
// TODO: checks
|
|
|
|
}
|
|
|
|
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, store.EnsureNode(lastIdx, gateway.Node))
|
|
|
|
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, store.EnsureService(lastIdx, "mgw", gateway.Service))
|
|
|
|
|
|
|
|
expectReplEvents(t, client,
|
2022-07-08 17:01:13 +00:00
|
|
|
func(t *testing.T, msg *pbpeerstream.ReplicationMessage) {
|
2022-07-15 20:03:40 +00:00
|
|
|
require.Equal(t, pbpeerstream.TypeURLExportedService, msg.GetResponse().ResourceURL)
|
2022-06-09 16:05:18 +00:00
|
|
|
require.Equal(t, mongoProxySN, msg.GetResponse().ResourceID)
|
2022-07-08 17:01:13 +00:00
|
|
|
require.Equal(t, pbpeerstream.Operation_OPERATION_UPSERT, msg.GetResponse().Operation)
|
2022-06-09 16:05:18 +00:00
|
|
|
|
2022-07-15 20:03:40 +00:00
|
|
|
var nodes pbpeerstream.ExportedService
|
|
|
|
require.NoError(t, msg.GetResponse().Resource.UnmarshalTo(&nodes))
|
2022-06-09 16:05:18 +00:00
|
|
|
require.Len(t, nodes.Nodes, 1)
|
|
|
|
|
2022-06-27 19:37:18 +00:00
|
|
|
pm := nodes.Nodes[0].Service.Connect.PeerMeta
|
|
|
|
require.Equal(t, "grpc", pm.Protocol)
|
|
|
|
spiffeIDs := []string{
|
|
|
|
"spiffe://11111111-2222-3333-4444-555555555555.consul/ns/default/dc/dc1/svc/mongo",
|
|
|
|
"spiffe://11111111-2222-3333-4444-555555555555.consul/gateway/mesh/dc/dc1",
|
|
|
|
}
|
|
|
|
require.Equal(t, spiffeIDs, pm.SpiffeID)
|
2022-06-09 16:05:18 +00:00
|
|
|
},
|
2022-07-08 17:01:13 +00:00
|
|
|
func(t *testing.T, msg *pbpeerstream.ReplicationMessage) {
|
2022-07-15 20:03:40 +00:00
|
|
|
require.Equal(t, pbpeerstream.TypeURLExportedService, msg.GetResponse().ResourceURL)
|
2022-05-19 21:37:52 +00:00
|
|
|
require.Equal(t, mysqlProxySN, msg.GetResponse().ResourceID)
|
2022-07-08 17:01:13 +00:00
|
|
|
require.Equal(t, pbpeerstream.Operation_OPERATION_UPSERT, msg.GetResponse().Operation)
|
2022-05-27 00:56:51 +00:00
|
|
|
|
2022-07-15 20:03:40 +00:00
|
|
|
var nodes pbpeerstream.ExportedService
|
|
|
|
require.NoError(t, msg.GetResponse().Resource.UnmarshalTo(&nodes))
|
2022-05-27 00:56:51 +00:00
|
|
|
require.Len(t, nodes.Nodes, 1)
|
|
|
|
|
2022-06-27 19:37:18 +00:00
|
|
|
pm := nodes.Nodes[0].Service.Connect.PeerMeta
|
|
|
|
require.Equal(t, "tcp", pm.Protocol)
|
|
|
|
spiffeIDs := []string{
|
|
|
|
"spiffe://11111111-2222-3333-4444-555555555555.consul/ns/default/dc/dc1/svc/mysql",
|
2022-07-12 16:38:13 +00:00
|
|
|
"spiffe://11111111-2222-3333-4444-555555555555.consul/gateway/mesh/dc/dc1",
|
2022-06-27 19:37:18 +00:00
|
|
|
}
|
|
|
|
require.Equal(t, spiffeIDs, pm.SpiffeID)
|
2022-05-19 21:37:52 +00:00
|
|
|
},
|
|
|
|
)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
mongo := &structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{Node: "zip", Address: "10.0.0.3"},
|
|
|
|
Service: &structs.NodeService{ID: "mongo-1", Service: "mongo", Port: 5000},
|
|
|
|
}
|
|
|
|
|
2022-05-10 20:25:51 +00:00
|
|
|
testutil.RunStep(t, "registering mongo instance leads to an UPSERT event", func(t *testing.T) {
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, store.EnsureNode(lastIdx, mongo.Node))
|
|
|
|
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, store.EnsureService(lastIdx, "zip", mongo.Service))
|
|
|
|
|
|
|
|
retry.Run(t, func(r *retry.R) {
|
|
|
|
msg, err := client.RecvWithTimeout(100 * time.Millisecond)
|
|
|
|
require.NoError(r, err)
|
2022-07-08 17:01:13 +00:00
|
|
|
require.Equal(r, pbpeerstream.Operation_OPERATION_UPSERT, msg.GetResponse().Operation)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
require.Equal(r, mongo.Service.CompoundServiceName().String(), msg.GetResponse().ResourceID)
|
|
|
|
|
2022-07-15 20:03:40 +00:00
|
|
|
var nodes pbpeerstream.ExportedService
|
|
|
|
require.NoError(t, msg.GetResponse().Resource.UnmarshalTo(&nodes))
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
require.Len(r, nodes.Nodes, 1)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-09-29 19:37:19 +00:00
|
|
|
testutil.RunStep(t, "un-exporting mysql leads to an exported service list update", func(t *testing.T) {
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
entry := &structs.ExportedServicesConfigEntry{
|
|
|
|
Name: "default",
|
|
|
|
Services: []structs.ExportedService{
|
|
|
|
{
|
|
|
|
Name: "mongo",
|
|
|
|
Consumers: []structs.ServiceConsumer{
|
|
|
|
{
|
2022-10-04 18:46:15 +00:00
|
|
|
Peer: "my-peering",
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-06-27 19:37:18 +00:00
|
|
|
require.NoError(t, entry.Normalize())
|
|
|
|
require.NoError(t, entry.Validate())
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
lastIdx++
|
2022-05-26 19:24:09 +00:00
|
|
|
err := store.EnsureConfigEntry(lastIdx, entry)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
retry.Run(t, func(r *retry.R) {
|
|
|
|
msg, err := client.RecvWithTimeout(100 * time.Millisecond)
|
|
|
|
require.NoError(r, err)
|
2022-09-29 19:37:19 +00:00
|
|
|
require.Equal(r, pbpeerstream.TypeURLExportedServiceList, msg.GetResponse().ResourceURL)
|
|
|
|
require.Equal(t, subExportedServiceList, msg.GetResponse().ResourceID)
|
|
|
|
require.Equal(t, pbpeerstream.Operation_OPERATION_UPSERT, msg.GetResponse().Operation)
|
|
|
|
|
|
|
|
var exportedServices pbpeerstream.ExportedServiceList
|
|
|
|
require.NoError(t, msg.GetResponse().Resource.UnmarshalTo(&exportedServices))
|
|
|
|
require.Equal(t, []string{structs.ServiceName{Name: "mongo"}.String()}, exportedServices.Services)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-05-10 20:25:51 +00:00
|
|
|
testutil.RunStep(t, "deleting the config entry leads to a DELETE event for mongo", func(t *testing.T) {
|
2022-05-26 19:24:09 +00:00
|
|
|
err := store.DeleteConfigEntry(lastIdx, structs.ExportedServices, "default", nil)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
retry.Run(t, func(r *retry.R) {
|
|
|
|
msg, err := client.RecvWithTimeout(100 * time.Millisecond)
|
|
|
|
require.NoError(r, err)
|
2022-09-29 19:37:19 +00:00
|
|
|
require.Equal(r, pbpeerstream.TypeURLExportedServiceList, msg.GetResponse().ResourceURL)
|
|
|
|
require.Equal(t, subExportedServiceList, msg.GetResponse().ResourceID)
|
|
|
|
require.Equal(t, pbpeerstream.Operation_OPERATION_UPSERT, msg.GetResponse().Operation)
|
|
|
|
|
|
|
|
var exportedServices pbpeerstream.ExportedServiceList
|
|
|
|
require.NoError(t, msg.GetResponse().Resource.UnmarshalTo(&exportedServices))
|
|
|
|
require.Len(t, exportedServices.Services, 0)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-26 19:24:09 +00:00
|
|
|
func TestStreamResources_Server_CARootUpdates(t *testing.T) {
|
2022-07-08 17:01:13 +00:00
|
|
|
srv, store := newTestServer(t, nil)
|
2022-05-26 19:24:09 +00:00
|
|
|
|
|
|
|
// Create a peering
|
|
|
|
var lastIdx uint64 = 1
|
2022-07-13 15:00:35 +00:00
|
|
|
p := writePeeringToBeDialed(t, store, lastIdx, "my-peering")
|
|
|
|
require.Empty(t, p.PeerID, "should be empty if being dialed")
|
2022-05-26 19:24:09 +00:00
|
|
|
|
|
|
|
// Set the initial roots and CA configuration.
|
|
|
|
clusterID, rootA := writeInitialRootsAndCA(t, store)
|
|
|
|
|
2022-07-13 15:00:35 +00:00
|
|
|
client := makeClient(t, srv, p.ID)
|
2022-05-26 19:24:09 +00:00
|
|
|
|
|
|
|
testutil.RunStep(t, "initial CA Roots replication", func(t *testing.T) {
|
|
|
|
expectReplEvents(t, client,
|
2022-09-29 19:37:19 +00:00
|
|
|
func(t *testing.T, msg *pbpeerstream.ReplicationMessage) {
|
|
|
|
require.Equal(t, pbpeerstream.TypeURLPeeringServerAddresses, msg.GetRequest().ResourceURL)
|
|
|
|
},
|
2022-07-08 17:01:13 +00:00
|
|
|
func(t *testing.T, msg *pbpeerstream.ReplicationMessage) {
|
2022-07-15 20:03:40 +00:00
|
|
|
require.Equal(t, pbpeerstream.TypeURLPeeringTrustBundle, msg.GetResponse().ResourceURL)
|
2022-05-26 19:24:09 +00:00
|
|
|
require.Equal(t, "roots", msg.GetResponse().ResourceID)
|
2022-07-08 17:01:13 +00:00
|
|
|
require.Equal(t, pbpeerstream.Operation_OPERATION_UPSERT, msg.GetResponse().Operation)
|
2022-05-26 19:24:09 +00:00
|
|
|
|
|
|
|
var trustBundle pbpeering.PeeringTrustBundle
|
2022-07-15 20:03:40 +00:00
|
|
|
require.NoError(t, msg.GetResponse().Resource.UnmarshalTo(&trustBundle))
|
2022-05-26 19:24:09 +00:00
|
|
|
|
|
|
|
require.ElementsMatch(t, []string{rootA.RootCert}, trustBundle.RootPEMs)
|
|
|
|
expect := connect.SpiffeIDSigningForCluster(clusterID).Host()
|
|
|
|
require.Equal(t, expect, trustBundle.TrustDomain)
|
|
|
|
},
|
2022-09-29 19:37:19 +00:00
|
|
|
func(t *testing.T, msg *pbpeerstream.ReplicationMessage) {
|
|
|
|
require.Equal(t, pbpeerstream.TypeURLExportedServiceList, msg.GetResponse().ResourceURL)
|
|
|
|
require.Equal(t, subExportedServiceList, msg.GetResponse().ResourceID)
|
|
|
|
require.Equal(t, pbpeerstream.Operation_OPERATION_UPSERT, msg.GetResponse().Operation)
|
|
|
|
|
|
|
|
var exportedServices pbpeerstream.ExportedServiceList
|
|
|
|
require.NoError(t, msg.GetResponse().Resource.UnmarshalTo(&exportedServices))
|
|
|
|
require.ElementsMatch(t, []string{}, exportedServices.Services)
|
|
|
|
},
|
2022-05-26 19:24:09 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
testutil.RunStep(t, "CA root rotation sends upsert event", func(t *testing.T) {
|
|
|
|
// get max index for CAS operation
|
|
|
|
cidx, _, err := store.CARoots(nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
rootB := connect.TestCA(t, nil)
|
|
|
|
rootC := connect.TestCA(t, nil)
|
|
|
|
rootC.Active = false // there can only be one active root
|
|
|
|
lastIdx++
|
|
|
|
set, err := store.CARootSetCAS(lastIdx, cidx, []*structs.CARoot{rootB, rootC})
|
|
|
|
require.True(t, set)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
expectReplEvents(t, client,
|
2022-07-08 17:01:13 +00:00
|
|
|
func(t *testing.T, msg *pbpeerstream.ReplicationMessage) {
|
2022-07-15 20:03:40 +00:00
|
|
|
require.Equal(t, pbpeerstream.TypeURLPeeringTrustBundle, msg.GetResponse().ResourceURL)
|
2022-05-26 19:24:09 +00:00
|
|
|
require.Equal(t, "roots", msg.GetResponse().ResourceID)
|
2022-07-08 17:01:13 +00:00
|
|
|
require.Equal(t, pbpeerstream.Operation_OPERATION_UPSERT, msg.GetResponse().Operation)
|
2022-05-26 19:24:09 +00:00
|
|
|
|
|
|
|
var trustBundle pbpeering.PeeringTrustBundle
|
2022-07-15 20:03:40 +00:00
|
|
|
require.NoError(t, msg.GetResponse().Resource.UnmarshalTo(&trustBundle))
|
2022-05-26 19:24:09 +00:00
|
|
|
|
|
|
|
require.ElementsMatch(t, []string{rootB.RootCert, rootC.RootCert}, trustBundle.RootPEMs)
|
|
|
|
expect := connect.SpiffeIDSigningForCluster(clusterID).Host()
|
|
|
|
require.Equal(t, expect, trustBundle.TrustDomain)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-10-12 01:02:04 +00:00
|
|
|
func TestStreamResources_Server_AckNackNonce(t *testing.T) {
|
|
|
|
srv, store := newTestServer(t, func(c *Config) {
|
|
|
|
c.incomingHeartbeatTimeout = 50 * time.Millisecond
|
|
|
|
})
|
|
|
|
|
|
|
|
p := writePeeringToBeDialed(t, store, 1, "my-peer")
|
|
|
|
require.Empty(t, p.PeerID, "should be empty if being dialed")
|
|
|
|
|
|
|
|
// Set the initial roots and CA configuration.
|
|
|
|
_, _ = writeInitialRootsAndCA(t, store)
|
|
|
|
|
|
|
|
client := makeClient(t, srv, testPeerID)
|
|
|
|
client.DrainStream(t)
|
|
|
|
|
|
|
|
testutil.RunStep(t, "ack contains nonce from response", func(t *testing.T) {
|
|
|
|
resp := &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Response_{
|
|
|
|
Response: &pbpeerstream.ReplicationMessage_Response{
|
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
|
|
|
Operation: pbpeerstream.Operation_OPERATION_UPSERT,
|
|
|
|
Nonce: "1234",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
require.NoError(t, client.Send(resp))
|
|
|
|
|
|
|
|
msg, err := client.Recv()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, "1234", msg.GetRequest().ResponseNonce)
|
|
|
|
})
|
|
|
|
|
|
|
|
testutil.RunStep(t, "nack contains nonce from response", func(t *testing.T) {
|
|
|
|
resp := &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Response_{
|
|
|
|
Response: &pbpeerstream.ReplicationMessage_Response{
|
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
|
|
|
Operation: pbpeerstream.Operation_OPERATION_UNSPECIFIED, // Unspecified gets NACK
|
|
|
|
Nonce: "5678",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
require.NoError(t, client.Send(resp))
|
|
|
|
|
|
|
|
msg, err := client.Recv()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, "5678", msg.GetRequest().ResponseNonce)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-07-25 21:27:53 +00:00
|
|
|
// Test that when the client doesn't send a heartbeat in time, the stream is disconnected.
|
|
|
|
func TestStreamResources_Server_DisconnectsOnHeartbeatTimeout(t *testing.T) {
|
2022-07-21 17:03:27 +00:00
|
|
|
it := incrementalTime{
|
|
|
|
base: time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC),
|
|
|
|
}
|
|
|
|
|
|
|
|
srv, store := newTestServer(t, func(c *Config) {
|
2022-08-30 15:09:25 +00:00
|
|
|
c.incomingHeartbeatTimeout = 50 * time.Millisecond
|
2022-07-21 17:03:27 +00:00
|
|
|
})
|
2022-08-29 20:32:26 +00:00
|
|
|
srv.Tracker.setClock(it.Now)
|
2022-07-21 17:03:27 +00:00
|
|
|
|
|
|
|
p := writePeeringToBeDialed(t, store, 1, "my-peer")
|
|
|
|
require.Empty(t, p.PeerID, "should be empty if being dialed")
|
|
|
|
|
|
|
|
// Set the initial roots and CA configuration.
|
|
|
|
_, _ = writeInitialRootsAndCA(t, store)
|
|
|
|
|
2022-08-01 14:33:18 +00:00
|
|
|
client := makeClient(t, srv, testPeerID)
|
2022-07-21 17:03:27 +00:00
|
|
|
|
2022-09-29 19:37:19 +00:00
|
|
|
client.DrainStream(t)
|
2022-07-21 17:03:27 +00:00
|
|
|
|
|
|
|
testutil.RunStep(t, "new stream gets tracked", func(t *testing.T) {
|
|
|
|
retry.Run(t, func(r *retry.R) {
|
2022-08-01 14:33:18 +00:00
|
|
|
status, ok := srv.StreamStatus(testPeerID)
|
2022-07-21 17:03:27 +00:00
|
|
|
require.True(r, ok)
|
|
|
|
require.True(r, status.Connected)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
testutil.RunStep(t, "stream is disconnected due to heartbeat timeout", func(t *testing.T) {
|
2022-07-25 21:27:53 +00:00
|
|
|
disconnectTime := it.FutureNow(1)
|
2022-07-21 17:03:27 +00:00
|
|
|
retry.Run(t, func(r *retry.R) {
|
2022-08-01 14:33:18 +00:00
|
|
|
status, ok := srv.StreamStatus(testPeerID)
|
2022-07-21 17:03:27 +00:00
|
|
|
require.True(r, ok)
|
|
|
|
require.False(r, status.Connected)
|
2022-07-25 21:27:53 +00:00
|
|
|
require.Equal(r, "heartbeat timeout", status.DisconnectErrorMessage)
|
|
|
|
require.Equal(r, disconnectTime, status.DisconnectTime)
|
2022-07-21 17:03:27 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test that the server sends heartbeats at the expected interval.
|
|
|
|
func TestStreamResources_Server_SendsHeartbeats(t *testing.T) {
|
|
|
|
it := incrementalTime{
|
|
|
|
base: time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC),
|
|
|
|
}
|
|
|
|
outgoingHeartbeatInterval := 5 * time.Millisecond
|
|
|
|
|
|
|
|
srv, store := newTestServer(t, func(c *Config) {
|
|
|
|
c.outgoingHeartbeatInterval = outgoingHeartbeatInterval
|
|
|
|
})
|
2022-08-29 20:32:26 +00:00
|
|
|
srv.Tracker.setClock(it.Now)
|
2022-07-21 17:03:27 +00:00
|
|
|
|
|
|
|
p := writePeeringToBeDialed(t, store, 1, "my-peer")
|
|
|
|
require.Empty(t, p.PeerID, "should be empty if being dialed")
|
|
|
|
|
|
|
|
// Set the initial roots and CA configuration.
|
|
|
|
_, _ = writeInitialRootsAndCA(t, store)
|
|
|
|
|
2022-08-01 14:33:18 +00:00
|
|
|
client := makeClient(t, srv, testPeerID)
|
2022-07-21 17:03:27 +00:00
|
|
|
|
|
|
|
testutil.RunStep(t, "new stream gets tracked", func(t *testing.T) {
|
|
|
|
retry.Run(t, func(r *retry.R) {
|
2022-09-29 19:37:19 +00:00
|
|
|
_, err := client.Recv()
|
|
|
|
require.NoError(r, err)
|
2022-08-01 14:33:18 +00:00
|
|
|
status, ok := srv.StreamStatus(testPeerID)
|
2022-07-21 17:03:27 +00:00
|
|
|
require.True(r, ok)
|
|
|
|
require.True(r, status.Connected)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
testutil.RunStep(t, "sends first heartbeat", func(t *testing.T) {
|
|
|
|
retry.RunWith(&retry.Timer{
|
|
|
|
Timeout: outgoingHeartbeatInterval * 2,
|
|
|
|
Wait: outgoingHeartbeatInterval / 2,
|
|
|
|
}, t, func(r *retry.R) {
|
|
|
|
heartbeat, err := client.Recv()
|
2022-09-29 19:37:19 +00:00
|
|
|
require.NoError(r, err)
|
|
|
|
require.NotNil(r, heartbeat.GetHeartbeat())
|
2022-07-21 17:03:27 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
testutil.RunStep(t, "sends second heartbeat", func(t *testing.T) {
|
|
|
|
retry.RunWith(&retry.Timer{
|
|
|
|
Timeout: outgoingHeartbeatInterval * 2,
|
|
|
|
Wait: outgoingHeartbeatInterval / 2,
|
|
|
|
}, t, func(r *retry.R) {
|
|
|
|
heartbeat, err := client.Recv()
|
2022-09-29 19:37:19 +00:00
|
|
|
require.NoError(r, err)
|
|
|
|
require.NotNil(r, heartbeat.GetHeartbeat())
|
2022-07-21 17:03:27 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test that as long as the server receives heartbeats it keeps the connection open.
|
|
|
|
func TestStreamResources_Server_KeepsConnectionOpenWithHeartbeat(t *testing.T) {
|
|
|
|
it := incrementalTime{
|
|
|
|
base: time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC),
|
|
|
|
}
|
|
|
|
incomingHeartbeatTimeout := 10 * time.Millisecond
|
|
|
|
|
|
|
|
srv, store := newTestServer(t, func(c *Config) {
|
2022-08-26 20:49:03 +00:00
|
|
|
c.incomingHeartbeatTimeout = incomingHeartbeatTimeout
|
2022-07-21 17:03:27 +00:00
|
|
|
})
|
2022-08-29 20:32:26 +00:00
|
|
|
srv.Tracker.setClock(it.Now)
|
2022-07-21 17:03:27 +00:00
|
|
|
|
|
|
|
p := writePeeringToBeDialed(t, store, 1, "my-peer")
|
|
|
|
require.Empty(t, p.PeerID, "should be empty if being dialed")
|
|
|
|
|
|
|
|
// Set the initial roots and CA configuration.
|
|
|
|
_, _ = writeInitialRootsAndCA(t, store)
|
|
|
|
|
2022-08-01 14:33:18 +00:00
|
|
|
client := makeClient(t, srv, testPeerID)
|
2022-07-21 17:03:27 +00:00
|
|
|
|
2022-09-29 19:37:19 +00:00
|
|
|
client.DrainStream(t)
|
2022-07-21 17:03:27 +00:00
|
|
|
|
|
|
|
testutil.RunStep(t, "new stream gets tracked", func(t *testing.T) {
|
|
|
|
retry.Run(t, func(r *retry.R) {
|
2022-08-01 14:33:18 +00:00
|
|
|
status, ok := srv.StreamStatus(testPeerID)
|
2022-07-21 17:03:27 +00:00
|
|
|
require.True(r, ok)
|
|
|
|
require.True(r, status.Connected)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
heartbeatMsg := &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Heartbeat_{
|
|
|
|
Heartbeat: &pbpeerstream.ReplicationMessage_Heartbeat{}}}
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
// errCh is used to collect any send errors from within the goroutine.
|
|
|
|
errCh := make(chan error)
|
|
|
|
|
|
|
|
// Set up a goroutine to send the heartbeat every 1/2 of the timeout.
|
|
|
|
go func() {
|
|
|
|
// This is just a do while loop. We want to send the heartbeat right away to start
|
|
|
|
// because the test setup above takes some time and we might be close to the heartbeat
|
|
|
|
// timeout already.
|
|
|
|
for {
|
|
|
|
err := client.Send(heartbeatMsg)
|
|
|
|
if err != nil {
|
|
|
|
select {
|
|
|
|
case errCh <- err:
|
|
|
|
case <-ctx.Done():
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
select {
|
|
|
|
case <-time.After(incomingHeartbeatTimeout / 2):
|
|
|
|
case <-ctx.Done():
|
|
|
|
close(errCh)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Assert that the stream remains connected for 5 heartbeat timeouts.
|
|
|
|
require.Never(t, func() bool {
|
2022-08-01 14:33:18 +00:00
|
|
|
status, ok := srv.StreamStatus(testPeerID)
|
2022-07-21 17:03:27 +00:00
|
|
|
if !ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return !status.Connected
|
|
|
|
}, incomingHeartbeatTimeout*5, incomingHeartbeatTimeout)
|
|
|
|
|
|
|
|
// Kill the heartbeat sending goroutine and check if it had any errors.
|
|
|
|
cancel()
|
|
|
|
err, ok := <-errCh
|
|
|
|
if ok {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-26 19:24:09 +00:00
|
|
|
// makeClient sets up a *MockClient with the initial subscription
|
|
|
|
// message handshake.
|
2022-08-22 14:22:11 +00:00
|
|
|
func makeClient(t *testing.T, srv *testServer, peerID string) *MockClient {
|
2022-05-26 19:24:09 +00:00
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
client := NewMockClient(context.Background())
|
|
|
|
|
|
|
|
errCh := make(chan error, 1)
|
|
|
|
client.ErrCh = errCh
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
// Pass errors from server handler into ErrCh so that they can be seen by the client on Recv().
|
|
|
|
// This matches gRPC's behavior when an error is returned by a server.
|
|
|
|
if err := srv.StreamResources(client.ReplicationStream); err != nil {
|
2022-08-22 14:22:11 +00:00
|
|
|
errCh <- err
|
2022-05-26 19:24:09 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2022-08-01 14:33:18 +00:00
|
|
|
// Send the initial request
|
|
|
|
require.NoError(t, client.Send(&pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Open_{
|
|
|
|
Open: &pbpeerstream.ReplicationMessage_Open{
|
|
|
|
PeerID: testPeerID,
|
|
|
|
StreamSecretID: testPendingStreamSecretID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
|
|
|
// Receive a services and roots subscription request pair from server
|
|
|
|
receivedSub1, err := client.Recv()
|
|
|
|
require.NoError(t, err)
|
|
|
|
receivedSub2, err := client.Recv()
|
|
|
|
require.NoError(t, err)
|
2022-08-22 14:22:11 +00:00
|
|
|
receivedSub3, err := client.Recv()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// This is required when the client subscribes to server address replication messages.
|
|
|
|
// We assert for the handler to be called at least once but the data doesn't matter.
|
|
|
|
srv.mockSnapshotHandler.expect("", 0, 0, nil)
|
2022-08-01 14:33:18 +00:00
|
|
|
|
2022-08-22 14:22:11 +00:00
|
|
|
// Issue services, roots, and server address subscription to server.
|
|
|
|
// Note that server address may not come as an initial message
|
2022-07-15 20:03:40 +00:00
|
|
|
for _, resourceURL := range []string{
|
|
|
|
pbpeerstream.TypeURLExportedService,
|
|
|
|
pbpeerstream.TypeURLPeeringTrustBundle,
|
2022-08-22 14:21:20 +00:00
|
|
|
pbpeerstream.TypeURLPeeringServerAddresses,
|
2022-07-15 20:03:40 +00:00
|
|
|
} {
|
|
|
|
init := &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Request_{
|
|
|
|
Request: &pbpeerstream.ReplicationMessage_Request{
|
|
|
|
PeerID: peerID,
|
|
|
|
ResourceURL: resourceURL,
|
|
|
|
},
|
2022-05-26 19:24:09 +00:00
|
|
|
},
|
2022-07-15 20:03:40 +00:00
|
|
|
}
|
|
|
|
require.NoError(t, client.Send(init))
|
2022-05-26 19:24:09 +00:00
|
|
|
}
|
|
|
|
|
2022-07-15 20:03:40 +00:00
|
|
|
expect := []*pbpeerstream.ReplicationMessage{
|
|
|
|
{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Request_{
|
|
|
|
Request: &pbpeerstream.ReplicationMessage_Request{
|
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
|
|
|
// The PeerID field is only set for the messages coming FROM
|
|
|
|
// the establishing side and are going to be empty from the
|
|
|
|
// other side.
|
|
|
|
PeerID: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Request_{
|
|
|
|
Request: &pbpeerstream.ReplicationMessage_Request{
|
|
|
|
ResourceURL: pbpeerstream.TypeURLPeeringTrustBundle,
|
|
|
|
// The PeerID field is only set for the messages coming FROM
|
|
|
|
// the establishing side and are going to be empty from the
|
|
|
|
// other side.
|
|
|
|
PeerID: "",
|
|
|
|
},
|
2022-05-26 19:24:09 +00:00
|
|
|
},
|
|
|
|
},
|
2022-09-02 15:44:54 +00:00
|
|
|
{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Request_{
|
|
|
|
Request: &pbpeerstream.ReplicationMessage_Request{
|
|
|
|
ResourceURL: pbpeerstream.TypeURLPeeringServerAddresses,
|
|
|
|
// The PeerID field is only set for the messages coming FROM
|
|
|
|
// the establishing side and are going to be empty from the
|
|
|
|
// other side.
|
|
|
|
PeerID: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-05-26 19:24:09 +00:00
|
|
|
}
|
2022-07-15 20:03:40 +00:00
|
|
|
got := []*pbpeerstream.ReplicationMessage{
|
|
|
|
receivedSub1,
|
|
|
|
receivedSub2,
|
2022-08-22 14:22:11 +00:00
|
|
|
receivedSub3,
|
2022-07-15 20:03:40 +00:00
|
|
|
}
|
2022-08-01 14:33:18 +00:00
|
|
|
prototest.AssertElementsMatch(t, expect, got)
|
2022-05-26 19:24:09 +00:00
|
|
|
|
|
|
|
return client
|
|
|
|
}
|
|
|
|
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
type testStreamBackend struct {
|
2022-07-08 17:01:13 +00:00
|
|
|
pub state.EventPublisher
|
|
|
|
store *state.Store
|
|
|
|
leader func() bool
|
2022-05-27 00:55:16 +00:00
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
leaderAddrLock sync.Mutex
|
|
|
|
leaderAddr string
|
2022-05-27 00:55:16 +00:00
|
|
|
}
|
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
var _ Backend = (*testStreamBackend)(nil)
|
2022-05-23 18:30:58 +00:00
|
|
|
|
|
|
|
func (b *testStreamBackend) IsLeader() bool {
|
|
|
|
if b.leader != nil {
|
|
|
|
return b.leader()
|
|
|
|
}
|
|
|
|
return true
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
func (b *testStreamBackend) SetLeaderAddress(addr string) {
|
|
|
|
b.leaderAddrLock.Lock()
|
|
|
|
defer b.leaderAddrLock.Unlock()
|
|
|
|
b.leaderAddr = addr
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
func (b *testStreamBackend) GetLeaderAddress() string {
|
|
|
|
b.leaderAddrLock.Lock()
|
|
|
|
defer b.leaderAddrLock.Unlock()
|
|
|
|
return b.leaderAddr
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
func (b *testStreamBackend) Subscribe(req *stream.SubscribeRequest) (*stream.Subscription, error) {
|
|
|
|
return b.pub.Subscribe(req)
|
2022-06-13 17:52:28 +00:00
|
|
|
}
|
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
func (b *testStreamBackend) PeeringTerminateByID(req *pbpeering.PeeringTerminateByIDRequest) error {
|
2022-06-13 17:52:28 +00:00
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
func (b *testStreamBackend) PeeringTrustBundleWrite(req *pbpeering.PeeringTrustBundleWriteRequest) error {
|
2022-06-13 17:52:28 +00:00
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
2022-08-01 14:33:18 +00:00
|
|
|
func (b *testStreamBackend) ValidateProposedPeeringSecret(id string) (bool, error) {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
2022-08-08 07:41:00 +00:00
|
|
|
func (b *testStreamBackend) PeeringSecretsWrite(req *pbpeering.SecretsWriteRequest) error {
|
2022-08-01 14:33:18 +00:00
|
|
|
return b.store.PeeringSecretsWrite(1, req)
|
|
|
|
}
|
|
|
|
|
2022-08-22 14:22:11 +00:00
|
|
|
func (b *testStreamBackend) PeeringWrite(req *pbpeering.PeeringWriteRequest) error {
|
|
|
|
return b.store.PeeringWrite(1, req)
|
|
|
|
}
|
|
|
|
|
2022-06-13 17:52:28 +00:00
|
|
|
// CatalogRegister mocks catalog registrations through Raft by copying the logic of FSM.applyRegister.
|
2022-07-08 17:01:13 +00:00
|
|
|
func (b *testStreamBackend) CatalogRegister(req *structs.RegisterRequest) error {
|
|
|
|
return b.store.EnsureRegistration(1, req)
|
2022-06-13 17:52:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CatalogDeregister mocks catalog de-registrations through Raft by copying the logic of FSM.applyDeregister.
|
2022-07-08 17:01:13 +00:00
|
|
|
func (b *testStreamBackend) CatalogDeregister(req *structs.DeregisterRequest) error {
|
2022-06-13 17:52:28 +00:00
|
|
|
if req.ServiceID != "" {
|
2022-07-08 17:01:13 +00:00
|
|
|
if err := b.store.DeleteService(1, req.Node, req.ServiceID, &req.EnterpriseMeta, req.PeerName); err != nil {
|
2022-06-13 17:52:28 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else if req.CheckID != "" {
|
2022-07-08 17:01:13 +00:00
|
|
|
if err := b.store.DeleteCheck(1, req.Node, req.CheckID, &req.EnterpriseMeta, req.PeerName); err != nil {
|
2022-06-13 17:52:28 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2022-07-08 17:01:13 +00:00
|
|
|
if err := b.store.DeleteNode(1, req.Node, &req.EnterpriseMeta, req.PeerName); err != nil {
|
2022-06-13 17:52:28 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-29 19:37:19 +00:00
|
|
|
func Test_ExportedServicesCount(t *testing.T) {
|
2022-07-18 17:20:04 +00:00
|
|
|
peerName := "billing"
|
|
|
|
peerID := "1fabcd52-1d46-49b0-b1d8-71559aee47f5"
|
|
|
|
|
|
|
|
srv, store := newTestServer(t, nil)
|
2022-08-01 14:33:18 +00:00
|
|
|
require.NoError(t, store.PeeringWrite(31, &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
ID: peerID,
|
|
|
|
Name: peerName,
|
|
|
|
},
|
|
|
|
}))
|
2022-07-18 17:20:04 +00:00
|
|
|
|
|
|
|
// connect the stream
|
|
|
|
mst, err := srv.Tracker.Connected(peerID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-09-29 19:37:19 +00:00
|
|
|
services := []string{"web", "api", "mongo"}
|
|
|
|
update := cache.UpdateEvent{
|
|
|
|
CorrelationID: subExportedServiceList,
|
|
|
|
Result: &pbpeerstream.ExportedServiceList{
|
|
|
|
Services: services,
|
|
|
|
}}
|
|
|
|
_, err = makeExportedServiceListResponse(mst, update)
|
|
|
|
require.NoError(t, err)
|
|
|
|
// Test the count and contents separately to ensure the count code path is hit.
|
|
|
|
require.Equal(t, 3, mst.GetExportedServicesCount())
|
|
|
|
require.ElementsMatch(t, services, mst.ExportedServices)
|
2022-07-18 17:20:04 +00:00
|
|
|
}
|
|
|
|
|
2022-05-12 21:04:44 +00:00
|
|
|
func Test_processResponse_Validation(t *testing.T) {
|
2022-07-15 17:20:43 +00:00
|
|
|
peerName := "billing"
|
|
|
|
peerID := "1fabcd52-1d46-49b0-b1d8-71559aee47f5"
|
|
|
|
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
type testCase struct {
|
|
|
|
name string
|
2022-07-08 17:01:13 +00:00
|
|
|
in *pbpeerstream.ReplicationMessage_Response
|
|
|
|
expect *pbpeerstream.ReplicationMessage
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
wantErr bool
|
|
|
|
}
|
|
|
|
|
2022-07-15 17:20:43 +00:00
|
|
|
srv, store := newTestServer(t, nil)
|
2022-08-01 14:33:18 +00:00
|
|
|
require.NoError(t, store.PeeringWrite(31, &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
ID: peerID,
|
|
|
|
Name: peerName,
|
|
|
|
},
|
|
|
|
}))
|
2022-07-15 17:20:43 +00:00
|
|
|
|
|
|
|
// connect the stream
|
|
|
|
mst, err := srv.Tracker.Connected(peerID)
|
|
|
|
require.NoError(t, err)
|
2022-05-12 21:04:44 +00:00
|
|
|
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
run := func(t *testing.T, tc testCase) {
|
2022-08-22 14:09:47 +00:00
|
|
|
reply, err := srv.processResponse(peerName, "", mst, tc.in)
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
if tc.wantErr {
|
|
|
|
require.Error(t, err)
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
require.Equal(t, tc.expect, reply)
|
|
|
|
}
|
|
|
|
|
|
|
|
tt := []testCase{
|
|
|
|
{
|
|
|
|
name: "valid upsert",
|
2022-07-08 17:01:13 +00:00
|
|
|
in: &pbpeerstream.ReplicationMessage_Response{
|
2022-07-15 20:03:40 +00:00
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
ResourceID: "api",
|
|
|
|
Nonce: "1",
|
2022-07-08 17:01:13 +00:00
|
|
|
Operation: pbpeerstream.Operation_OPERATION_UPSERT,
|
2022-07-15 20:03:40 +00:00
|
|
|
Resource: makeAnyPB(t, &pbpeerstream.ExportedService{}),
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
2022-07-08 17:01:13 +00:00
|
|
|
expect: &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Request_{
|
|
|
|
Request: &pbpeerstream.ReplicationMessage_Request{
|
2022-07-15 20:03:40 +00:00
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
2022-07-13 15:00:35 +00:00
|
|
|
ResponseNonce: "1",
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid resource url",
|
2022-07-08 17:01:13 +00:00
|
|
|
in: &pbpeerstream.ReplicationMessage_Response{
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
ResourceURL: "nomad.Job",
|
|
|
|
Nonce: "1",
|
2022-07-08 17:01:13 +00:00
|
|
|
Operation: pbpeerstream.Operation_OPERATION_UNSPECIFIED,
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
2022-07-08 17:01:13 +00:00
|
|
|
expect: &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Request_{
|
|
|
|
Request: &pbpeerstream.ReplicationMessage_Request{
|
2022-07-13 15:00:35 +00:00
|
|
|
ResourceURL: "nomad.Job",
|
|
|
|
ResponseNonce: "1",
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
Error: &pbstatus.Status{
|
|
|
|
Code: int32(code.Code_INVALID_ARGUMENT),
|
|
|
|
Message: `received response for unknown resource type "nomad.Job"`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
2022-10-12 01:02:04 +00:00
|
|
|
{
|
|
|
|
name: "missing a nonce",
|
|
|
|
in: &pbpeerstream.ReplicationMessage_Response{
|
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
|
|
|
ResourceID: "web",
|
|
|
|
Nonce: "",
|
|
|
|
Operation: pbpeerstream.Operation_OPERATION_UNSPECIFIED,
|
|
|
|
},
|
|
|
|
expect: &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Request_{
|
|
|
|
Request: &pbpeerstream.ReplicationMessage_Request{
|
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
|
|
|
ResponseNonce: "",
|
|
|
|
Error: &pbstatus.Status{
|
|
|
|
Code: int32(code.Code_INVALID_ARGUMENT),
|
|
|
|
Message: fmt.Sprintf(`received response without a nonce for: %s:web`, pbpeerstream.TypeURLExportedService),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
{
|
|
|
|
name: "unknown operation",
|
2022-07-08 17:01:13 +00:00
|
|
|
in: &pbpeerstream.ReplicationMessage_Response{
|
2022-07-15 20:03:40 +00:00
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
Nonce: "1",
|
2022-07-08 17:01:13 +00:00
|
|
|
Operation: pbpeerstream.Operation_OPERATION_UNSPECIFIED,
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
2022-07-08 17:01:13 +00:00
|
|
|
expect: &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Request_{
|
|
|
|
Request: &pbpeerstream.ReplicationMessage_Request{
|
2022-07-15 20:03:40 +00:00
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
2022-07-13 15:00:35 +00:00
|
|
|
ResponseNonce: "1",
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
Error: &pbstatus.Status{
|
|
|
|
Code: int32(code.Code_INVALID_ARGUMENT),
|
2022-07-08 17:01:13 +00:00
|
|
|
Message: `unsupported operation: "OPERATION_UNSPECIFIED"`,
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "out of range operation",
|
2022-07-08 17:01:13 +00:00
|
|
|
in: &pbpeerstream.ReplicationMessage_Response{
|
2022-07-15 20:03:40 +00:00
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
Nonce: "1",
|
2022-07-08 17:01:13 +00:00
|
|
|
Operation: pbpeerstream.Operation(100000),
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
2022-07-08 17:01:13 +00:00
|
|
|
expect: &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Request_{
|
|
|
|
Request: &pbpeerstream.ReplicationMessage_Request{
|
2022-07-15 20:03:40 +00:00
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
2022-07-13 15:00:35 +00:00
|
|
|
ResponseNonce: "1",
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
Error: &pbstatus.Status{
|
|
|
|
Code: int32(code.Code_INVALID_ARGUMENT),
|
2022-05-19 21:37:52 +00:00
|
|
|
Message: `unsupported operation: 100000`,
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range tt {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
run(t, tc)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-05-19 21:37:52 +00:00
|
|
|
|
2022-07-13 15:00:35 +00:00
|
|
|
// writePeeringToDialFrom creates a peering with the provided name and ensures
|
2022-05-19 21:37:52 +00:00
|
|
|
// the PeerID field is set for the ID of the remote peer.
|
2022-07-13 15:00:35 +00:00
|
|
|
func writePeeringToDialFrom(t *testing.T, store *state.Store, idx uint64, peerName string) *pbpeering.Peering {
|
2022-05-19 21:37:52 +00:00
|
|
|
remotePeerID, err := uuid.GenerateUUID()
|
|
|
|
require.NoError(t, err)
|
2022-07-13 15:00:35 +00:00
|
|
|
return writeTestPeering(t, store, idx, peerName, remotePeerID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// writePeeringToBeDialed creates a peering with the provided name and ensures
|
|
|
|
// the PeerID field is NOT set for the ID of the remote peer.
|
|
|
|
func writePeeringToBeDialed(t *testing.T, store *state.Store, idx uint64, peerName string) *pbpeering.Peering {
|
|
|
|
return writeTestPeering(t, store, idx, peerName, "")
|
|
|
|
}
|
2022-05-19 21:37:52 +00:00
|
|
|
|
2022-07-13 15:00:35 +00:00
|
|
|
func writeTestPeering(t *testing.T, store *state.Store, idx uint64, peerName, remotePeerID string) *pbpeering.Peering {
|
2022-05-19 21:37:52 +00:00
|
|
|
peering := pbpeering.Peering{
|
2022-08-01 14:33:18 +00:00
|
|
|
ID: testPeerID,
|
2022-05-19 21:37:52 +00:00
|
|
|
Name: peerName,
|
|
|
|
PeerID: remotePeerID,
|
|
|
|
}
|
2022-08-01 14:33:18 +00:00
|
|
|
if remotePeerID != "" {
|
|
|
|
peering.PeerServerAddresses = []string{"127.0.0.1:5300"}
|
|
|
|
}
|
2022-08-08 07:41:00 +00:00
|
|
|
|
2022-08-01 14:33:18 +00:00
|
|
|
require.NoError(t, store.PeeringWrite(idx, &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &peering,
|
2022-08-08 07:41:00 +00:00
|
|
|
SecretsRequest: &pbpeering.SecretsWriteRequest{
|
|
|
|
PeerID: testPeerID,
|
|
|
|
// Simulate generating a stream secret by first generating a token then exchanging for a stream secret.
|
|
|
|
Request: &pbpeering.SecretsWriteRequest_GenerateToken{
|
|
|
|
GenerateToken: &pbpeering.SecretsWriteRequest_GenerateTokenRequest{
|
|
|
|
EstablishmentSecret: testEstablishmentSecretID,
|
2022-08-02 22:20:07 +00:00
|
|
|
},
|
2022-08-01 14:33:18 +00:00
|
|
|
},
|
2022-08-08 07:41:00 +00:00
|
|
|
},
|
|
|
|
}))
|
|
|
|
require.NoError(t, store.PeeringSecretsWrite(idx, &pbpeering.SecretsWriteRequest{
|
|
|
|
PeerID: testPeerID,
|
|
|
|
Request: &pbpeering.SecretsWriteRequest_ExchangeSecret{
|
|
|
|
ExchangeSecret: &pbpeering.SecretsWriteRequest_ExchangeSecretRequest{
|
2022-08-08 15:06:07 +00:00
|
|
|
EstablishmentSecret: testEstablishmentSecretID,
|
2022-08-08 07:41:00 +00:00
|
|
|
PendingStreamSecret: testPendingStreamSecretID,
|
|
|
|
},
|
2022-08-01 14:33:18 +00:00
|
|
|
},
|
|
|
|
}))
|
2022-05-19 21:37:52 +00:00
|
|
|
|
|
|
|
_, p, err := store.PeeringRead(nil, state.Query{Value: peerName})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2022-05-26 19:24:09 +00:00
|
|
|
func writeInitialRootsAndCA(t *testing.T, store *state.Store) (string, *structs.CARoot) {
|
2022-05-25 17:37:44 +00:00
|
|
|
const clusterID = connect.TestClusterID
|
|
|
|
|
|
|
|
rootA := connect.TestCA(t, nil)
|
|
|
|
_, err := store.CARootSetCAS(1, 0, structs.CARoots{rootA})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = store.CASetConfig(0, &structs.CAConfiguration{ClusterID: clusterID})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-26 19:24:09 +00:00
|
|
|
return clusterID, rootA
|
2022-05-25 17:37:44 +00:00
|
|
|
}
|
|
|
|
|
2022-08-01 21:06:18 +00:00
|
|
|
func makeAnyPB(t *testing.T, pb newproto.Message) *anypb.Any {
|
2022-07-15 20:03:40 +00:00
|
|
|
any, err := anypb.New(pb)
|
2022-05-19 21:37:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
return any
|
|
|
|
}
|
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
func expectReplEvents(t *testing.T, client *MockClient, checkFns ...func(t *testing.T, got *pbpeerstream.ReplicationMessage)) {
|
2022-05-19 21:37:52 +00:00
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
num := len(checkFns)
|
|
|
|
|
|
|
|
if num == 0 {
|
|
|
|
// No updates should be received.
|
|
|
|
msg, err := client.RecvWithTimeout(100 * time.Millisecond)
|
|
|
|
if err == io.EOF && msg == nil {
|
|
|
|
return
|
|
|
|
} else if err != nil {
|
|
|
|
t.Fatalf("received unexpected update error: %v", err)
|
|
|
|
} else {
|
|
|
|
t.Fatalf("received unexpected update: %+v", msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-09 16:05:18 +00:00
|
|
|
const timeout = 10 * time.Second
|
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
var out []*pbpeerstream.ReplicationMessage
|
2022-05-19 21:37:52 +00:00
|
|
|
for len(out) < num {
|
2022-06-09 16:05:18 +00:00
|
|
|
msg, err := client.RecvWithTimeout(timeout)
|
2022-05-19 21:37:52 +00:00
|
|
|
if err == io.EOF && msg == nil {
|
|
|
|
t.Fatalf("timed out with %d of %d events", len(out), num)
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
out = append(out, msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg, err := client.RecvWithTimeout(100 * time.Millisecond); err != io.EOF || msg != nil {
|
|
|
|
t.Fatalf("expected only %d events but got more; prev %+v; next %+v", num, out, msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Len(t, out, num)
|
|
|
|
|
|
|
|
sort.SliceStable(out, func(i, j int) bool {
|
|
|
|
a, b := out[i], out[j]
|
|
|
|
|
|
|
|
typeA := fmt.Sprintf("%T", a.GetPayload())
|
|
|
|
typeB := fmt.Sprintf("%T", b.GetPayload())
|
|
|
|
if typeA != typeB {
|
|
|
|
return typeA < typeB
|
|
|
|
}
|
|
|
|
|
|
|
|
switch a.GetPayload().(type) {
|
2022-07-08 17:01:13 +00:00
|
|
|
case *pbpeerstream.ReplicationMessage_Request_:
|
2022-05-19 21:37:52 +00:00
|
|
|
reqA, reqB := a.GetRequest(), b.GetRequest()
|
|
|
|
if reqA.ResourceURL != reqB.ResourceURL {
|
|
|
|
return reqA.ResourceURL < reqB.ResourceURL
|
|
|
|
}
|
2022-07-13 15:00:35 +00:00
|
|
|
return reqA.ResponseNonce < reqB.ResponseNonce
|
2022-05-19 21:37:52 +00:00
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
case *pbpeerstream.ReplicationMessage_Response_:
|
2022-05-19 21:37:52 +00:00
|
|
|
respA, respB := a.GetResponse(), b.GetResponse()
|
|
|
|
if respA.ResourceURL != respB.ResourceURL {
|
|
|
|
return respA.ResourceURL < respB.ResourceURL
|
|
|
|
}
|
|
|
|
if respA.ResourceID != respB.ResourceID {
|
|
|
|
return respA.ResourceID < respB.ResourceID
|
|
|
|
}
|
|
|
|
return respA.Nonce < respB.Nonce
|
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
case *pbpeerstream.ReplicationMessage_Terminated_:
|
2022-05-19 21:37:52 +00:00
|
|
|
return false
|
|
|
|
|
|
|
|
default:
|
|
|
|
panic("unknown type")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-10-12 01:02:04 +00:00
|
|
|
nonces := make(map[string]struct{})
|
2022-05-19 21:37:52 +00:00
|
|
|
for i := 0; i < num; i++ {
|
|
|
|
checkFns[i](t, out[i])
|
2022-10-12 01:02:04 +00:00
|
|
|
|
|
|
|
// Ensure every nonce was unique.
|
|
|
|
if resp := out[i].GetResponse(); resp != nil {
|
|
|
|
require.NotContains(t, nonces, resp.Nonce)
|
|
|
|
}
|
2022-05-19 21:37:52 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-13 17:52:28 +00:00
|
|
|
|
2022-09-29 19:37:19 +00:00
|
|
|
func Test_processResponse_ExportedServiceUpdates(t *testing.T) {
|
2022-07-15 17:20:43 +00:00
|
|
|
srv, store := newTestServer(t, func(c *Config) {
|
2022-07-08 17:01:13 +00:00
|
|
|
backend := c.Backend.(*testStreamBackend)
|
|
|
|
backend.leader = func() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
2022-06-13 17:52:28 +00:00
|
|
|
|
|
|
|
type testCase struct {
|
2022-09-29 19:37:19 +00:00
|
|
|
name string
|
|
|
|
seed []*structs.RegisterRequest
|
|
|
|
input *pbpeerstream.ExportedService
|
|
|
|
expect map[string]structs.CheckServiceNodes
|
|
|
|
exportedServices []string
|
2022-06-13 17:52:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
peerName := "billing"
|
2022-07-15 17:20:43 +00:00
|
|
|
peerID := "1fabcd52-1d46-49b0-b1d8-71559aee47f5"
|
2022-06-13 17:52:28 +00:00
|
|
|
remoteMeta := pbcommon.NewEnterpriseMetaFromStructs(*structs.DefaultEnterpriseMetaInPartition("billing-ap"))
|
|
|
|
|
|
|
|
// "api" service is imported from the billing-ap partition, corresponding to the billing peer.
|
|
|
|
// Locally it is stored to the default partition.
|
|
|
|
defaultMeta := *acl.DefaultEnterpriseMeta()
|
|
|
|
apiSN := structs.NewServiceName("api", &defaultMeta)
|
|
|
|
|
2022-07-15 17:20:43 +00:00
|
|
|
// create a peering in the state store
|
2022-08-01 14:33:18 +00:00
|
|
|
require.NoError(t, store.PeeringWrite(31, &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
ID: peerID,
|
|
|
|
Name: peerName,
|
|
|
|
},
|
|
|
|
}))
|
2022-07-15 17:20:43 +00:00
|
|
|
|
|
|
|
// connect the stream
|
|
|
|
mst, err := srv.Tracker.Connected(peerID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-06-13 17:52:28 +00:00
|
|
|
run := func(t *testing.T, tc testCase) {
|
|
|
|
// Seed the local catalog with some data to reconcile against.
|
2022-07-15 17:20:43 +00:00
|
|
|
// and increment the tracker's imported services count
|
2022-09-29 19:37:19 +00:00
|
|
|
var serviceNames []structs.ServiceName
|
2022-06-13 17:52:28 +00:00
|
|
|
for _, reg := range tc.seed {
|
2022-07-08 17:01:13 +00:00
|
|
|
require.NoError(t, srv.Backend.CatalogRegister(reg))
|
2022-07-15 17:20:43 +00:00
|
|
|
|
2022-09-29 19:37:19 +00:00
|
|
|
sn := reg.Service.CompoundServiceName()
|
|
|
|
serviceNames = append(serviceNames, sn)
|
2022-07-15 17:20:43 +00:00
|
|
|
}
|
2022-09-29 19:37:19 +00:00
|
|
|
mst.SetImportedServices(serviceNames)
|
2022-07-15 17:20:43 +00:00
|
|
|
|
|
|
|
in := &pbpeerstream.ReplicationMessage_Response{
|
2022-07-15 20:03:40 +00:00
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedService,
|
2022-07-15 17:20:43 +00:00
|
|
|
ResourceID: apiSN.String(),
|
|
|
|
Nonce: "1",
|
2022-09-29 19:37:19 +00:00
|
|
|
Operation: pbpeerstream.Operation_OPERATION_UPSERT,
|
2022-07-15 17:20:43 +00:00
|
|
|
Resource: makeAnyPB(t, tc.input),
|
2022-06-13 17:52:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Simulate an update arriving for billing/api.
|
2022-08-22 14:09:47 +00:00
|
|
|
_, err = srv.processResponse(peerName, acl.DefaultPartitionName, mst, in)
|
2022-07-15 17:20:43 +00:00
|
|
|
require.NoError(t, err)
|
2022-06-13 17:52:28 +00:00
|
|
|
|
2022-09-29 19:37:19 +00:00
|
|
|
if len(tc.exportedServices) > 0 {
|
|
|
|
resp := &pbpeerstream.ReplicationMessage_Response{
|
|
|
|
ResourceURL: pbpeerstream.TypeURLExportedServiceList,
|
|
|
|
ResourceID: subExportedServiceList,
|
2022-10-12 01:02:04 +00:00
|
|
|
Nonce: "2",
|
2022-09-29 19:37:19 +00:00
|
|
|
Operation: pbpeerstream.Operation_OPERATION_UPSERT,
|
|
|
|
Resource: makeAnyPB(t, &pbpeerstream.ExportedServiceList{Services: tc.exportedServices}),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simulate an update arriving for billing/api.
|
|
|
|
_, err = srv.processResponse(peerName, acl.DefaultPartitionName, mst, resp)
|
|
|
|
require.NoError(t, err)
|
|
|
|
// Test the count and contents separately to ensure the count code path is hit.
|
|
|
|
require.Equal(t, mst.GetImportedServicesCount(), len(tc.exportedServices))
|
|
|
|
require.ElementsMatch(t, mst.ImportedServices, tc.exportedServices)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, allServices, err := srv.GetStore().ServiceList(nil, &defaultMeta, peerName)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// This ensures that only services specified under tc.expect are stored. It includes
|
|
|
|
// all exported services plus their sidecar proxies.
|
|
|
|
for _, svc := range allServices {
|
|
|
|
_, ok := tc.expect[svc.Name]
|
|
|
|
require.True(t, ok)
|
|
|
|
}
|
|
|
|
|
2022-06-13 17:52:28 +00:00
|
|
|
for svc, expect := range tc.expect {
|
|
|
|
t.Run(svc, func(t *testing.T) {
|
2022-07-08 17:01:13 +00:00
|
|
|
_, got, err := srv.GetStore().CheckServiceNodes(nil, svc, &defaultMeta, peerName)
|
2022-06-13 17:52:28 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
requireEqualInstances(t, expect, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tt := []testCase{
|
|
|
|
{
|
2022-09-29 19:37:19 +00:00
|
|
|
name: "upsert two service instances to the same node",
|
|
|
|
exportedServices: []string{"api"},
|
2022-07-15 20:03:40 +00:00
|
|
|
input: &pbpeerstream.ExportedService{
|
2022-06-13 17:52:28 +00:00
|
|
|
Nodes: []*pbservice.CheckServiceNode{
|
|
|
|
{
|
|
|
|
Node: &pbservice.Node{
|
|
|
|
ID: "af913374-68ea-41e5-82e8-6ffd3dffc461",
|
|
|
|
Node: "node-foo",
|
|
|
|
Partition: remoteMeta.Partition,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Service: &pbservice.NodeService{
|
|
|
|
ID: "api-1",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: remoteMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: []*pbservice.HealthCheck{
|
|
|
|
{
|
|
|
|
CheckID: "node-foo-check",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: remoteMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CheckID: "api-1-check",
|
|
|
|
ServiceID: "api-1",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: remoteMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Node: &pbservice.Node{
|
|
|
|
ID: "af913374-68ea-41e5-82e8-6ffd3dffc461",
|
|
|
|
Node: "node-foo",
|
|
|
|
Partition: remoteMeta.Partition,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Service: &pbservice.NodeService{
|
|
|
|
ID: "api-2",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: remoteMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: []*pbservice.HealthCheck{
|
|
|
|
{
|
|
|
|
CheckID: "node-foo-check",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: remoteMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CheckID: "api-2-check",
|
|
|
|
ServiceID: "api-2",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: remoteMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: map[string]structs.CheckServiceNodes{
|
|
|
|
"api": {
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "af913374-68ea-41e5-82e8-6ffd3dffc461",
|
|
|
|
Node: "node-foo",
|
|
|
|
|
|
|
|
// The remote billing-ap partition is overwritten for all resources with the local default.
|
|
|
|
Partition: defaultMeta.PartitionOrEmpty(),
|
|
|
|
|
|
|
|
// The name of the peer "billing" is attached as well.
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "api-1",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: []*structs.HealthCheck{
|
|
|
|
{
|
|
|
|
CheckID: "node-foo-check",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CheckID: "api-1-check",
|
|
|
|
ServiceID: "api-1",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "af913374-68ea-41e5-82e8-6ffd3dffc461",
|
|
|
|
Node: "node-foo",
|
|
|
|
Partition: defaultMeta.PartitionOrEmpty(),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "api-2",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: []*structs.HealthCheck{
|
|
|
|
{
|
|
|
|
CheckID: "node-foo-check",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CheckID: "api-2-check",
|
|
|
|
ServiceID: "api-2",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-09-29 19:37:19 +00:00
|
|
|
name: "deleting a service with an empty exported service event",
|
|
|
|
exportedServices: []string{"api"},
|
|
|
|
seed: []*structs.RegisterRequest{
|
|
|
|
{
|
|
|
|
ID: types.NodeID("af913374-68ea-41e5-82e8-6ffd3dffc461"),
|
|
|
|
Node: "node-foo",
|
|
|
|
PeerName: peerName,
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "api-2",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
ServiceID: "api-2",
|
|
|
|
CheckID: types.CheckID("api-2-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
CheckID: types.CheckID("node-foo-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
input: &pbpeerstream.ExportedService{},
|
|
|
|
expect: map[string]structs.CheckServiceNodes{
|
|
|
|
"api": {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "upsert two service instances to different nodes",
|
|
|
|
exportedServices: []string{"api"},
|
2022-07-15 20:03:40 +00:00
|
|
|
input: &pbpeerstream.ExportedService{
|
2022-06-13 17:52:28 +00:00
|
|
|
Nodes: []*pbservice.CheckServiceNode{
|
|
|
|
{
|
|
|
|
Node: &pbservice.Node{
|
|
|
|
ID: "af913374-68ea-41e5-82e8-6ffd3dffc461",
|
|
|
|
Node: "node-foo",
|
|
|
|
Partition: remoteMeta.Partition,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Service: &pbservice.NodeService{
|
|
|
|
ID: "api-1",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: remoteMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: []*pbservice.HealthCheck{
|
|
|
|
{
|
|
|
|
CheckID: "node-foo-check",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: remoteMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CheckID: "api-1-check",
|
|
|
|
ServiceID: "api-1",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: remoteMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Node: &pbservice.Node{
|
|
|
|
ID: "c0f97de9-4e1b-4e80-a1c6-cd8725835ab2",
|
|
|
|
Node: "node-bar",
|
|
|
|
Partition: remoteMeta.Partition,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Service: &pbservice.NodeService{
|
|
|
|
ID: "api-2",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: remoteMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: []*pbservice.HealthCheck{
|
|
|
|
{
|
|
|
|
CheckID: "node-bar-check",
|
|
|
|
Node: "node-bar",
|
|
|
|
EnterpriseMeta: remoteMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CheckID: "api-2-check",
|
|
|
|
ServiceID: "api-2",
|
|
|
|
Node: "node-bar",
|
|
|
|
EnterpriseMeta: remoteMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: map[string]structs.CheckServiceNodes{
|
|
|
|
"api": {
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "c0f97de9-4e1b-4e80-a1c6-cd8725835ab2",
|
|
|
|
Node: "node-bar",
|
|
|
|
Partition: defaultMeta.PartitionOrEmpty(),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "api-2",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: []*structs.HealthCheck{
|
|
|
|
{
|
|
|
|
CheckID: "node-bar-check",
|
|
|
|
Node: "node-bar",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CheckID: "api-2-check",
|
|
|
|
ServiceID: "api-2",
|
|
|
|
Node: "node-bar",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "af913374-68ea-41e5-82e8-6ffd3dffc461",
|
|
|
|
Node: "node-foo",
|
|
|
|
|
|
|
|
// The remote billing-ap partition is overwritten for all resources with the local default.
|
|
|
|
Partition: defaultMeta.PartitionOrEmpty(),
|
|
|
|
|
|
|
|
// The name of the peer "billing" is attached as well.
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "api-1",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: []*structs.HealthCheck{
|
|
|
|
{
|
|
|
|
CheckID: "node-foo-check",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CheckID: "api-1-check",
|
|
|
|
ServiceID: "api-1",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-09-29 19:37:19 +00:00
|
|
|
name: "deleting one service name from a node does not delete other service names",
|
|
|
|
exportedServices: []string{"api", "redis"},
|
2022-06-13 17:52:28 +00:00
|
|
|
seed: []*structs.RegisterRequest{
|
|
|
|
{
|
2022-09-29 19:37:19 +00:00
|
|
|
ID: types.NodeID("af913374-68ea-41e5-82e8-6ffd3dffc461"),
|
|
|
|
Node: "node-foo",
|
2022-06-13 17:52:28 +00:00
|
|
|
PeerName: peerName,
|
|
|
|
Service: &structs.NodeService{
|
2022-09-29 19:37:19 +00:00
|
|
|
ID: "redis-2",
|
|
|
|
Service: "redis",
|
2022-06-13 17:52:28 +00:00
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{
|
2022-09-29 19:37:19 +00:00
|
|
|
Node: "node-foo",
|
|
|
|
ServiceID: "redis-2",
|
|
|
|
CheckID: types.CheckID("redis-2-check"),
|
2022-06-13 17:52:28 +00:00
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
2022-09-29 19:37:19 +00:00
|
|
|
Node: "node-foo",
|
|
|
|
CheckID: types.CheckID("node-foo-check"),
|
2022-06-13 17:52:28 +00:00
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: types.NodeID("af913374-68ea-41e5-82e8-6ffd3dffc461"),
|
|
|
|
Node: "node-foo",
|
|
|
|
PeerName: peerName,
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "api-1",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
ServiceID: "api-1",
|
|
|
|
CheckID: types.CheckID("api-1-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
CheckID: types.CheckID("node-foo-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-09-29 19:37:19 +00:00
|
|
|
// Nil input is for the "api" service.
|
2022-07-15 20:03:40 +00:00
|
|
|
input: &pbpeerstream.ExportedService{},
|
2022-06-13 17:52:28 +00:00
|
|
|
expect: map[string]structs.CheckServiceNodes{
|
|
|
|
"api": {},
|
2022-09-29 19:37:19 +00:00
|
|
|
// Existing redis service was not affected by deletion.
|
|
|
|
"redis": {
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "af913374-68ea-41e5-82e8-6ffd3dffc461",
|
|
|
|
Node: "node-foo",
|
|
|
|
Partition: defaultMeta.PartitionOrEmpty(),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "redis-2",
|
|
|
|
Service: "redis",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: []*structs.HealthCheck{
|
|
|
|
{
|
|
|
|
CheckID: "node-foo-check",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CheckID: "redis-2-check",
|
|
|
|
ServiceID: "redis-2",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-06-13 17:52:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-09-29 19:37:19 +00:00
|
|
|
name: "unexporting a service does not delete other services",
|
2022-06-13 17:52:28 +00:00
|
|
|
seed: []*structs.RegisterRequest{
|
|
|
|
{
|
|
|
|
ID: types.NodeID("af913374-68ea-41e5-82e8-6ffd3dffc461"),
|
|
|
|
Node: "node-foo",
|
|
|
|
PeerName: peerName,
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "redis-2",
|
|
|
|
Service: "redis",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
ServiceID: "redis-2",
|
|
|
|
CheckID: types.CheckID("redis-2-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
CheckID: types.CheckID("node-foo-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-09-29 19:37:19 +00:00
|
|
|
{
|
|
|
|
ID: types.NodeID("af913374-68ea-41e5-82e8-6ffd3dffc461"),
|
|
|
|
Node: "node-foo",
|
|
|
|
PeerName: peerName,
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "redis-2-sidecar-proxy",
|
|
|
|
Service: "redis-sidecar-proxy",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
ServiceID: "redis-2-sidecar-proxy",
|
|
|
|
CheckID: types.CheckID("redis-2-sidecar-proxy-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
CheckID: types.CheckID("node-foo-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-06-13 17:52:28 +00:00
|
|
|
{
|
|
|
|
ID: types.NodeID("af913374-68ea-41e5-82e8-6ffd3dffc461"),
|
|
|
|
Node: "node-foo",
|
|
|
|
PeerName: peerName,
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "api-1",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
ServiceID: "api-1",
|
|
|
|
CheckID: types.CheckID("api-1-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
CheckID: types.CheckID("node-foo-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-09-29 19:37:19 +00:00
|
|
|
{
|
|
|
|
ID: types.NodeID("af913374-68ea-41e5-82e8-6ffd3dffc461"),
|
|
|
|
Node: "node-foo",
|
|
|
|
PeerName: peerName,
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "api-1-sidecar-proxy",
|
|
|
|
Service: "api-sidecar-proxy",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
ServiceID: "api-1-sidecar-proxy",
|
|
|
|
CheckID: types.CheckID("api-1-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
CheckID: types.CheckID("node-foo-sidecar-proxy-check"),
|
|
|
|
ServiceID: "api-1-sidecar-proxy",
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-06-13 17:52:28 +00:00
|
|
|
},
|
|
|
|
// Nil input is for the "api" service.
|
2022-09-29 19:37:19 +00:00
|
|
|
input: &pbpeerstream.ExportedService{},
|
|
|
|
exportedServices: []string{"redis"},
|
2022-06-13 17:52:28 +00:00
|
|
|
expect: map[string]structs.CheckServiceNodes{
|
|
|
|
// Existing redis service was not affected by deletion.
|
|
|
|
"redis": {
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "af913374-68ea-41e5-82e8-6ffd3dffc461",
|
|
|
|
Node: "node-foo",
|
|
|
|
Partition: defaultMeta.PartitionOrEmpty(),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "redis-2",
|
|
|
|
Service: "redis",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: []*structs.HealthCheck{
|
|
|
|
{
|
|
|
|
CheckID: "node-foo-check",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CheckID: "redis-2-check",
|
|
|
|
ServiceID: "redis-2",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-09-29 19:37:19 +00:00
|
|
|
"redis-sidecar-proxy": {
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "af913374-68ea-41e5-82e8-6ffd3dffc461",
|
|
|
|
Node: "node-foo",
|
|
|
|
Partition: defaultMeta.PartitionOrEmpty(),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "redis-2-sidecar-proxy",
|
|
|
|
Service: "redis-sidecar-proxy",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: []*structs.HealthCheck{
|
|
|
|
{
|
|
|
|
CheckID: "node-foo-check",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CheckID: "redis-2-sidecar-proxy-check",
|
|
|
|
ServiceID: "redis-2-sidecar-proxy",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-06-13 17:52:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-09-29 19:37:19 +00:00
|
|
|
name: "service checks are cleaned up when not present in a response",
|
|
|
|
exportedServices: []string{"api"},
|
2022-06-13 17:52:28 +00:00
|
|
|
seed: []*structs.RegisterRequest{
|
|
|
|
{
|
|
|
|
ID: types.NodeID("af913374-68ea-41e5-82e8-6ffd3dffc461"),
|
|
|
|
Node: "node-foo",
|
|
|
|
PeerName: peerName,
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "api-1",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
ServiceID: "api-1",
|
|
|
|
CheckID: types.CheckID("api-1-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
CheckID: types.CheckID("node-foo-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-15 20:03:40 +00:00
|
|
|
input: &pbpeerstream.ExportedService{
|
2022-06-13 17:52:28 +00:00
|
|
|
Nodes: []*pbservice.CheckServiceNode{
|
|
|
|
{
|
|
|
|
Node: &pbservice.Node{
|
|
|
|
ID: "af913374-68ea-41e5-82e8-6ffd3dffc461",
|
|
|
|
Node: "node-foo",
|
|
|
|
Partition: remoteMeta.Partition,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Service: &pbservice.NodeService{
|
|
|
|
ID: "api-1",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: remoteMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: []*pbservice.HealthCheck{
|
|
|
|
// Service check was deleted
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: map[string]structs.CheckServiceNodes{
|
|
|
|
// Service check should be gone
|
|
|
|
"api": {
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "af913374-68ea-41e5-82e8-6ffd3dffc461",
|
|
|
|
Node: "node-foo",
|
|
|
|
Partition: defaultMeta.PartitionOrEmpty(),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "api-1",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: []*structs.HealthCheck{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-09-29 19:37:19 +00:00
|
|
|
name: "node checks are cleaned up when not present in a response",
|
|
|
|
exportedServices: []string{"api", "redis"},
|
2022-06-13 17:52:28 +00:00
|
|
|
seed: []*structs.RegisterRequest{
|
|
|
|
{
|
|
|
|
ID: types.NodeID("af913374-68ea-41e5-82e8-6ffd3dffc461"),
|
|
|
|
Node: "node-foo",
|
|
|
|
PeerName: peerName,
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "redis-2",
|
|
|
|
Service: "redis",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
ServiceID: "redis-2",
|
|
|
|
CheckID: types.CheckID("redis-2-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
CheckID: types.CheckID("node-foo-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: types.NodeID("af913374-68ea-41e5-82e8-6ffd3dffc461"),
|
|
|
|
Node: "node-foo",
|
|
|
|
PeerName: peerName,
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "api-1",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
ServiceID: "api-1",
|
|
|
|
CheckID: types.CheckID("api-1-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
CheckID: types.CheckID("node-foo-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-15 20:03:40 +00:00
|
|
|
input: &pbpeerstream.ExportedService{
|
2022-06-13 17:52:28 +00:00
|
|
|
Nodes: []*pbservice.CheckServiceNode{
|
|
|
|
{
|
|
|
|
Node: &pbservice.Node{
|
|
|
|
ID: "af913374-68ea-41e5-82e8-6ffd3dffc461",
|
|
|
|
Node: "node-foo",
|
|
|
|
Partition: remoteMeta.Partition,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Service: &pbservice.NodeService{
|
|
|
|
ID: "api-1",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: remoteMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: []*pbservice.HealthCheck{
|
|
|
|
// Node check was deleted
|
|
|
|
{
|
|
|
|
CheckID: "api-1-check",
|
|
|
|
ServiceID: "api-1",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: remoteMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: map[string]structs.CheckServiceNodes{
|
|
|
|
// Node check should be gone
|
|
|
|
"api": {
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "af913374-68ea-41e5-82e8-6ffd3dffc461",
|
|
|
|
Node: "node-foo",
|
|
|
|
Partition: defaultMeta.PartitionOrEmpty(),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "api-1",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: []*structs.HealthCheck{
|
|
|
|
{
|
|
|
|
CheckID: "api-1-check",
|
|
|
|
ServiceID: "api-1",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"redis": {
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "af913374-68ea-41e5-82e8-6ffd3dffc461",
|
|
|
|
Node: "node-foo",
|
|
|
|
Partition: defaultMeta.PartitionOrEmpty(),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "redis-2",
|
|
|
|
Service: "redis",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: []*structs.HealthCheck{
|
|
|
|
{
|
|
|
|
CheckID: "redis-2-check",
|
|
|
|
ServiceID: "redis-2",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-09-29 19:37:19 +00:00
|
|
|
name: "replacing a service instance on a node cleans up the old instance",
|
|
|
|
exportedServices: []string{"api", "redis"},
|
2022-06-13 17:52:28 +00:00
|
|
|
seed: []*structs.RegisterRequest{
|
|
|
|
{
|
|
|
|
ID: types.NodeID("af913374-68ea-41e5-82e8-6ffd3dffc461"),
|
|
|
|
Node: "node-foo",
|
|
|
|
PeerName: peerName,
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "redis-2",
|
|
|
|
Service: "redis",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
ServiceID: "redis-2",
|
|
|
|
CheckID: types.CheckID("redis-2-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
CheckID: types.CheckID("node-foo-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: types.NodeID("af913374-68ea-41e5-82e8-6ffd3dffc461"),
|
|
|
|
Node: "node-foo",
|
|
|
|
PeerName: peerName,
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "api-1",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
ServiceID: "api-1",
|
|
|
|
CheckID: types.CheckID("api-1-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
CheckID: types.CheckID("node-foo-check"),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-15 20:03:40 +00:00
|
|
|
input: &pbpeerstream.ExportedService{
|
2022-06-13 17:52:28 +00:00
|
|
|
Nodes: []*pbservice.CheckServiceNode{
|
|
|
|
{
|
|
|
|
Node: &pbservice.Node{
|
|
|
|
ID: "af913374-68ea-41e5-82e8-6ffd3dffc461",
|
|
|
|
Node: "node-foo",
|
|
|
|
Partition: remoteMeta.Partition,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
// New service ID and checks for the api service.
|
|
|
|
Service: &pbservice.NodeService{
|
|
|
|
ID: "new-api-v2",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: remoteMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: []*pbservice.HealthCheck{
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
ServiceID: "new-api-v2",
|
|
|
|
CheckID: "new-api-v2-check",
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
CheckID: "node-foo-check",
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: map[string]structs.CheckServiceNodes{
|
|
|
|
"api": {
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "af913374-68ea-41e5-82e8-6ffd3dffc461",
|
|
|
|
Node: "node-foo",
|
|
|
|
Partition: defaultMeta.PartitionOrEmpty(),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "new-api-v2",
|
|
|
|
Service: "api",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: []*structs.HealthCheck{
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
CheckID: "node-foo-check",
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CheckID: "new-api-v2-check",
|
|
|
|
ServiceID: "new-api-v2",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"redis": {
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "af913374-68ea-41e5-82e8-6ffd3dffc461",
|
|
|
|
Node: "node-foo",
|
|
|
|
Partition: defaultMeta.PartitionOrEmpty(),
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
ID: "redis-2",
|
|
|
|
Service: "redis",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
Checks: []*structs.HealthCheck{
|
|
|
|
{
|
|
|
|
Node: "node-foo",
|
|
|
|
CheckID: "node-foo-check",
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CheckID: "redis-2-check",
|
|
|
|
ServiceID: "redis-2",
|
|
|
|
Node: "node-foo",
|
|
|
|
EnterpriseMeta: defaultMeta,
|
|
|
|
PeerName: peerName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tt {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
run(t, tc)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-01 21:06:18 +00:00
|
|
|
// TestLogTraceProto tests that all PB trace log helpers redact the
|
|
|
|
// long-lived SecretStreamID.
|
|
|
|
// We ensure it gets redacted when logging a ReplicationMessage_Open or a ReplicationMessage.
|
|
|
|
// In the stream handler we only log the ReplicationMessage_Open, but testing both guards against
|
|
|
|
// a change in that behavior.
|
|
|
|
func TestLogTraceProto(t *testing.T) {
|
|
|
|
type testCase struct {
|
|
|
|
input proto.Message
|
|
|
|
}
|
|
|
|
|
|
|
|
tt := map[string]testCase{
|
|
|
|
"replication message": {
|
|
|
|
input: &pbpeerstream.ReplicationMessage{
|
|
|
|
Payload: &pbpeerstream.ReplicationMessage_Open_{
|
|
|
|
Open: &pbpeerstream.ReplicationMessage_Open{
|
|
|
|
StreamSecretID: testPendingStreamSecretID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"open message": {
|
|
|
|
input: &pbpeerstream.ReplicationMessage_Open{
|
|
|
|
StreamSecretID: testPendingStreamSecretID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for name, tc := range tt {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
var b bytes.Buffer
|
|
|
|
logger, err := logging.Setup(logging.Config{
|
|
|
|
LogLevel: "TRACE",
|
|
|
|
}, &b)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
logTraceRecv(logger, tc.input)
|
|
|
|
logTraceSend(logger, tc.input)
|
|
|
|
logTraceProto(logger, tc.input, false)
|
|
|
|
|
|
|
|
body, err := io.ReadAll(&b)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotContains(t, string(body), testPendingStreamSecretID)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-13 17:52:28 +00:00
|
|
|
func requireEqualInstances(t *testing.T, expect, got structs.CheckServiceNodes) {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
require.Equal(t, len(expect), len(got), "got differing number of instances")
|
|
|
|
|
|
|
|
for i := range expect {
|
|
|
|
// Node equality
|
|
|
|
require.Equal(t, expect[i].Node.ID, got[i].Node.ID, "node mismatch")
|
|
|
|
require.Equal(t, expect[i].Node.Partition, got[i].Node.Partition, "partition mismatch")
|
|
|
|
require.Equal(t, expect[i].Node.PeerName, got[i].Node.PeerName, "peer name mismatch")
|
|
|
|
|
|
|
|
// Service equality
|
|
|
|
require.Equal(t, expect[i].Service.ID, got[i].Service.ID, "service id mismatch")
|
|
|
|
require.Equal(t, expect[i].Service.PeerName, got[i].Service.PeerName, "peer name mismatch")
|
|
|
|
require.Equal(t, expect[i].Service.PartitionOrDefault(), got[i].Service.PartitionOrDefault(), "partition mismatch")
|
|
|
|
|
|
|
|
// Check equality
|
|
|
|
require.Equal(t, len(expect[i].Checks), len(got[i].Checks), "got differing number of check")
|
|
|
|
|
|
|
|
for j := range expect[i].Checks {
|
|
|
|
require.Equal(t, expect[i].Checks[j].CheckID, got[i].Checks[j].CheckID, "check id mismatch")
|
|
|
|
require.Equal(t, expect[i].Checks[j].PeerName, got[i].Checks[j].PeerName, "peer name mismatch")
|
|
|
|
require.Equal(t, expect[i].Checks[j].PartitionOrDefault(), got[i].Checks[j].PartitionOrDefault(), "partition mismatch")
|
|
|
|
}
|
|
|
|
}
|
2022-06-21 18:04:08 +00:00
|
|
|
}
|
2022-06-13 17:52:28 +00:00
|
|
|
|
2022-07-08 17:01:13 +00:00
|
|
|
type testServer struct {
|
|
|
|
*Server
|
2022-08-22 14:22:11 +00:00
|
|
|
|
|
|
|
// mockSnapshotHandler is solely used for handling autopilot events
|
|
|
|
// which don't come from the state store.
|
|
|
|
mockSnapshotHandler *mockSnapshotHandler
|
2022-07-08 17:01:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newTestServer(t *testing.T, configFn func(c *Config)) (*testServer, *state.Store) {
|
2022-08-22 14:22:11 +00:00
|
|
|
t.Helper()
|
2022-07-08 17:01:13 +00:00
|
|
|
publisher := stream.NewEventPublisher(10 * time.Second)
|
2022-08-22 14:22:11 +00:00
|
|
|
store, handler := newStateStore(t, publisher)
|
2022-07-08 17:01:13 +00:00
|
|
|
|
|
|
|
ports := freeport.GetN(t, 1) // {grpc}
|
|
|
|
|
|
|
|
cfg := Config{
|
|
|
|
Backend: &testStreamBackend{
|
|
|
|
store: store,
|
|
|
|
pub: publisher,
|
|
|
|
},
|
|
|
|
GetStore: func() StateStore { return store },
|
|
|
|
Logger: testutil.Logger(t),
|
|
|
|
Datacenter: "dc1",
|
|
|
|
ConnectEnabled: true,
|
2022-08-01 14:33:18 +00:00
|
|
|
ForwardRPC: noopForwardRPC,
|
2022-07-08 17:01:13 +00:00
|
|
|
}
|
|
|
|
if configFn != nil {
|
|
|
|
configFn(&cfg)
|
|
|
|
}
|
|
|
|
|
|
|
|
grpcServer := grpc.NewServer()
|
|
|
|
|
|
|
|
srv := NewServer(cfg)
|
|
|
|
srv.Register(grpcServer)
|
|
|
|
|
|
|
|
var (
|
|
|
|
grpcPort = ports[0]
|
|
|
|
grpcAddr = fmt.Sprintf("127.0.0.1:%d", grpcPort)
|
|
|
|
)
|
|
|
|
ln, err := net.Listen("tcp", grpcAddr)
|
|
|
|
require.NoError(t, err)
|
|
|
|
go func() {
|
|
|
|
_ = grpcServer.Serve(ln)
|
|
|
|
}()
|
|
|
|
t.Cleanup(grpcServer.Stop)
|
|
|
|
|
|
|
|
return &testServer{
|
2022-08-22 14:22:11 +00:00
|
|
|
Server: srv,
|
|
|
|
mockSnapshotHandler: handler,
|
2022-07-08 17:01:13 +00:00
|
|
|
}, store
|
|
|
|
}
|
|
|
|
|
2022-06-21 18:04:08 +00:00
|
|
|
func testUUID(t *testing.T) string {
|
|
|
|
v, err := lib.GenerateUUID(nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return v
|
2022-06-13 17:52:28 +00:00
|
|
|
}
|
2022-07-08 17:01:13 +00:00
|
|
|
|
|
|
|
func noopForwardRPC(structs.RPCInfo, func(*grpc.ClientConn) error) (bool, error) {
|
|
|
|
return false, nil
|
|
|
|
}
|