Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix some of the peering topology tests to safely run without tenancy in CE #19540

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 44 additions & 33 deletions test-integ/peering_commontopo/ac6_failovers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import (
"fmt"
"testing"

"github.com/hashicorp/consul/testing/deployer/topology"
"github.com/stretchr/testify/require"

"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/test/integration/consul-container/libs/utils"
"github.com/hashicorp/consul/testing/deployer/topology"
"github.com/stretchr/testify/require"
)

type ac6FailoversSuite struct {
Expand Down Expand Up @@ -199,8 +198,13 @@ func (s *ac6FailoversSuite) testName() (ret string) {
}

func (s *ac6FailoversSuite) setup(t *testing.T, ct *commonTopo) {
if !utils.IsEnterprise() && (s.NearInPartAlt || s.FarInPartAlt) {
t.Skip("ENT required for nondefault partitions")
if !utils.IsEnterprise() {
if s.NearInPartAlt || s.FarInPartAlt {
t.Skip("ENT required for nondefault partitions")
}
if s.NearInNSAlt || s.FarInNSAlt {
t.Skip("ENT required for nondefault namespaces")
}
}

nearClu := ct.DC1
Expand All @@ -215,8 +219,8 @@ func (s *ac6FailoversSuite) setup(t *testing.T, ct *commonTopo) {
// - server in clientPartition/DC (main target)
nearServerSID := topology.ServiceID{
Name: "ac6-server",
Partition: ConfigEntryPartition("default"),
Namespace: "default",
Partition: defaultToEmptyForCE("default"),
Namespace: defaultToEmptyForCE("default"),
}
if s.NearInPartAlt {
nearServerSID.Partition = "part1"
Expand All @@ -235,16 +239,16 @@ func (s *ac6FailoversSuite) setup(t *testing.T, ct *commonTopo) {
&api.ServiceConfigEntry{
Kind: api.ServiceDefaults,
Name: nearServerSID.Name,
Partition: ConfigEntryPartition(nearServerSID.Partition),
Namespace: nearServerSID.Namespace,
Partition: defaultToEmptyForCE(nearServerSID.Partition),
Namespace: defaultToEmptyForCE(nearServerSID.Namespace),
Protocol: "http",
},
)
// - server in otherPartition/otherDC
farServerSID := topology.ServiceID{
Name: nearServerSID.Name,
Partition: "default",
Namespace: "default",
Partition: defaultToEmptyForCE("default"),
Namespace: defaultToEmptyForCE("default"),
}
if s.FarInPartAlt {
farServerSID.Partition = "part1"
Expand All @@ -262,7 +266,7 @@ func (s *ac6FailoversSuite) setup(t *testing.T, ct *commonTopo) {
ct.ExportService(farClu, farServerSID.Partition,
api.ExportedService{
Name: farServerSID.Name,
Namespace: farServerSID.Namespace,
Namespace: defaultToEmptyForCE(farServerSID.Namespace),
Consumers: []api.ServiceConsumer{
{
Peer: LocalPeerName(nearClu, nearServerSID.Partition),
Expand All @@ -274,7 +278,7 @@ func (s *ac6FailoversSuite) setup(t *testing.T, ct *commonTopo) {
ct.ExportService(farClu, farServerSID.Partition,
api.ExportedService{
Name: farServerSID.Name,
Namespace: farServerSID.Namespace,
Namespace: defaultToEmptyForCE(farServerSID.Namespace),
Consumers: []api.ServiceConsumer{
{
// this must not be "", or else it is basically ignored altogether
Expand All @@ -292,7 +296,7 @@ func (s *ac6FailoversSuite) setup(t *testing.T, ct *commonTopo) {
{
Service: farServerSID.Name,
Peer: LocalPeerName(farClu, farServerSID.Partition),
Namespace: farServerSID.Namespace,
Namespace: defaultToEmptyForCE(farServerSID.Namespace),
},
}
} else {
Expand All @@ -306,8 +310,8 @@ func (s *ac6FailoversSuite) setup(t *testing.T, ct *commonTopo) {
targets = []api.ServiceResolverFailoverTarget{
{
Service: farServerSID.Name,
Partition: part,
Namespace: farServerSID.Namespace,
Partition: defaultToEmptyForCE(part),
Namespace: defaultToEmptyForCE(farServerSID.Namespace),
},
}
}
Expand All @@ -316,15 +320,15 @@ func (s *ac6FailoversSuite) setup(t *testing.T, ct *commonTopo) {
&api.ServiceConfigEntry{
Kind: api.ServiceDefaults,
Name: farServerSID.Name,
Partition: ConfigEntryPartition(farServerSID.Partition),
Namespace: farServerSID.Namespace,
Partition: defaultToEmptyForCE(farServerSID.Partition),
Namespace: defaultToEmptyForCE(farServerSID.Namespace),
Protocol: "http",
},
&api.ServiceResolverConfigEntry{
Kind: api.ServiceResolver,
Name: nearServerSID.Name,
Partition: ConfigEntryPartition(nearServerSID.Partition),
Namespace: nearServerSID.Namespace,
Partition: defaultToEmptyForCE(nearServerSID.Partition),
Namespace: defaultToEmptyForCE(nearServerSID.Namespace),
Failover: map[string]api.ServiceResolverFailover{
"*": {
Targets: targets,
Expand All @@ -335,8 +339,8 @@ func (s *ac6FailoversSuite) setup(t *testing.T, ct *commonTopo) {

clientSID := topology.ServiceID{
Name: "ac6-client",
Partition: nearServerSID.Partition,
Namespace: nearServerSID.Namespace,
Partition: defaultToEmptyForCE(nearServerSID.Partition),
Namespace: defaultToEmptyForCE(nearServerSID.Namespace),
}
client := NewFortioServiceWithDefaults(
nearClu.Datacenter,
Expand All @@ -347,8 +351,8 @@ func (s *ac6FailoversSuite) setup(t *testing.T, ct *commonTopo) {
{
ID: topology.ServiceID{
Name: nearServerSID.Name,
Partition: nearServerSID.Partition,
Namespace: nearServerSID.Namespace,
Partition: defaultToEmptyForCE(nearServerSID.Partition),
Namespace: defaultToEmptyForCE(nearServerSID.Namespace),
},
LocalPort: 5000,
// exposed so we can hit it directly
Expand All @@ -363,8 +367,8 @@ func (s *ac6FailoversSuite) setup(t *testing.T, ct *commonTopo) {
&api.ServiceConfigEntry{
Kind: api.ServiceDefaults,
Name: clientSID.Name,
Partition: ConfigEntryPartition(clientSID.Partition),
Namespace: clientSID.Namespace,
Partition: defaultToEmptyForCE(clientSID.Partition),
Namespace: defaultToEmptyForCE(clientSID.Namespace),
Protocol: "http",
},
)
Expand All @@ -374,21 +378,21 @@ func (s *ac6FailoversSuite) setup(t *testing.T, ct *commonTopo) {
&api.ServiceIntentionsConfigEntry{
Kind: api.ServiceIntentions,
Name: nearServerSID.Name,
Partition: ConfigEntryPartition(nearServerSID.Partition),
Namespace: nearServerSID.Namespace,
Partition: defaultToEmptyForCE(nearServerSID.Partition),
Namespace: defaultToEmptyForCE(nearServerSID.Namespace),
Sources: []*api.SourceIntention{{
Name: clientSID.Name,
Namespace: clientSID.Namespace,
Namespace: defaultToEmptyForCE(clientSID.Namespace),
// in this field, "" -> destination partition, so no ConfigEntryPartition :eyeroll:
// https://developer.hashicorp.com/consul/docs/connect/config-entries/service-intentions#sources-partition
Partition: topology.PartitionOrDefault(clientSID.Partition),
Partition: defaultToEmptyForCE(clientSID.Partition),
Action: api.IntentionActionAllow,
}},
},
)
farSource := api.SourceIntention{
Name: clientSID.Name,
Namespace: clientSID.Namespace,
Namespace: defaultToEmptyForCE(clientSID.Namespace),
Peer: LocalPeerName(nearClu, clientSID.Partition),
Action: api.IntentionActionAllow,
}
Expand All @@ -402,8 +406,8 @@ func (s *ac6FailoversSuite) setup(t *testing.T, ct *commonTopo) {
&api.ServiceIntentionsConfigEntry{
Kind: api.ServiceIntentions,
Name: farServerSID.Name,
Partition: ConfigEntryPartition(farServerSID.Partition),
Namespace: farServerSID.Namespace,
Partition: defaultToEmptyForCE(farServerSID.Partition),
Namespace: defaultToEmptyForCE(farServerSID.Namespace),
Sources: []*api.SourceIntention{&farSource},
},
)
Expand Down Expand Up @@ -464,3 +468,10 @@ func (s *ac6FailoversSuite) test(t *testing.T, ct *commonTopo) {
expectSID.Normalize()
ct.Assert.FortioFetch2FortioName(t, client, upstream, farClu.Name, expectSID)
}

func defaultToEmptyForCE(tenancy string) string {
if utils.IsEnterprise() {
return tenancy
}
return topology.DefaultToEmpty(tenancy)
}
4 changes: 2 additions & 2 deletions test-integ/peering_commontopo/commontopo.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ func (ct *commonTopo) ExportService(clu *topology.Cluster, partition string, svc
if !found {
clu.InitialConfigEntries = append(clu.InitialConfigEntries,
&api.ExportedServicesConfigEntry{
Name: partition, // this NEEDs to be "default" in CE
Partition: ConfigEntryPartition(partition),
Name: topology.PartitionOrDefault(partition), // this NEEDs to be "default" in CE
Partition: topology.DefaultToEmpty(partition),
Services: svcs,
},
)
Expand Down
2 changes: 1 addition & 1 deletion test-integ/topoutil/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func NewTopologyMeshGatewaySet(

node := &topology.Node{
Kind: nodeKind,
Partition: partition,
Partition: sid.Partition,
Name: name,
Services: []*topology.Service{{
ID: sid,
Expand Down
10 changes: 2 additions & 8 deletions testing/deployer/sprawl/peering.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,7 @@ func (s *Sprawl) awaitMeshGateways() {
logger.Info("awaiting MGW readiness")
RETRY:
// TODO: not sure if there's a better way to check if the MGW is ready
svcs, _, err := cl.Catalog().Service(mgw.ID.Name, "", &api.QueryOptions{
Namespace: mgw.ID.Namespace,
Partition: mgw.ID.Partition,
})
svcs, _, err := cl.Catalog().Service(mgw.ID.Name, "", mgw.ID.QueryOptions())
if err != nil {
logger.Debug("fetching MGW service", "err", err)
time.Sleep(time.Second)
Expand All @@ -227,10 +224,7 @@ func (s *Sprawl) awaitMeshGateways() {
log.Fatalf("expected 1 MGW service, actually: %#v", svcs)
}

entries, _, err := cl.Health().Service(mgw.ID.Name, "", true, &api.QueryOptions{
Namespace: mgw.ID.Namespace,
Partition: mgw.ID.Partition,
})
entries, _, err := cl.Health().Service(mgw.ID.Name, "", true, mgw.ID.QueryOptions())
if err != nil {
logger.Debug("fetching MGW checks", "err", err)
time.Sleep(time.Second)
Expand Down
7 changes: 7 additions & 0 deletions testing/deployer/topology/ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ func (id ServiceID) NamespaceOrDefault() string {
return NamespaceOrDefault(id.Namespace)
}

func (id ServiceID) QueryOptions() *api.QueryOptions {
return &api.QueryOptions{
Partition: DefaultToEmpty(id.Partition),
Namespace: DefaultToEmpty(id.Namespace),
}
}

func PartitionOrDefault(name string) string {
if name == "" {
return "default"
Expand Down