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
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2022-06-08 22:53:32 +00:00
|
|
|
"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
|
|
|
|
|
|
|
"github.com/hashicorp/go-memdb"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/acl"
|
2022-06-27 19:37:18 +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/structs"
|
|
|
|
"github.com/hashicorp/consul/proto/pbpeering"
|
2022-06-15 19:36:18 +00:00
|
|
|
"github.com/hashicorp/consul/proto/prototest"
|
2022-05-10 20:25:51 +00:00
|
|
|
"github.com/hashicorp/consul/sdk/testutil"
|
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-21 18:04:08 +00:00
|
|
|
const (
|
|
|
|
testFooPeerID = "9e650110-ac74-4c5a-a6a8-9348b2bed4e9"
|
|
|
|
testBarPeerID = "5ebcff30-5509-4858-8142-a8e580f1863f"
|
|
|
|
testBazPeerID = "432feb2f-5476-4ae2-b33c-e43640ca0e86"
|
2022-08-01 14:33:18 +00:00
|
|
|
|
|
|
|
testFooSecretID = "e34e9c3d-a27d-4f82-a6d2-28a86af2be6b"
|
|
|
|
testBazSecretID = "dd3802bb-0c91-4b2a-be51-505bacae772b"
|
2022-06-21 18:04: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
|
|
|
func insertTestPeerings(t *testing.T, s *Store) {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
tx := s.db.WriteTxn(0)
|
|
|
|
defer tx.Abort()
|
|
|
|
|
|
|
|
err := tx.Insert(tablePeering, &pbpeering.Peering{
|
|
|
|
Name: "foo",
|
|
|
|
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
|
2022-06-21 18:04:08 +00:00
|
|
|
ID: testFooPeerID,
|
2022-07-04 14:47:58 +00:00
|
|
|
State: pbpeering.PeeringState_PENDING,
|
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
|
|
|
CreateIndex: 1,
|
|
|
|
ModifyIndex: 1,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = tx.Insert(tablePeering, &pbpeering.Peering{
|
|
|
|
Name: "bar",
|
|
|
|
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
|
2022-06-21 18:04:08 +00:00
|
|
|
ID: testBarPeerID,
|
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
|
|
|
State: pbpeering.PeeringState_FAILING,
|
|
|
|
CreateIndex: 2,
|
|
|
|
ModifyIndex: 2,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = tx.Insert(tableIndex, &IndexEntry{
|
|
|
|
Key: tablePeering,
|
|
|
|
Value: 2,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, tx.Commit())
|
|
|
|
}
|
|
|
|
|
2022-08-01 14:33:18 +00:00
|
|
|
func insertTestPeeringSecret(t *testing.T, s *Store, secret *pbpeering.PeeringSecrets) {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
tx := s.db.WriteTxn(0)
|
|
|
|
defer tx.Abort()
|
|
|
|
|
|
|
|
err := tx.Insert(tablePeeringSecrets, secret)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var uuids []string
|
|
|
|
if establishment := secret.GetEstablishment().GetSecretID(); establishment != "" {
|
|
|
|
uuids = append(uuids, establishment)
|
|
|
|
}
|
|
|
|
if pending := secret.GetStream().GetPendingSecretID(); pending != "" {
|
|
|
|
uuids = append(uuids, pending)
|
|
|
|
}
|
|
|
|
if active := secret.GetStream().GetActiveSecretID(); active != "" {
|
|
|
|
uuids = append(uuids, active)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, id := range uuids {
|
|
|
|
err = tx.Insert(tablePeeringSecretUUIDs, id)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
require.NoError(t, tx.Commit())
|
|
|
|
}
|
|
|
|
|
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 insertTestPeeringTrustBundles(t *testing.T, s *Store) {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
tx := s.db.WriteTxn(0)
|
|
|
|
defer tx.Abort()
|
|
|
|
|
|
|
|
err := tx.Insert(tablePeeringTrustBundles, &pbpeering.PeeringTrustBundle{
|
|
|
|
TrustDomain: "foo.com",
|
|
|
|
PeerName: "foo",
|
|
|
|
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
|
|
|
|
RootPEMs: []string{"foo certificate bundle"},
|
|
|
|
CreateIndex: 1,
|
|
|
|
ModifyIndex: 1,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = tx.Insert(tablePeeringTrustBundles, &pbpeering.PeeringTrustBundle{
|
|
|
|
TrustDomain: "bar.com",
|
|
|
|
PeerName: "bar",
|
|
|
|
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
|
|
|
|
RootPEMs: []string{"bar certificate bundle"},
|
|
|
|
CreateIndex: 2,
|
|
|
|
ModifyIndex: 2,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = tx.Insert(tableIndex, &IndexEntry{
|
|
|
|
Key: tablePeeringTrustBundles,
|
|
|
|
Value: 2,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, tx.Commit())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStateStore_PeeringReadByID(t *testing.T) {
|
|
|
|
s := NewStateStore(nil)
|
|
|
|
insertTestPeerings(t, s)
|
|
|
|
|
|
|
|
type testcase struct {
|
|
|
|
name string
|
|
|
|
id string
|
|
|
|
expect *pbpeering.Peering
|
|
|
|
}
|
|
|
|
run := func(t *testing.T, tc testcase) {
|
|
|
|
_, peering, err := s.PeeringReadByID(nil, tc.id)
|
|
|
|
require.NoError(t, err)
|
2022-06-21 18:04:08 +00:00
|
|
|
prototest.AssertDeepEqual(t, tc.expect, 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
|
|
|
}
|
|
|
|
tcs := []testcase{
|
|
|
|
{
|
|
|
|
name: "get foo",
|
2022-06-21 18:04:08 +00:00
|
|
|
id: testFooPeerID,
|
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
|
|
|
expect: &pbpeering.Peering{
|
|
|
|
Name: "foo",
|
|
|
|
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
|
2022-06-21 18:04:08 +00:00
|
|
|
ID: testFooPeerID,
|
2022-07-04 14:47:58 +00:00
|
|
|
State: pbpeering.PeeringState_PENDING,
|
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
|
|
|
CreateIndex: 1,
|
|
|
|
ModifyIndex: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "get bar",
|
2022-06-21 18:04:08 +00:00
|
|
|
id: testBarPeerID,
|
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
|
|
|
expect: &pbpeering.Peering{
|
|
|
|
Name: "bar",
|
|
|
|
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
|
2022-06-21 18:04:08 +00:00
|
|
|
ID: testBarPeerID,
|
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
|
|
|
State: pbpeering.PeeringState_FAILING,
|
|
|
|
CreateIndex: 2,
|
|
|
|
ModifyIndex: 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "get non-existent",
|
|
|
|
id: "05f54e2f-7813-4d4d-ba03-534554c88a18",
|
|
|
|
expect: nil,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range tcs {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
run(t, tc)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-01 14:33:18 +00:00
|
|
|
func TestStateStore_PeeringSecretsRead(t *testing.T) {
|
|
|
|
s := NewStateStore(nil)
|
|
|
|
|
|
|
|
insertTestPeerings(t, s)
|
|
|
|
|
|
|
|
insertTestPeeringSecret(t, s, &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Establishment: &pbpeering.PeeringSecrets_Establishment{
|
|
|
|
SecretID: testFooSecretID,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
type testcase struct {
|
|
|
|
name string
|
|
|
|
peerID string
|
|
|
|
expect *pbpeering.PeeringSecrets
|
|
|
|
}
|
|
|
|
run := func(t *testing.T, tc testcase) {
|
|
|
|
secrets, err := s.PeeringSecretsRead(nil, tc.peerID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
prototest.AssertDeepEqual(t, tc.expect, secrets)
|
|
|
|
}
|
|
|
|
tcs := []testcase{
|
|
|
|
{
|
|
|
|
name: "get foo",
|
|
|
|
peerID: testFooPeerID,
|
|
|
|
expect: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Establishment: &pbpeering.PeeringSecrets_Establishment{
|
|
|
|
SecretID: testFooSecretID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "get non-existent baz",
|
|
|
|
peerID: testBazPeerID,
|
|
|
|
expect: nil,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range tcs {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
run(t, tc)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStore_PeeringSecretsWrite(t *testing.T) {
|
|
|
|
dumpUUIDs := func(s *Store) []string {
|
|
|
|
tx := s.db.ReadTxn()
|
|
|
|
defer tx.Abort()
|
|
|
|
|
|
|
|
iter, err := tx.Get(tablePeeringSecretUUIDs, indexID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var resp []string
|
|
|
|
for entry := iter.Next(); entry != nil; entry = iter.Next() {
|
|
|
|
resp = append(resp, entry.(string))
|
|
|
|
}
|
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
|
|
|
writeSeed := func(s *Store, req *pbpeering.PeeringWriteRequest) {
|
|
|
|
tx := s.db.WriteTxn(1)
|
|
|
|
defer tx.Abort()
|
|
|
|
|
|
|
|
if req.Peering != nil {
|
|
|
|
require.NoError(t, tx.Insert(tablePeering, req.Peering))
|
|
|
|
}
|
|
|
|
if req.Secret != nil {
|
|
|
|
require.NoError(t, tx.Insert(tablePeeringSecrets, req.Secret))
|
|
|
|
|
|
|
|
var toInsert []string
|
|
|
|
if establishment := req.Secret.GetEstablishment().GetSecretID(); establishment != "" {
|
|
|
|
toInsert = append(toInsert, establishment)
|
|
|
|
}
|
|
|
|
if pending := req.Secret.GetStream().GetPendingSecretID(); pending != "" {
|
|
|
|
toInsert = append(toInsert, pending)
|
|
|
|
}
|
|
|
|
if active := req.Secret.GetStream().GetActiveSecretID(); active != "" {
|
|
|
|
toInsert = append(toInsert, active)
|
|
|
|
}
|
|
|
|
for _, id := range toInsert {
|
|
|
|
require.NoError(t, tx.Insert(tablePeeringSecretUUIDs, id))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tx.Commit()
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
testSecretOne = testUUID()
|
|
|
|
testSecretTwo = testUUID()
|
|
|
|
testSecretThree = testUUID()
|
|
|
|
)
|
|
|
|
|
|
|
|
type testcase struct {
|
|
|
|
name string
|
|
|
|
seed *pbpeering.PeeringWriteRequest
|
|
|
|
input *pbpeering.PeeringSecrets
|
|
|
|
expect *pbpeering.PeeringSecrets
|
|
|
|
expectUUIDs []string
|
|
|
|
expectErr string
|
|
|
|
}
|
|
|
|
run := func(t *testing.T, tc testcase) {
|
|
|
|
s := NewStateStore(nil)
|
|
|
|
|
|
|
|
// Optionally seed existing secrets for the peering.
|
|
|
|
if tc.seed != nil {
|
|
|
|
writeSeed(s, tc.seed)
|
|
|
|
}
|
|
|
|
|
|
|
|
err := s.PeeringSecretsWrite(10, tc.input)
|
|
|
|
if tc.expectErr != "" {
|
|
|
|
testutil.RequireErrorContains(t, err, tc.expectErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Validate that we read what we expect
|
|
|
|
secrets, err := s.PeeringSecretsRead(nil, tc.input.PeerID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, secrets)
|
|
|
|
prototest.AssertDeepEqual(t, tc.expect, secrets)
|
|
|
|
|
|
|
|
// Validate accounting of the UUIDs table
|
|
|
|
require.ElementsMatch(t, tc.expectUUIDs, dumpUUIDs(s))
|
|
|
|
}
|
|
|
|
tcs := []testcase{
|
|
|
|
{
|
|
|
|
name: "missing peer id",
|
|
|
|
input: &pbpeering.PeeringSecrets{},
|
|
|
|
expectErr: "missing peer ID",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "no secret IDs were embedded",
|
|
|
|
input: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
},
|
|
|
|
expectErr: "no secret IDs were embedded",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown peer id",
|
|
|
|
input: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Establishment: &pbpeering.PeeringSecrets_Establishment{
|
|
|
|
SecretID: testFooSecretID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectErr: "unknown peering",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "dialing peer does not track UUIDs",
|
|
|
|
seed: &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
Name: "foo",
|
|
|
|
ID: testFooPeerID,
|
|
|
|
PeerServerAddresses: []string{"10.0.0.1:5300"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
input: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Stream: &pbpeering.PeeringSecrets_Stream{
|
|
|
|
ActiveSecretID: testFooSecretID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Stream: &pbpeering.PeeringSecrets_Stream{
|
|
|
|
ActiveSecretID: testFooSecretID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// UUIDs are only tracked for uniqueness in the generating cluster.
|
|
|
|
expectUUIDs: []string{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "generate new establishment secret",
|
|
|
|
seed: &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
Name: "foo",
|
|
|
|
ID: testFooPeerID,
|
|
|
|
},
|
|
|
|
Secret: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Stream: &pbpeering.PeeringSecrets_Stream{
|
|
|
|
PendingSecretID: testSecretOne,
|
|
|
|
ActiveSecretID: testSecretTwo,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
input: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Establishment: &pbpeering.PeeringSecrets_Establishment{
|
|
|
|
SecretID: testSecretThree,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Establishment: &pbpeering.PeeringSecrets_Establishment{
|
|
|
|
SecretID: testSecretThree,
|
|
|
|
},
|
|
|
|
// Stream secrets are inherited
|
|
|
|
Stream: &pbpeering.PeeringSecrets_Stream{
|
|
|
|
PendingSecretID: testSecretOne,
|
|
|
|
ActiveSecretID: testSecretTwo,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectUUIDs: []string{testSecretOne, testSecretTwo, testSecretThree},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "replace establishment secret",
|
|
|
|
seed: &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
Name: "foo",
|
|
|
|
ID: testFooPeerID,
|
|
|
|
},
|
|
|
|
Secret: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Establishment: &pbpeering.PeeringSecrets_Establishment{
|
|
|
|
SecretID: testSecretOne,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
input: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Establishment: &pbpeering.PeeringSecrets_Establishment{
|
|
|
|
// Two replaces One
|
|
|
|
SecretID: testSecretTwo,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Establishment: &pbpeering.PeeringSecrets_Establishment{
|
|
|
|
SecretID: testSecretTwo,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectUUIDs: []string{testSecretTwo},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "generate new pending secret",
|
|
|
|
seed: &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
Name: "foo",
|
|
|
|
ID: testFooPeerID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
input: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Stream: &pbpeering.PeeringSecrets_Stream{
|
|
|
|
PendingSecretID: testSecretOne,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Stream: &pbpeering.PeeringSecrets_Stream{
|
|
|
|
PendingSecretID: testSecretOne,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectUUIDs: []string{testSecretOne},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "replace pending secret",
|
|
|
|
seed: &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
Name: "foo",
|
|
|
|
ID: testFooPeerID,
|
|
|
|
},
|
|
|
|
Secret: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Stream: &pbpeering.PeeringSecrets_Stream{
|
|
|
|
PendingSecretID: testSecretOne,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
input: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Stream: &pbpeering.PeeringSecrets_Stream{
|
|
|
|
// Two replaces One
|
|
|
|
PendingSecretID: testSecretTwo,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Stream: &pbpeering.PeeringSecrets_Stream{
|
|
|
|
PendingSecretID: testSecretTwo,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectUUIDs: []string{testSecretTwo},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "promote pending secret and delete active",
|
|
|
|
seed: &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
Name: "foo",
|
|
|
|
ID: testFooPeerID,
|
|
|
|
},
|
|
|
|
Secret: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Stream: &pbpeering.PeeringSecrets_Stream{
|
|
|
|
PendingSecretID: testSecretTwo,
|
|
|
|
ActiveSecretID: testSecretOne,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
input: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Stream: &pbpeering.PeeringSecrets_Stream{
|
|
|
|
// Two gets promoted over One
|
|
|
|
ActiveSecretID: testSecretTwo,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Stream: &pbpeering.PeeringSecrets_Stream{
|
|
|
|
ActiveSecretID: testSecretTwo,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectUUIDs: []string{testSecretTwo},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range tcs {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
run(t, tc)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStore_PeeringSecretsDelete(t *testing.T) {
|
|
|
|
s := NewStateStore(nil)
|
|
|
|
insertTestPeerings(t, s)
|
|
|
|
|
|
|
|
const (
|
|
|
|
establishmentID = "b4b9cbae-4bbd-454b-b7ae-441a5c89c3b9"
|
|
|
|
pendingID = "0ba06390-bd77-4c52-8397-f88c0867157d"
|
|
|
|
activeID = "0b8a3817-aca0-4c06-94b6-b0763a5cd013"
|
|
|
|
)
|
|
|
|
|
|
|
|
insertTestPeeringSecret(t, s, &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testFooPeerID,
|
|
|
|
Establishment: &pbpeering.PeeringSecrets_Establishment{
|
|
|
|
SecretID: establishmentID,
|
|
|
|
},
|
|
|
|
Stream: &pbpeering.PeeringSecrets_Stream{
|
|
|
|
PendingSecretID: pendingID,
|
|
|
|
ActiveSecretID: activeID,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.NoError(t, s.PeeringSecretsDelete(12, testFooPeerID))
|
|
|
|
|
|
|
|
// The secrets should be gone
|
|
|
|
secrets, err := s.PeeringSecretsRead(nil, testFooPeerID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, secrets)
|
|
|
|
|
|
|
|
// The UUIDs should be free
|
|
|
|
uuids := []string{establishmentID, pendingID, activeID}
|
|
|
|
|
|
|
|
for _, id := range uuids {
|
|
|
|
free, err := s.ValidateProposedPeeringSecretUUID(id)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, free)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 TestStateStore_PeeringRead(t *testing.T) {
|
|
|
|
s := NewStateStore(nil)
|
|
|
|
insertTestPeerings(t, s)
|
|
|
|
|
|
|
|
type testcase struct {
|
|
|
|
name string
|
|
|
|
query Query
|
|
|
|
expect *pbpeering.Peering
|
|
|
|
}
|
|
|
|
run := func(t *testing.T, tc testcase) {
|
|
|
|
_, peering, err := s.PeeringRead(nil, tc.query)
|
|
|
|
require.NoError(t, err)
|
2022-06-21 18:04:08 +00:00
|
|
|
prototest.AssertDeepEqual(t, tc.expect, 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
|
|
|
}
|
|
|
|
tcs := []testcase{
|
|
|
|
{
|
|
|
|
name: "get foo",
|
|
|
|
query: Query{
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
expect: &pbpeering.Peering{
|
|
|
|
Name: "foo",
|
|
|
|
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
|
2022-06-21 18:04:08 +00:00
|
|
|
ID: testFooPeerID,
|
2022-07-04 14:47:58 +00:00
|
|
|
State: pbpeering.PeeringState_PENDING,
|
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
|
|
|
CreateIndex: 1,
|
|
|
|
ModifyIndex: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "get non-existent baz",
|
|
|
|
query: Query{
|
|
|
|
Value: "baz",
|
|
|
|
},
|
|
|
|
expect: nil,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range tcs {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
run(t, tc)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStore_Peering_Watch(t *testing.T) {
|
|
|
|
s := NewStateStore(nil)
|
|
|
|
|
|
|
|
var lastIdx uint64
|
|
|
|
lastIdx++
|
|
|
|
|
|
|
|
// set up initial write
|
2022-08-01 14:33:18 +00:00
|
|
|
err := s.PeeringWrite(lastIdx, &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
ID: testFooPeerID,
|
|
|
|
Name: "foo",
|
|
|
|
},
|
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)
|
|
|
|
|
|
|
|
newWatch := func(t *testing.T, q Query) memdb.WatchSet {
|
|
|
|
t.Helper()
|
|
|
|
// set up a watch
|
|
|
|
ws := memdb.NewWatchSet()
|
|
|
|
|
|
|
|
_, _, err := s.PeeringRead(ws, q)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
return ws
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("insert fires watch", func(t *testing.T) {
|
|
|
|
// watch on non-existent bar
|
|
|
|
ws := newWatch(t, Query{Value: "bar"})
|
|
|
|
|
|
|
|
lastIdx++
|
2022-08-01 14:33:18 +00:00
|
|
|
err := s.PeeringWrite(lastIdx, &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
ID: testBarPeerID,
|
|
|
|
Name: "bar",
|
|
|
|
},
|
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)
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
|
|
|
// should find bar peering
|
|
|
|
idx, p, err := s.PeeringRead(ws, Query{Value: "bar"})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, lastIdx, idx)
|
|
|
|
require.NotNil(t, p)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("update fires watch", func(t *testing.T) {
|
|
|
|
// watch on existing foo
|
|
|
|
ws := newWatch(t, Query{Value: "foo"})
|
|
|
|
|
|
|
|
// unrelated write shouldn't fire watch
|
|
|
|
lastIdx++
|
2022-08-01 14:33:18 +00:00
|
|
|
err := s.PeeringWrite(lastIdx, &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
ID: testBarPeerID,
|
|
|
|
Name: "bar",
|
|
|
|
},
|
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)
|
|
|
|
require.False(t, watchFired(ws))
|
|
|
|
|
|
|
|
// foo write should fire watch
|
|
|
|
lastIdx++
|
2022-08-01 14:33:18 +00:00
|
|
|
err = s.PeeringWrite(lastIdx, &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
ID: testFooPeerID,
|
|
|
|
Name: "foo",
|
|
|
|
DeletedAt: structs.TimeToProto(time.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
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
|
|
|
// check foo is updated
|
|
|
|
idx, p, err := s.PeeringRead(ws, Query{Value: "foo"})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, lastIdx, idx)
|
2022-06-08 22:53:32 +00:00
|
|
|
require.False(t, p.IsActive())
|
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
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("delete fires watch", func(t *testing.T) {
|
|
|
|
// watch on existing foo
|
2022-06-08 22:53:32 +00:00
|
|
|
ws := newWatch(t, Query{Value: "bar"})
|
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-06-08 22:53:32 +00:00
|
|
|
require.NoError(t, s.PeeringDelete(lastIdx, Query{Value: "foo"}))
|
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(t, watchFired(ws))
|
|
|
|
|
2022-06-08 22:53:32 +00:00
|
|
|
// mark for deletion before actually deleting
|
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-08-01 14:33:18 +00:00
|
|
|
err := s.PeeringWrite(lastIdx, &pbpeering.PeeringWriteRequest{Peering: &pbpeering.Peering{
|
2022-06-21 18:04:08 +00:00
|
|
|
ID: testBarPeerID,
|
2022-06-08 22:53:32 +00:00
|
|
|
Name: "bar",
|
|
|
|
DeletedAt: structs.TimeToProto(time.Now()),
|
2022-08-01 14:33:18 +00:00
|
|
|
},
|
2022-06-08 22:53:32 +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
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
2022-06-08 22:53:32 +00:00
|
|
|
ws = newWatch(t, Query{Value: "bar"})
|
|
|
|
|
|
|
|
// delete on bar should fire watch
|
|
|
|
lastIdx++
|
|
|
|
err = s.PeeringDelete(lastIdx, Query{Value: "bar"})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
|
|
|
// check bar is gone
|
|
|
|
idx, p, err := s.PeeringRead(ws, Query{Value: "bar"})
|
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)
|
|
|
|
require.Equal(t, lastIdx, idx)
|
|
|
|
require.Nil(t, p)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStore_PeeringList(t *testing.T) {
|
|
|
|
s := NewStateStore(nil)
|
|
|
|
insertTestPeerings(t, s)
|
|
|
|
|
|
|
|
_, pps, err := s.PeeringList(nil, acl.EnterpriseMeta{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
expect := []*pbpeering.Peering{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
|
2022-06-21 18:04:08 +00:00
|
|
|
ID: testFooPeerID,
|
2022-07-04 14:47:58 +00:00
|
|
|
State: pbpeering.PeeringState_PENDING,
|
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
|
|
|
CreateIndex: 1,
|
|
|
|
ModifyIndex: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "bar",
|
|
|
|
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
|
2022-06-21 18:04:08 +00:00
|
|
|
ID: testBarPeerID,
|
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
|
|
|
State: pbpeering.PeeringState_FAILING,
|
|
|
|
CreateIndex: 2,
|
|
|
|
ModifyIndex: 2,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
require.ElementsMatch(t, expect, pps)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStore_PeeringList_Watch(t *testing.T) {
|
|
|
|
s := NewStateStore(nil)
|
|
|
|
|
|
|
|
var lastIdx uint64
|
|
|
|
lastIdx++ // start at 1
|
|
|
|
|
|
|
|
// track number of expected peerings in state store
|
|
|
|
var count int
|
|
|
|
|
|
|
|
newWatch := func(t *testing.T, entMeta acl.EnterpriseMeta) memdb.WatchSet {
|
|
|
|
t.Helper()
|
|
|
|
// set up a watch
|
|
|
|
ws := memdb.NewWatchSet()
|
|
|
|
|
|
|
|
_, _, err := s.PeeringList(ws, entMeta)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
return ws
|
|
|
|
}
|
|
|
|
|
2022-06-08 22:53:32 +00:00
|
|
|
testutil.RunStep(t, "insert fires watch", 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
|
|
|
ws := newWatch(t, acl.EnterpriseMeta{})
|
|
|
|
|
|
|
|
lastIdx++
|
|
|
|
// insert a peering
|
2022-08-01 14:33:18 +00:00
|
|
|
err := s.PeeringWrite(lastIdx, &pbpeering.PeeringWriteRequest{Peering: &pbpeering.Peering{
|
2022-06-21 18:04:08 +00:00
|
|
|
ID: testFooPeerID,
|
2022-06-08 22:53:32 +00:00
|
|
|
Name: "foo",
|
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
|
|
|
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
|
2022-08-01 14:33:18 +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
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
count++
|
|
|
|
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
|
|
|
// should find bar peering
|
|
|
|
idx, pp, err := s.PeeringList(ws, acl.EnterpriseMeta{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, lastIdx, idx)
|
|
|
|
require.Len(t, pp, count)
|
|
|
|
})
|
|
|
|
|
2022-06-08 22:53:32 +00:00
|
|
|
testutil.RunStep(t, "update fires watch", 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
|
|
|
ws := newWatch(t, acl.EnterpriseMeta{})
|
|
|
|
|
|
|
|
// update peering
|
|
|
|
lastIdx++
|
2022-08-01 14:33:18 +00:00
|
|
|
require.NoError(t, s.PeeringWrite(lastIdx, &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
ID: testFooPeerID,
|
|
|
|
Name: "foo",
|
|
|
|
DeletedAt: structs.TimeToProto(time.Now()),
|
|
|
|
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
|
|
|
|
},
|
2022-06-08 22:53:32 +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
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
|
|
|
idx, pp, err := s.PeeringList(ws, acl.EnterpriseMeta{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, lastIdx, idx)
|
|
|
|
require.Len(t, pp, count)
|
|
|
|
})
|
|
|
|
|
2022-06-08 22:53:32 +00:00
|
|
|
testutil.RunStep(t, "delete fires watch", 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
|
|
|
ws := newWatch(t, acl.EnterpriseMeta{})
|
|
|
|
|
|
|
|
// delete peering
|
|
|
|
lastIdx++
|
2022-06-08 22:53:32 +00:00
|
|
|
err := s.PeeringDelete(lastIdx, Query{Value: "foo"})
|
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)
|
|
|
|
count--
|
|
|
|
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
|
|
|
idx, pp, err := s.PeeringList(ws, acl.EnterpriseMeta{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, lastIdx, idx)
|
|
|
|
require.Len(t, pp, count)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStore_PeeringWrite(t *testing.T) {
|
2022-06-08 22:53:32 +00:00
|
|
|
// Note that all test cases in this test share a state store and must be run sequentially.
|
|
|
|
// Each case depends on the previous.
|
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
|
|
|
s := NewStateStore(nil)
|
2022-06-08 22:53:32 +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
|
|
|
type testcase struct {
|
2022-08-01 14:33:18 +00:00
|
|
|
name string
|
|
|
|
input *pbpeering.PeeringWriteRequest
|
|
|
|
expectSecrets *pbpeering.PeeringSecrets
|
|
|
|
expectErr 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
|
|
|
}
|
|
|
|
run := func(t *testing.T, tc testcase) {
|
2022-06-08 22:53:32 +00:00
|
|
|
err := s.PeeringWrite(10, tc.input)
|
|
|
|
if tc.expectErr != "" {
|
|
|
|
testutil.RequireErrorContains(t, err, tc.expectErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(t, 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
|
|
|
|
|
|
|
q := Query{
|
2022-08-01 14:33:18 +00:00
|
|
|
Value: tc.input.Peering.Name,
|
|
|
|
EnterpriseMeta: *structs.NodeEnterpriseMetaInPartition(tc.input.Peering.Partition),
|
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
|
|
|
}
|
|
|
|
_, p, err := s.PeeringRead(nil, q)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, p)
|
2022-08-01 14:33:18 +00:00
|
|
|
require.Equal(t, tc.input.Peering.State, p.State)
|
|
|
|
require.Equal(t, tc.input.Peering.Name, p.Name)
|
|
|
|
|
|
|
|
secrets, err := s.PeeringSecretsRead(nil, tc.input.Peering.ID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
prototest.AssertDeepEqual(t, tc.expectSecrets, secrets)
|
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
|
|
|
}
|
|
|
|
tcs := []testcase{
|
|
|
|
{
|
|
|
|
name: "create baz",
|
2022-08-01 14:33:18 +00:00
|
|
|
input: &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
ID: testBazPeerID,
|
|
|
|
Name: "baz",
|
|
|
|
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
|
|
|
|
},
|
|
|
|
Secret: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testBazPeerID,
|
|
|
|
Establishment: &pbpeering.PeeringSecrets_Establishment{
|
|
|
|
SecretID: testBazSecretID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectSecrets: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testBazPeerID,
|
|
|
|
Establishment: &pbpeering.PeeringSecrets_Establishment{
|
|
|
|
SecretID: testBazSecretID,
|
|
|
|
},
|
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-08 22:53:32 +00:00
|
|
|
name: "update baz",
|
2022-08-01 14:33:18 +00:00
|
|
|
input: &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
ID: testBazPeerID,
|
|
|
|
Name: "baz",
|
|
|
|
State: pbpeering.PeeringState_FAILING,
|
|
|
|
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectSecrets: &pbpeering.PeeringSecrets{
|
|
|
|
PeerID: testBazPeerID,
|
|
|
|
Establishment: &pbpeering.PeeringSecrets_Establishment{
|
|
|
|
SecretID: testBazSecretID,
|
|
|
|
},
|
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-08 22:53:32 +00:00
|
|
|
{
|
|
|
|
name: "mark baz for deletion",
|
2022-08-01 14:33:18 +00:00
|
|
|
input: &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
ID: testBazPeerID,
|
|
|
|
Name: "baz",
|
|
|
|
State: pbpeering.PeeringState_DELETING,
|
|
|
|
DeletedAt: structs.TimeToProto(time.Now()),
|
|
|
|
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
|
|
|
|
},
|
2022-06-08 22:53:32 +00:00
|
|
|
},
|
2022-08-01 14:33:18 +00:00
|
|
|
// Secrets for baz should have been deleted
|
|
|
|
expectSecrets: nil,
|
2022-06-08 22:53:32 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "cannot update peering marked for deletion",
|
2022-08-01 14:33:18 +00:00
|
|
|
input: &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
ID: testBazPeerID,
|
|
|
|
Name: "baz",
|
|
|
|
// Attempt to add metadata
|
|
|
|
Meta: map[string]string{
|
|
|
|
"source": "kubernetes",
|
|
|
|
},
|
|
|
|
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
|
2022-06-08 22:53:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
expectErr: "cannot write to peering that is marked for deletion",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "cannot create peering marked for deletion",
|
2022-08-01 14:33:18 +00:00
|
|
|
input: &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
ID: testFooPeerID,
|
|
|
|
Name: "foo",
|
|
|
|
DeletedAt: structs.TimeToProto(time.Now()),
|
|
|
|
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
|
|
|
|
},
|
2022-06-08 22:53:32 +00:00
|
|
|
},
|
|
|
|
expectErr: "cannot create a new peering marked for deletion",
|
|
|
|
},
|
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 tcs {
|
2022-06-08 22:53:32 +00:00
|
|
|
testutil.RunStep(t, tc.name, 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
|
|
|
run(t, tc)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStore_PeeringDelete(t *testing.T) {
|
|
|
|
s := NewStateStore(nil)
|
|
|
|
insertTestPeerings(t, s)
|
|
|
|
|
2022-06-08 22:53:32 +00:00
|
|
|
testutil.RunStep(t, "cannot delete without marking for deletion", func(t *testing.T) {
|
|
|
|
q := Query{Value: "foo"}
|
|
|
|
err := s.PeeringDelete(10, q)
|
|
|
|
testutil.RequireErrorContains(t, err, "cannot delete a peering without first marking for deletion")
|
|
|
|
})
|
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-08 22:53:32 +00:00
|
|
|
testutil.RunStep(t, "can delete after marking for deletion", func(t *testing.T) {
|
2022-08-01 14:33:18 +00:00
|
|
|
require.NoError(t, s.PeeringWrite(11, &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
ID: testFooPeerID,
|
|
|
|
Name: "foo",
|
|
|
|
DeletedAt: structs.TimeToProto(time.Now()),
|
|
|
|
},
|
2022-06-08 22:53:32 +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
|
|
|
|
2022-06-08 22:53:32 +00:00
|
|
|
q := Query{Value: "foo"}
|
|
|
|
require.NoError(t, s.PeeringDelete(12, q))
|
|
|
|
|
|
|
|
_, p, err := s.PeeringRead(nil, q)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, p)
|
|
|
|
})
|
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 TestStore_PeeringTerminateByID(t *testing.T) {
|
|
|
|
s := NewStateStore(nil)
|
|
|
|
insertTestPeerings(t, s)
|
|
|
|
|
|
|
|
// id corresponding to default/foo
|
2022-06-21 18:04:08 +00:00
|
|
|
const id = testFooPeerID
|
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, s.PeeringTerminateByID(10, id))
|
|
|
|
|
|
|
|
_, p, err := s.PeeringReadByID(nil, id)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, pbpeering.PeeringState_TERMINATED, p.State)
|
|
|
|
}
|
|
|
|
|
2022-06-15 19:36:18 +00:00
|
|
|
func TestStateStore_PeeringTrustBundleList(t *testing.T) {
|
|
|
|
s := NewStateStore(nil)
|
|
|
|
insertTestPeeringTrustBundles(t, s)
|
|
|
|
|
|
|
|
type testcase struct {
|
|
|
|
name string
|
|
|
|
entMeta acl.EnterpriseMeta
|
|
|
|
expect []*pbpeering.PeeringTrustBundle
|
|
|
|
}
|
|
|
|
|
|
|
|
entMeta := structs.NodeEnterpriseMetaInDefaultPartition()
|
|
|
|
|
|
|
|
expect := []*pbpeering.PeeringTrustBundle{
|
|
|
|
{
|
|
|
|
TrustDomain: "bar.com",
|
|
|
|
PeerName: "bar",
|
|
|
|
Partition: entMeta.PartitionOrEmpty(),
|
|
|
|
RootPEMs: []string{"bar certificate bundle"},
|
|
|
|
CreateIndex: 2,
|
|
|
|
ModifyIndex: 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TrustDomain: "foo.com",
|
|
|
|
PeerName: "foo",
|
|
|
|
Partition: entMeta.PartitionOrEmpty(),
|
|
|
|
RootPEMs: []string{"foo certificate bundle"},
|
|
|
|
CreateIndex: 1,
|
|
|
|
ModifyIndex: 1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, bundles, err := s.PeeringTrustBundleList(nil, *entMeta)
|
|
|
|
require.NoError(t, err)
|
|
|
|
prototest.AssertDeepEqual(t, expect, bundles)
|
|
|
|
}
|
|
|
|
|
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 TestStateStore_PeeringTrustBundleRead(t *testing.T) {
|
|
|
|
s := NewStateStore(nil)
|
|
|
|
insertTestPeeringTrustBundles(t, s)
|
|
|
|
|
|
|
|
type testcase struct {
|
|
|
|
name string
|
|
|
|
query Query
|
|
|
|
expect *pbpeering.PeeringTrustBundle
|
|
|
|
}
|
|
|
|
run := func(t *testing.T, tc testcase) {
|
|
|
|
_, ptb, err := s.PeeringTrustBundleRead(nil, tc.query)
|
|
|
|
require.NoError(t, err)
|
2022-06-21 18:04:08 +00:00
|
|
|
prototest.AssertDeepEqual(t, tc.expect, ptb)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
entMeta := structs.NodeEnterpriseMetaInDefaultPartition()
|
|
|
|
|
|
|
|
tcs := []testcase{
|
|
|
|
{
|
|
|
|
name: "get foo",
|
|
|
|
query: Query{
|
|
|
|
Value: "foo",
|
|
|
|
EnterpriseMeta: *entMeta,
|
|
|
|
},
|
|
|
|
expect: &pbpeering.PeeringTrustBundle{
|
|
|
|
TrustDomain: "foo.com",
|
|
|
|
PeerName: "foo",
|
|
|
|
Partition: entMeta.PartitionOrEmpty(),
|
|
|
|
RootPEMs: []string{"foo certificate bundle"},
|
|
|
|
CreateIndex: 1,
|
|
|
|
ModifyIndex: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "get non-existent baz",
|
|
|
|
query: Query{
|
|
|
|
Value: "baz",
|
|
|
|
},
|
|
|
|
expect: nil,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range tcs {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
run(t, tc)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStore_PeeringTrustBundleWrite(t *testing.T) {
|
|
|
|
s := NewStateStore(nil)
|
|
|
|
insertTestPeeringTrustBundles(t, s)
|
|
|
|
type testcase struct {
|
|
|
|
name string
|
|
|
|
input *pbpeering.PeeringTrustBundle
|
|
|
|
}
|
|
|
|
run := func(t *testing.T, tc testcase) {
|
|
|
|
require.NoError(t, s.PeeringTrustBundleWrite(10, tc.input))
|
|
|
|
|
|
|
|
q := Query{
|
|
|
|
Value: tc.input.PeerName,
|
|
|
|
EnterpriseMeta: *structs.NodeEnterpriseMetaInPartition(tc.input.Partition),
|
|
|
|
}
|
|
|
|
_, ptb, err := s.PeeringTrustBundleRead(nil, q)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, ptb)
|
|
|
|
require.Equal(t, tc.input.TrustDomain, ptb.TrustDomain)
|
|
|
|
require.Equal(t, tc.input.PeerName, ptb.PeerName)
|
|
|
|
}
|
|
|
|
tcs := []testcase{
|
|
|
|
{
|
|
|
|
name: "create baz",
|
|
|
|
input: &pbpeering.PeeringTrustBundle{
|
|
|
|
TrustDomain: "baz.com",
|
|
|
|
PeerName: "baz",
|
|
|
|
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "update foo",
|
|
|
|
input: &pbpeering.PeeringTrustBundle{
|
|
|
|
TrustDomain: "foo-updated.com",
|
|
|
|
PeerName: "foo",
|
|
|
|
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range tcs {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
run(t, tc)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStore_PeeringTrustBundleDelete(t *testing.T) {
|
|
|
|
s := NewStateStore(nil)
|
|
|
|
insertTestPeeringTrustBundles(t, s)
|
|
|
|
|
|
|
|
q := Query{Value: "foo"}
|
|
|
|
|
|
|
|
require.NoError(t, s.PeeringTrustBundleDelete(10, q))
|
|
|
|
|
|
|
|
_, ptb, err := s.PeeringRead(nil, q)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, ptb)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStateStore_ExportedServicesForPeer(t *testing.T) {
|
|
|
|
s := NewStateStore(nil)
|
|
|
|
|
|
|
|
var lastIdx uint64
|
|
|
|
|
2022-06-27 19:37:18 +00:00
|
|
|
ca := &structs.CAConfiguration{
|
|
|
|
Provider: "consul",
|
|
|
|
ClusterID: connect.TestClusterID,
|
|
|
|
}
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, s.CASetConfig(lastIdx, ca))
|
|
|
|
|
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-08-01 14:33:18 +00:00
|
|
|
require.NoError(t, s.PeeringWrite(lastIdx, &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
ID: testUUID(),
|
|
|
|
Name: "my-peering",
|
|
|
|
},
|
2022-05-19 19:21: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
|
|
|
|
2022-05-19 19:21:44 +00:00
|
|
|
_, p, err := s.PeeringRead(nil, Query{
|
|
|
|
Value: "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
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, p)
|
|
|
|
|
|
|
|
id := p.ID
|
|
|
|
|
2022-05-19 19:21:44 +00:00
|
|
|
defaultEntMeta := structs.DefaultEnterpriseMetaInDefaultPartition()
|
|
|
|
|
2022-05-25 17:37:44 +00:00
|
|
|
newSN := func(name string) structs.ServiceName {
|
|
|
|
return structs.NewServiceName(name, defaultEntMeta)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
ws := memdb.NewWatchSet()
|
|
|
|
|
2022-05-19 19:21:44 +00:00
|
|
|
ensureConfigEntry := func(t *testing.T, entry structs.ConfigEntry) {
|
|
|
|
t.Helper()
|
|
|
|
require.NoError(t, entry.Normalize())
|
|
|
|
require.NoError(t, entry.Validate())
|
|
|
|
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, s.EnsureConfigEntry(lastIdx, entry))
|
|
|
|
}
|
|
|
|
|
2022-06-27 19:37:18 +00:00
|
|
|
newTarget := func(service, serviceSubset, datacenter string) *structs.DiscoveryTarget {
|
|
|
|
t := structs.NewDiscoveryTarget(service, serviceSubset, "default", "default", datacenter)
|
|
|
|
t.SNI = connect.TargetSNI(t, connect.TestTrustDomain)
|
|
|
|
t.Name = t.SNI
|
|
|
|
t.ConnectTimeout = 5 * time.Second // default
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2022-05-10 20:25:51 +00:00
|
|
|
testutil.RunStep(t, "no exported services", func(t *testing.T) {
|
2022-05-19 19:21:44 +00:00
|
|
|
expect := &structs.ExportedServiceList{}
|
|
|
|
|
2022-06-27 19:37:18 +00:00
|
|
|
idx, got, err := s.ExportedServicesForPeer(ws, id, "dc1")
|
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)
|
|
|
|
require.Equal(t, lastIdx, idx)
|
2022-05-19 19:21:44 +00:00
|
|
|
require.Equal(t, expect, got)
|
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, "config entry with exact service names", 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-05-19 19:21:44 +00:00
|
|
|
{PeerName: "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
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "redis",
|
|
|
|
Consumers: []structs.ServiceConsumer{
|
2022-05-19 19:21:44 +00:00
|
|
|
{PeerName: "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
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "mongo",
|
|
|
|
Consumers: []structs.ServiceConsumer{
|
2022-05-19 19:21:44 +00:00
|
|
|
{PeerName: "my-other-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-05-19 19:21:44 +00:00
|
|
|
ensureConfigEntry(t, 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.True(t, watchFired(ws))
|
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
|
2022-05-19 19:21:44 +00:00
|
|
|
expect := &structs.ExportedServiceList{
|
|
|
|
Services: []structs.ServiceName{
|
|
|
|
{
|
|
|
|
Name: "mysql",
|
|
|
|
EnterpriseMeta: *defaultEntMeta,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "redis",
|
|
|
|
EnterpriseMeta: *defaultEntMeta,
|
|
|
|
},
|
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
|
|
|
DiscoChains: map[structs.ServiceName]structs.ExportedDiscoveryChainInfo{
|
|
|
|
newSN("mysql"): {
|
|
|
|
Protocol: "tcp",
|
|
|
|
TCPTargets: []*structs.DiscoveryTarget{
|
|
|
|
newTarget("mysql", "", "dc1"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
newSN("redis"): {
|
|
|
|
Protocol: "tcp",
|
|
|
|
TCPTargets: []*structs.DiscoveryTarget{
|
|
|
|
newTarget("redis", "", "dc1"),
|
|
|
|
},
|
|
|
|
},
|
2022-05-25 17:37: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
|
|
|
}
|
2022-05-19 19:21:44 +00:00
|
|
|
|
2022-06-27 19:37:18 +00:00
|
|
|
idx, got, err := s.ExportedServicesForPeer(ws, id, "dc1")
|
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)
|
|
|
|
require.Equal(t, lastIdx, idx)
|
2022-05-19 19:21:44 +00:00
|
|
|
require.Equal(t, expect, got)
|
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, "config entry with wildcard service name picks up existing service", 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++
|
2022-05-19 19:21:44 +00:00
|
|
|
require.NoError(t, s.EnsureNode(lastIdx, &structs.Node{
|
|
|
|
Node: "foo", Address: "127.0.0.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
|
|
|
|
|
|
|
lastIdx++
|
2022-05-19 19:21:44 +00:00
|
|
|
require.NoError(t, s.EnsureService(lastIdx, "foo", &structs.NodeService{
|
|
|
|
ID: "billing", Service: "billing", Port: 5000,
|
|
|
|
}))
|
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: "*",
|
|
|
|
Consumers: []structs.ServiceConsumer{
|
2022-05-19 19:21:44 +00:00
|
|
|
{PeerName: "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-05-19 19:21:44 +00:00
|
|
|
ensureConfigEntry(t, 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.True(t, watchFired(ws))
|
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
|
2022-05-19 19:21:44 +00:00
|
|
|
expect := &structs.ExportedServiceList{
|
|
|
|
Services: []structs.ServiceName{
|
|
|
|
{
|
|
|
|
Name: "billing",
|
|
|
|
EnterpriseMeta: *defaultEntMeta,
|
|
|
|
},
|
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
|
|
|
DiscoChains: map[structs.ServiceName]structs.ExportedDiscoveryChainInfo{
|
|
|
|
newSN("billing"): {
|
|
|
|
Protocol: "tcp",
|
|
|
|
TCPTargets: []*structs.DiscoveryTarget{
|
|
|
|
newTarget("billing", "", "dc1"),
|
|
|
|
},
|
|
|
|
},
|
2022-05-25 17:37: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
|
|
|
}
|
2022-06-27 19:37:18 +00:00
|
|
|
idx, got, err := s.ExportedServicesForPeer(ws, id, "dc1")
|
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)
|
|
|
|
require.Equal(t, lastIdx, idx)
|
|
|
|
require.Equal(t, expect, got)
|
|
|
|
})
|
|
|
|
|
2022-05-10 20:25:51 +00:00
|
|
|
testutil.RunStep(t, "config entry with wildcard service names picks up new registrations", 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++
|
2022-05-19 19:21:44 +00:00
|
|
|
require.NoError(t, s.EnsureService(lastIdx, "foo", &structs.NodeService{
|
|
|
|
ID: "payments", Service: "payments", Port: 5000,
|
|
|
|
}))
|
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-19 19:21:44 +00:00
|
|
|
// The proxy will be ignored.
|
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 19:21:44 +00:00
|
|
|
require.NoError(t, s.EnsureService(lastIdx, "foo", &structs.NodeService{
|
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
|
|
|
Kind: structs.ServiceKindConnectProxy,
|
|
|
|
ID: "payments-proxy",
|
|
|
|
Service: "payments-proxy",
|
|
|
|
Port: 5000,
|
2022-05-19 19:21:44 +00:00
|
|
|
}))
|
|
|
|
|
|
|
|
// Ensure everything is L7-capable.
|
|
|
|
ensureConfigEntry(t, &structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
EnterpriseMeta: *defaultEntMeta,
|
|
|
|
})
|
|
|
|
|
|
|
|
ensureConfigEntry(t, &structs.ServiceRouterConfigEntry{
|
|
|
|
Kind: structs.ServiceRouter,
|
|
|
|
Name: "router",
|
|
|
|
EnterpriseMeta: *defaultEntMeta,
|
|
|
|
})
|
|
|
|
|
|
|
|
ensureConfigEntry(t, &structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "splitter",
|
|
|
|
EnterpriseMeta: *defaultEntMeta,
|
|
|
|
Splits: []structs.ServiceSplit{{Weight: 100}},
|
|
|
|
})
|
|
|
|
|
|
|
|
ensureConfigEntry(t, &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "resolver",
|
|
|
|
EnterpriseMeta: *defaultEntMeta,
|
|
|
|
})
|
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(t, watchFired(ws))
|
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
|
2022-05-19 19:21:44 +00:00
|
|
|
expect := &structs.ExportedServiceList{
|
|
|
|
Services: []structs.ServiceName{
|
|
|
|
{
|
|
|
|
Name: "billing",
|
|
|
|
EnterpriseMeta: *defaultEntMeta,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "payments",
|
|
|
|
EnterpriseMeta: *defaultEntMeta,
|
|
|
|
},
|
|
|
|
// NOTE: no payments-proxy here
|
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
|
|
|
DiscoChains: map[structs.ServiceName]structs.ExportedDiscoveryChainInfo{
|
|
|
|
newSN("billing"): {
|
|
|
|
Protocol: "http",
|
2022-05-19 19:21:44 +00:00
|
|
|
},
|
2022-06-27 19:37:18 +00:00
|
|
|
newSN("payments"): {
|
|
|
|
Protocol: "http",
|
2022-05-19 19:21:44 +00:00
|
|
|
},
|
2022-06-27 19:37:18 +00:00
|
|
|
newSN("resolver"): {
|
|
|
|
Protocol: "http",
|
|
|
|
},
|
|
|
|
newSN("router"): {
|
|
|
|
Protocol: "http",
|
|
|
|
},
|
|
|
|
newSN("splitter"): {
|
|
|
|
Protocol: "http",
|
2022-05-19 19:21:44 +00:00
|
|
|
},
|
2022-05-25 17:37: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
|
|
|
}
|
2022-06-27 19:37:18 +00:00
|
|
|
idx, got, err := s.ExportedServicesForPeer(ws, id, "dc1")
|
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)
|
|
|
|
require.Equal(t, lastIdx, idx)
|
2022-05-19 19:21:44 +00:00
|
|
|
require.Equal(t, expect, got)
|
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, "config entry with wildcard service names picks up service deletions", 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, s.DeleteService(lastIdx, "foo", "billing", nil, ""))
|
|
|
|
|
2022-05-19 19:21:44 +00:00
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, s.DeleteConfigEntry(lastIdx, structs.ServiceSplitter, "splitter", 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.True(t, watchFired(ws))
|
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
|
2022-05-19 19:21:44 +00:00
|
|
|
expect := &structs.ExportedServiceList{
|
|
|
|
Services: []structs.ServiceName{
|
|
|
|
{
|
|
|
|
Name: "payments",
|
|
|
|
EnterpriseMeta: *defaultEntMeta,
|
|
|
|
},
|
|
|
|
// NOTE: no payments-proxy here
|
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
|
|
|
DiscoChains: map[structs.ServiceName]structs.ExportedDiscoveryChainInfo{
|
|
|
|
newSN("payments"): {
|
|
|
|
Protocol: "http",
|
2022-05-19 19:21:44 +00:00
|
|
|
},
|
2022-06-27 19:37:18 +00:00
|
|
|
newSN("resolver"): {
|
|
|
|
Protocol: "http",
|
|
|
|
},
|
|
|
|
newSN("router"): {
|
|
|
|
Protocol: "http",
|
2022-05-19 19:21:44 +00:00
|
|
|
},
|
2022-05-25 17:37: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
|
|
|
}
|
2022-06-27 19:37:18 +00:00
|
|
|
idx, got, err := s.ExportedServicesForPeer(ws, id, "dc1")
|
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)
|
|
|
|
require.Equal(t, lastIdx, idx)
|
2022-05-19 19:21:44 +00:00
|
|
|
require.Equal(t, expect, got)
|
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 clears exported services", func(t *testing.T) {
|
2022-05-19 19:21:44 +00:00
|
|
|
expect := &structs.ExportedServiceList{}
|
|
|
|
|
|
|
|
require.NoError(t, s.DeleteConfigEntry(lastIdx, structs.ExportedServices, "default", defaultEntMeta))
|
2022-06-27 19:37:18 +00:00
|
|
|
idx, got, err := s.ExportedServicesForPeer(ws, id, "dc1")
|
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)
|
|
|
|
require.Equal(t, lastIdx, idx)
|
2022-05-19 19:21:44 +00:00
|
|
|
require.Equal(t, expect, got)
|
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-06 19:35:31 +00:00
|
|
|
|
|
|
|
func TestStateStore_PeeringsForService(t *testing.T) {
|
2022-06-08 22:53:32 +00:00
|
|
|
type testPeering struct {
|
|
|
|
peering *pbpeering.Peering
|
|
|
|
delete bool
|
|
|
|
}
|
2022-05-06 19:35:31 +00:00
|
|
|
type testCase struct {
|
|
|
|
name string
|
|
|
|
services []structs.ServiceName
|
2022-06-08 22:53:32 +00:00
|
|
|
peerings []testPeering
|
2022-05-23 16:16:39 +00:00
|
|
|
entry *structs.ExportedServicesConfigEntry
|
2022-05-06 19:35:31 +00:00
|
|
|
query []string
|
|
|
|
expect [][]*pbpeering.Peering
|
|
|
|
expectIdx uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
run := func(t *testing.T, tc testCase) {
|
|
|
|
s := testStateStore(t)
|
|
|
|
|
|
|
|
var lastIdx uint64
|
|
|
|
// Create peerings
|
2022-06-08 22:53:32 +00:00
|
|
|
for _, tp := range tc.peerings {
|
2022-06-21 18:04:08 +00:00
|
|
|
if tp.peering.ID == "" {
|
|
|
|
tp.peering.ID = testUUID()
|
|
|
|
}
|
2022-05-06 19:35:31 +00:00
|
|
|
lastIdx++
|
2022-08-01 14:33:18 +00:00
|
|
|
require.NoError(t, s.PeeringWrite(lastIdx, &pbpeering.PeeringWriteRequest{Peering: tp.peering}))
|
2022-06-08 22:53:32 +00:00
|
|
|
|
|
|
|
// New peerings can't be marked for deletion so there is a two step process
|
|
|
|
// of first creating the peering and then marking it for deletion by setting DeletedAt.
|
|
|
|
if tp.delete {
|
|
|
|
lastIdx++
|
|
|
|
|
|
|
|
copied := pbpeering.Peering{
|
2022-06-21 18:04:08 +00:00
|
|
|
ID: tp.peering.ID,
|
2022-06-08 22:53:32 +00:00
|
|
|
Name: tp.peering.Name,
|
|
|
|
DeletedAt: structs.TimeToProto(time.Now()),
|
|
|
|
}
|
2022-08-01 14:33:18 +00:00
|
|
|
require.NoError(t, s.PeeringWrite(lastIdx, &pbpeering.PeeringWriteRequest{Peering: &copied}))
|
2022-06-08 22:53:32 +00:00
|
|
|
}
|
2022-05-06 19:35:31 +00:00
|
|
|
|
|
|
|
// make sure it got created
|
2022-06-08 22:53:32 +00:00
|
|
|
q := Query{Value: tp.peering.Name}
|
2022-05-06 19:35:31 +00:00
|
|
|
_, p, err := s.PeeringRead(nil, q)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, p)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a Nodes for services
|
|
|
|
svcNode := &structs.Node{Node: "foo", Address: "127.0.0.1"}
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, s.EnsureNode(lastIdx, svcNode))
|
|
|
|
|
|
|
|
// Create the test services
|
|
|
|
for _, svc := range tc.services {
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, s.EnsureService(lastIdx, svcNode.Node, &structs.NodeService{
|
|
|
|
ID: svc.Name,
|
|
|
|
Service: svc.Name,
|
|
|
|
Port: 8080,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the config entries.
|
2022-05-23 16:16:39 +00:00
|
|
|
if tc.entry != nil {
|
2022-05-06 19:35:31 +00:00
|
|
|
lastIdx++
|
2022-05-23 16:16:39 +00:00
|
|
|
require.NoError(t, tc.entry.Normalize())
|
|
|
|
require.NoError(t, s.EnsureConfigEntry(lastIdx, tc.entry))
|
2022-05-06 19:35:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Query for peers.
|
|
|
|
for resultIdx, q := range tc.query {
|
|
|
|
tx := s.db.ReadTxn()
|
|
|
|
defer tx.Abort()
|
|
|
|
idx, peers, err := s.PeeringsForService(nil, q, *acl.DefaultEnterpriseMeta())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, tc.expectIdx, idx)
|
|
|
|
|
|
|
|
// Verify the result, ignoring generated fields
|
|
|
|
require.Len(t, peers, len(tc.expect[resultIdx]))
|
|
|
|
for _, got := range peers {
|
|
|
|
got.ID = ""
|
|
|
|
got.ModifyIndex = 0
|
|
|
|
got.CreateIndex = 0
|
|
|
|
}
|
|
|
|
require.ElementsMatch(t, tc.expect[resultIdx], peers)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cases := []testCase{
|
|
|
|
{
|
|
|
|
name: "no exported services",
|
|
|
|
services: []structs.ServiceName{
|
|
|
|
{Name: "foo"},
|
|
|
|
},
|
2022-06-08 22:53:32 +00:00
|
|
|
peerings: []testPeering{},
|
2022-05-23 16:16:39 +00:00
|
|
|
entry: nil,
|
2022-05-06 19:35:31 +00:00
|
|
|
query: []string{"foo"},
|
|
|
|
expect: [][]*pbpeering.Peering{{}},
|
|
|
|
},
|
2022-06-08 22:53:32 +00:00
|
|
|
{
|
|
|
|
name: "peerings marked for deletion are excluded",
|
|
|
|
services: []structs.ServiceName{
|
|
|
|
{Name: "foo"},
|
|
|
|
},
|
|
|
|
peerings: []testPeering{
|
|
|
|
{
|
|
|
|
peering: &pbpeering.Peering{
|
|
|
|
Name: "peer1",
|
2022-07-04 14:47:58 +00:00
|
|
|
State: pbpeering.PeeringState_PENDING,
|
2022-06-08 22:53:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
peering: &pbpeering.Peering{
|
2022-06-13 14:22:46 +00:00
|
|
|
Name: "peer2",
|
2022-06-08 22:53:32 +00:00
|
|
|
},
|
|
|
|
delete: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
entry: &structs.ExportedServicesConfigEntry{
|
|
|
|
Name: "default",
|
|
|
|
Services: []structs.ExportedService{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Consumers: []structs.ServiceConsumer{
|
|
|
|
{
|
|
|
|
PeerName: "peer1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
PeerName: "peer2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
query: []string{"foo"},
|
|
|
|
expect: [][]*pbpeering.Peering{
|
|
|
|
{
|
2022-07-04 14:47:58 +00:00
|
|
|
{Name: "peer1", State: pbpeering.PeeringState_PENDING},
|
2022-06-08 22:53:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
expectIdx: uint64(6), // config entries max index
|
|
|
|
},
|
2022-05-06 19:35:31 +00:00
|
|
|
{
|
|
|
|
name: "config entry with exact service name",
|
|
|
|
services: []structs.ServiceName{
|
|
|
|
{Name: "foo"},
|
|
|
|
{Name: "bar"},
|
|
|
|
},
|
2022-06-08 22:53:32 +00:00
|
|
|
peerings: []testPeering{
|
|
|
|
{
|
|
|
|
peering: &pbpeering.Peering{
|
|
|
|
Name: "peer1",
|
2022-07-04 14:47:58 +00:00
|
|
|
State: pbpeering.PeeringState_PENDING,
|
2022-06-08 22:53:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
peering: &pbpeering.Peering{
|
|
|
|
Name: "peer2",
|
2022-07-04 14:47:58 +00:00
|
|
|
State: pbpeering.PeeringState_PENDING,
|
2022-06-08 22:53:32 +00:00
|
|
|
},
|
|
|
|
},
|
2022-05-06 19:35:31 +00:00
|
|
|
},
|
2022-05-23 16:16:39 +00:00
|
|
|
entry: &structs.ExportedServicesConfigEntry{
|
|
|
|
Name: "default",
|
|
|
|
Services: []structs.ExportedService{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Consumers: []structs.ServiceConsumer{
|
|
|
|
{
|
|
|
|
PeerName: "peer1",
|
2022-05-06 19:35:31 +00:00
|
|
|
},
|
|
|
|
},
|
2022-05-23 16:16:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "bar",
|
|
|
|
Consumers: []structs.ServiceConsumer{
|
|
|
|
{
|
|
|
|
PeerName: "peer2",
|
2022-05-06 19:35:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
query: []string{"foo", "bar"},
|
|
|
|
expect: [][]*pbpeering.Peering{
|
|
|
|
{
|
2022-07-04 14:47:58 +00:00
|
|
|
{Name: "peer1", State: pbpeering.PeeringState_PENDING},
|
2022-05-06 19:35:31 +00:00
|
|
|
},
|
|
|
|
{
|
2022-07-04 14:47:58 +00:00
|
|
|
{Name: "peer2", State: pbpeering.PeeringState_PENDING},
|
2022-05-06 19:35:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
expectIdx: uint64(6), // config entries max index
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "config entry with wildcard service name",
|
|
|
|
services: []structs.ServiceName{
|
|
|
|
{Name: "foo"},
|
|
|
|
{Name: "bar"},
|
|
|
|
},
|
2022-06-08 22:53:32 +00:00
|
|
|
peerings: []testPeering{
|
|
|
|
{
|
|
|
|
peering: &pbpeering.Peering{
|
|
|
|
Name: "peer1",
|
2022-07-04 14:47:58 +00:00
|
|
|
State: pbpeering.PeeringState_PENDING,
|
2022-06-08 22:53:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
peering: &pbpeering.Peering{
|
|
|
|
Name: "peer2",
|
2022-07-04 14:47:58 +00:00
|
|
|
State: pbpeering.PeeringState_PENDING,
|
2022-06-08 22:53:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
peering: &pbpeering.Peering{
|
|
|
|
Name: "peer3",
|
2022-07-04 14:47:58 +00:00
|
|
|
State: pbpeering.PeeringState_PENDING,
|
2022-06-08 22:53:32 +00:00
|
|
|
},
|
|
|
|
},
|
2022-05-06 19:35:31 +00:00
|
|
|
},
|
2022-05-23 16:16:39 +00:00
|
|
|
entry: &structs.ExportedServicesConfigEntry{
|
|
|
|
Name: "default",
|
|
|
|
Services: []structs.ExportedService{
|
|
|
|
{
|
|
|
|
Name: "*",
|
|
|
|
Consumers: []structs.ServiceConsumer{
|
|
|
|
{
|
|
|
|
PeerName: "peer1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
PeerName: "peer2",
|
2022-05-06 19:35:31 +00:00
|
|
|
},
|
|
|
|
},
|
2022-05-23 16:16:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "bar",
|
|
|
|
Consumers: []structs.ServiceConsumer{
|
|
|
|
{
|
|
|
|
PeerName: "peer3",
|
2022-05-06 19:35:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
query: []string{"foo", "bar"},
|
|
|
|
expect: [][]*pbpeering.Peering{
|
|
|
|
{
|
2022-07-04 14:47:58 +00:00
|
|
|
{Name: "peer1", State: pbpeering.PeeringState_PENDING},
|
|
|
|
{Name: "peer2", State: pbpeering.PeeringState_PENDING},
|
2022-05-06 19:35:31 +00:00
|
|
|
},
|
|
|
|
{
|
2022-07-04 14:47:58 +00:00
|
|
|
{Name: "peer3", State: pbpeering.PeeringState_PENDING},
|
2022-05-06 19:35:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
expectIdx: uint64(7),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
2022-05-10 20:25:51 +00:00
|
|
|
testutil.RunStep(t, tc.name, func(t *testing.T) {
|
2022-05-06 19:35:31 +00:00
|
|
|
run(t, tc)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-05-23 23:57:42 +00:00
|
|
|
|
|
|
|
func TestStore_TrustBundleListByService(t *testing.T) {
|
|
|
|
store := testStateStore(t)
|
|
|
|
entMeta := *acl.DefaultEnterpriseMeta()
|
|
|
|
|
|
|
|
var lastIdx uint64
|
2022-06-27 19:37:18 +00:00
|
|
|
|
|
|
|
ca := &structs.CAConfiguration{
|
|
|
|
Provider: "consul",
|
|
|
|
ClusterID: connect.TestClusterID,
|
|
|
|
}
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, store.CASetConfig(lastIdx, ca))
|
2022-05-23 23:57:42 +00:00
|
|
|
|
2022-06-21 18:04:08 +00:00
|
|
|
var (
|
|
|
|
peerID1 = testUUID()
|
|
|
|
peerID2 = testUUID()
|
|
|
|
)
|
|
|
|
|
2022-06-27 19:37:18 +00:00
|
|
|
ws := memdb.NewWatchSet()
|
2022-05-23 23:57:42 +00:00
|
|
|
testutil.RunStep(t, "no results on initial setup", func(t *testing.T) {
|
2022-06-27 19:37:18 +00:00
|
|
|
idx, resp, err := store.TrustBundleListByService(ws, "foo", "dc1", entMeta)
|
2022-05-23 23:57:42 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, lastIdx, idx)
|
|
|
|
require.Len(t, resp, 0)
|
|
|
|
})
|
|
|
|
|
|
|
|
testutil.RunStep(t, "registering service does not yield trust bundles", func(t *testing.T) {
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, store.EnsureNode(lastIdx, &structs.Node{
|
|
|
|
Node: "my-node",
|
|
|
|
Address: "127.0.0.1",
|
|
|
|
}))
|
|
|
|
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, store.EnsureService(lastIdx, "my-node", &structs.NodeService{
|
|
|
|
ID: "foo-1",
|
|
|
|
Service: "foo",
|
|
|
|
Port: 8000,
|
|
|
|
}))
|
|
|
|
|
|
|
|
require.False(t, watchFired(ws))
|
|
|
|
|
2022-06-27 19:37:18 +00:00
|
|
|
idx, resp, err := store.TrustBundleListByService(ws, "foo", "dc1", entMeta)
|
2022-05-23 23:57:42 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, resp, 0)
|
|
|
|
require.Equal(t, lastIdx-2, idx)
|
|
|
|
})
|
|
|
|
|
|
|
|
testutil.RunStep(t, "creating peering does not yield trust bundles", func(t *testing.T) {
|
|
|
|
lastIdx++
|
2022-08-01 14:33:18 +00:00
|
|
|
require.NoError(t, store.PeeringWrite(lastIdx, &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
ID: peerID1,
|
|
|
|
Name: "peer1",
|
|
|
|
},
|
2022-05-23 23:57:42 +00:00
|
|
|
}))
|
|
|
|
|
|
|
|
// The peering is only watched after the service is exported via config entry.
|
|
|
|
require.False(t, watchFired(ws))
|
|
|
|
|
2022-06-27 19:37:18 +00:00
|
|
|
idx, resp, err := store.TrustBundleListByService(ws, "foo", "dc1", entMeta)
|
2022-05-23 23:57:42 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, resp, 0)
|
2022-06-27 19:37:18 +00:00
|
|
|
require.Equal(t, lastIdx-3, idx)
|
2022-05-23 23:57:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
testutil.RunStep(t, "exporting the service does not yield trust bundles", func(t *testing.T) {
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(lastIdx, &structs.ExportedServicesConfigEntry{
|
|
|
|
Name: "default",
|
|
|
|
Services: []structs.ExportedService{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Consumers: []structs.ServiceConsumer{
|
|
|
|
{
|
|
|
|
PeerName: "peer1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
|
|
|
// The config entry is watched.
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
|
2022-06-27 19:37:18 +00:00
|
|
|
idx, resp, err := store.TrustBundleListByService(ws, "foo", "dc1", entMeta)
|
2022-05-23 23:57:42 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, lastIdx, idx)
|
|
|
|
require.Len(t, resp, 0)
|
|
|
|
})
|
|
|
|
|
|
|
|
testutil.RunStep(t, "trust bundles are returned after they are created", func(t *testing.T) {
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, store.PeeringTrustBundleWrite(lastIdx, &pbpeering.PeeringTrustBundle{
|
|
|
|
TrustDomain: "peer1.com",
|
|
|
|
PeerName: "peer1",
|
|
|
|
RootPEMs: []string{"peer-root-1"},
|
|
|
|
}))
|
|
|
|
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
|
2022-06-27 19:37:18 +00:00
|
|
|
idx, resp, err := store.TrustBundleListByService(ws, "foo", "dc1", entMeta)
|
2022-05-23 23:57:42 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, lastIdx, idx)
|
|
|
|
require.Len(t, resp, 1)
|
|
|
|
require.Equal(t, []string{"peer-root-1"}, resp[0].RootPEMs)
|
|
|
|
})
|
|
|
|
|
|
|
|
testutil.RunStep(t, "trust bundles are not returned after unexporting service", func(t *testing.T) {
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, store.DeleteConfigEntry(lastIdx, structs.ExportedServices, "default", &entMeta))
|
|
|
|
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
|
2022-06-27 19:37:18 +00:00
|
|
|
idx, resp, err := store.TrustBundleListByService(ws, "foo", "dc1", entMeta)
|
2022-05-23 23:57:42 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, lastIdx, idx)
|
|
|
|
require.Len(t, resp, 0)
|
|
|
|
})
|
|
|
|
|
|
|
|
testutil.RunStep(t, "trust bundles are returned after config entry is restored", func(t *testing.T) {
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(lastIdx, &structs.ExportedServicesConfigEntry{
|
|
|
|
Name: "default",
|
|
|
|
Services: []structs.ExportedService{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Consumers: []structs.ServiceConsumer{
|
|
|
|
{
|
|
|
|
PeerName: "peer1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
|
2022-06-27 19:37:18 +00:00
|
|
|
idx, resp, err := store.TrustBundleListByService(ws, "foo", "dc1", entMeta)
|
2022-05-23 23:57:42 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, lastIdx, idx)
|
|
|
|
require.Len(t, resp, 1)
|
|
|
|
require.Equal(t, []string{"peer-root-1"}, resp[0].RootPEMs)
|
|
|
|
})
|
|
|
|
|
|
|
|
testutil.RunStep(t, "bundles for other peers are ignored", func(t *testing.T) {
|
|
|
|
lastIdx++
|
2022-08-01 14:33:18 +00:00
|
|
|
require.NoError(t, store.PeeringWrite(lastIdx, &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
ID: peerID2,
|
|
|
|
Name: "peer2",
|
|
|
|
},
|
2022-05-23 23:57:42 +00:00
|
|
|
}))
|
|
|
|
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, store.PeeringTrustBundleWrite(lastIdx, &pbpeering.PeeringTrustBundle{
|
|
|
|
TrustDomain: "peer2.com",
|
|
|
|
PeerName: "peer2",
|
|
|
|
RootPEMs: []string{"peer-root-2"},
|
|
|
|
}))
|
|
|
|
|
|
|
|
// No relevant changes.
|
|
|
|
require.False(t, watchFired(ws))
|
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
|
2022-06-27 19:37:18 +00:00
|
|
|
idx, resp, err := store.TrustBundleListByService(ws, "foo", "dc1", entMeta)
|
2022-05-23 23:57:42 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, lastIdx-2, idx)
|
|
|
|
require.Len(t, resp, 1)
|
|
|
|
require.Equal(t, []string{"peer-root-1"}, resp[0].RootPEMs)
|
|
|
|
})
|
|
|
|
|
|
|
|
testutil.RunStep(t, "second bundle is returned when service is exported to that peer", func(t *testing.T) {
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(lastIdx, &structs.ExportedServicesConfigEntry{
|
|
|
|
Name: "default",
|
|
|
|
Services: []structs.ExportedService{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Consumers: []structs.ServiceConsumer{
|
|
|
|
{
|
|
|
|
PeerName: "peer1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
PeerName: "peer2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
|
2022-06-27 19:37:18 +00:00
|
|
|
idx, resp, err := store.TrustBundleListByService(ws, "foo", "dc1", entMeta)
|
2022-05-23 23:57:42 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, lastIdx, idx)
|
|
|
|
require.Len(t, resp, 2)
|
|
|
|
require.Equal(t, []string{"peer-root-1"}, resp[0].RootPEMs)
|
|
|
|
require.Equal(t, []string{"peer-root-2"}, resp[1].RootPEMs)
|
|
|
|
})
|
|
|
|
|
|
|
|
testutil.RunStep(t, "deleting the peering excludes its trust bundle", func(t *testing.T) {
|
|
|
|
lastIdx++
|
2022-08-01 14:33:18 +00:00
|
|
|
require.NoError(t, store.PeeringWrite(lastIdx, &pbpeering.PeeringWriteRequest{
|
|
|
|
Peering: &pbpeering.Peering{
|
|
|
|
ID: peerID1,
|
|
|
|
Name: "peer1",
|
|
|
|
DeletedAt: structs.TimeToProto(time.Now()),
|
|
|
|
},
|
2022-06-08 22:53:32 +00:00
|
|
|
}))
|
2022-05-23 23:57:42 +00:00
|
|
|
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
|
2022-06-27 19:37:18 +00:00
|
|
|
idx, resp, err := store.TrustBundleListByService(ws, "foo", "dc1", entMeta)
|
2022-05-23 23:57:42 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, lastIdx, idx)
|
|
|
|
require.Len(t, resp, 1)
|
|
|
|
require.Equal(t, []string{"peer-root-2"}, resp[0].RootPEMs)
|
|
|
|
})
|
|
|
|
|
|
|
|
testutil.RunStep(t, "deleting the service does not excludes its trust bundle", func(t *testing.T) {
|
|
|
|
lastIdx++
|
|
|
|
require.NoError(t, store.DeleteService(lastIdx, "my-node", "foo-1", &entMeta, ""))
|
|
|
|
|
|
|
|
require.False(t, watchFired(ws))
|
|
|
|
|
2022-06-27 19:37:18 +00:00
|
|
|
idx, resp, err := store.TrustBundleListByService(ws, "foo", "dc1", entMeta)
|
2022-05-23 23:57:42 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, lastIdx-1, idx)
|
|
|
|
require.Len(t, resp, 1)
|
|
|
|
require.Equal(t, []string{"peer-root-2"}, resp[0].RootPEMs)
|
|
|
|
})
|
|
|
|
}
|
2022-06-08 22:53:32 +00:00
|
|
|
|
|
|
|
func TestStateStore_Peering_ListDeleted(t *testing.T) {
|
|
|
|
s := testStateStore(t)
|
|
|
|
|
|
|
|
// Insert one active peering and two marked for deletion.
|
|
|
|
{
|
|
|
|
tx := s.db.WriteTxn(0)
|
|
|
|
defer tx.Abort()
|
|
|
|
|
|
|
|
err := tx.Insert(tablePeering, &pbpeering.Peering{
|
|
|
|
Name: "foo",
|
|
|
|
Partition: acl.DefaultPartitionName,
|
2022-06-21 18:04:08 +00:00
|
|
|
ID: testFooPeerID,
|
2022-06-08 22:53:32 +00:00
|
|
|
DeletedAt: structs.TimeToProto(time.Now()),
|
|
|
|
CreateIndex: 1,
|
|
|
|
ModifyIndex: 1,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = tx.Insert(tablePeering, &pbpeering.Peering{
|
|
|
|
Name: "bar",
|
|
|
|
Partition: acl.DefaultPartitionName,
|
2022-06-21 18:04:08 +00:00
|
|
|
ID: testBarPeerID,
|
2022-06-08 22:53:32 +00:00
|
|
|
CreateIndex: 2,
|
|
|
|
ModifyIndex: 2,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = tx.Insert(tablePeering, &pbpeering.Peering{
|
|
|
|
Name: "baz",
|
|
|
|
Partition: acl.DefaultPartitionName,
|
2022-06-21 18:04:08 +00:00
|
|
|
ID: testBazPeerID,
|
2022-06-08 22:53:32 +00:00
|
|
|
DeletedAt: structs.TimeToProto(time.Now()),
|
|
|
|
CreateIndex: 3,
|
|
|
|
ModifyIndex: 3,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = tx.Insert(tableIndex, &IndexEntry{
|
|
|
|
Key: tablePeering,
|
|
|
|
Value: 3,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, tx.Commit())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
idx, deleted, err := s.PeeringListDeleted(nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, uint64(3), idx)
|
|
|
|
require.Len(t, deleted, 2)
|
|
|
|
|
|
|
|
var names []string
|
|
|
|
for _, peering := range deleted {
|
|
|
|
names = append(names, peering.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
require.ElementsMatch(t, []string{"foo", "baz"}, names)
|
|
|
|
}
|