From 0ca070b301ad27f6c2e5be9c658d3681de44fc72 Mon Sep 17 00:00:00 2001 From: cskh Date: Fri, 8 Dec 2023 12:22:16 -0500 Subject: [PATCH] upgrade test(LTS): add segments to version 1.10 (#19861) --- .../usage_profiles/sd_wan_segments_test.go | 70 ------------------- testing/deployer/sprawl/acl.go | 2 + testing/deployer/sprawl/boot.go | 4 +- testing/deployer/sprawl/details.go | 18 ++++- .../deployer/sprawl/internal/tfgen/agent.go | 18 +++++ testing/deployer/topology/topology.go | 11 +++ 6 files changed, 50 insertions(+), 73 deletions(-) delete mode 100644 test-integ/upgrade/usage_profiles/sd_wan_segments_test.go diff --git a/test-integ/upgrade/usage_profiles/sd_wan_segments_test.go b/test-integ/upgrade/usage_profiles/sd_wan_segments_test.go deleted file mode 100644 index 98a0873c17..0000000000 --- a/test-integ/upgrade/usage_profiles/sd_wan_segments_test.go +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: BUSL-1.1 - -package usage_profiles - -import ( - "testing" - "time" - - "github.com/stretchr/testify/require" - - "github.com/hashicorp/consul/test/integration/consul-container/libs/utils" - "github.com/hashicorp/consul/testing/deployer/sprawl" - "github.com/hashicorp/consul/testing/deployer/sprawl/sprawltest" - "github.com/hashicorp/consul/testing/deployer/topology" -) - -const ( - // The long term support version - ltsVersion = "1.15.7" -) - -// Test_Upgrade_ServiceDiscovery_Wan_Segment test upgrade from a source version -// to a specified long term support version -// Clusters: multi-segment and multi-cluster (TODO) -// Workload: service discovery (no mesh) (TODO) -func Test_Upgrade_ServiceDiscovery_Wan_Segment(t *testing.T) { - utils.LatestVersion = "1.10.8" - utils.TargetVersion = ltsVersion - - dc1, err := createTopology("dc1") - require.NoError(t, err) - t.Log("Created topology:", dc1.Name, "enterprise:", utils.IsEnterprise()) - - toplogyConfig := &topology.Config{ - Networks: []*topology.Network{ - {Name: "dc1"}, - }, - } - toplogyConfig.Clusters = append(toplogyConfig.Clusters, dc1) - sp := sprawltest.Launch(t, toplogyConfig) - - cfg := sp.Config() - require.NoError(t, sp.Upgrade(cfg, "dc1", sprawl.UpgradeTypeStandard, utils.TargetImages(), nil)) - t.Log("Finished standard upgrade ...") - - time.Sleep(30 * time.Second) -} - -func createTopology(name string) (*topology.Cluster, error) { - clu := &topology.Cluster{ - Name: name, - Images: utils.LatestImages(), - Nodes: []*topology.Node{ - { - Kind: topology.NodeKindServer, - Name: "dc1-server1", - Addresses: []*topology.Address{ - {Network: "dc1"}, - }, - }, - { - Kind: topology.NodeKindClient, - Name: "dc1-client1", - }, - }, - Enterprise: utils.IsEnterprise(), - } - return clu, nil -} diff --git a/testing/deployer/sprawl/acl.go b/testing/deployer/sprawl/acl.go index 92f4701840..2f5cdcc160 100644 --- a/testing/deployer/sprawl/acl.go +++ b/testing/deployer/sprawl/acl.go @@ -170,6 +170,8 @@ agent_prefix "" { node_prefix "" { policy = "write" } + +operator = "read" ` policy, _, err := acl.PolicyCreate( &api.ACLPolicy{ diff --git a/testing/deployer/sprawl/boot.go b/testing/deployer/sprawl/boot.go index 38407d50ae..8f8aa6cee1 100644 --- a/testing/deployer/sprawl/boot.go +++ b/testing/deployer/sprawl/boot.go @@ -316,7 +316,7 @@ func (s *Sprawl) createFirstTime() error { } for _, cluster := range s.topology.Clusters { if err := s.waitForClientAntiEntropyOnce(cluster); err != nil { - return fmt.Errorf("waitForClientAntiEntropyOnce[%s]: %w", cluster.Name, err) + return fmt.Errorf("create first time - waitForClientAntiEntropyOnce[%s]: %w", cluster.Name, err) } } @@ -447,7 +447,7 @@ func (s *Sprawl) postRegenTasks(firstTime bool) error { for _, cluster := range s.topology.Clusters { if err := s.waitForClientAntiEntropyOnce(cluster); err != nil { - return fmt.Errorf("waitForClientAntiEntropyOnce[%s]: %w", cluster.Name, err) + return fmt.Errorf("post regenerate waitForClientAntiEntropyOnce[%s]: %w", cluster.Name, err) } } diff --git a/testing/deployer/sprawl/details.go b/testing/deployer/sprawl/details.go index d4e6dea45b..4fde28bed2 100644 --- a/testing/deployer/sprawl/details.go +++ b/testing/deployer/sprawl/details.go @@ -10,6 +10,10 @@ import ( "strconv" "strings" "text/tabwriter" + "time" + + retry "github.com/avast/retry-go" + "github.com/hashicorp/consul/api" ) // PrintDetails will dump relevant addressing and naming data to the logger for @@ -22,7 +26,19 @@ func (s *Sprawl) PrintDetails() error { for _, cluster := range s.topology.Clusters { client := s.clients[cluster.Name] - cfg, err := client.Operator().RaftGetConfiguration(nil) + var cfg *api.RaftConfiguration + var err error + err = retry.Do( + func() error { + cfg, err = client.Operator().RaftGetConfiguration(nil) + if err != nil { + return fmt.Errorf("error get raft config: %w", err) + } + return nil + }, + retry.MaxDelay(5*time.Second), + retry.Attempts(15), + ) if err != nil { return fmt.Errorf("could not get raft config for cluster %q: %w", cluster.Name, err) } diff --git a/testing/deployer/sprawl/internal/tfgen/agent.go b/testing/deployer/sprawl/internal/tfgen/agent.go index db68a60b61..05aed6ccdd 100644 --- a/testing/deployer/sprawl/internal/tfgen/agent.go +++ b/testing/deployer/sprawl/internal/tfgen/agent.go @@ -60,6 +60,13 @@ func (g *Generator) generateAgentHCL(node *topology.Node, enableV2, enableV2Tena b.add("retry_interval", "1s") // } + if node.Segment != nil { + b.add("segment", node.Segment.Name) + b.addSlice("retry_join", []string{ + fmt.Sprintf("server.%s-consulcluster.lan:%d", node.Cluster, node.Segment.Port), + }) + } + if node.Images.GreaterThanVersion(topology.MinVersionPeering) { if node.IsServer() { b.addBlock("peering", func() { @@ -209,6 +216,17 @@ func (g *Generator) generateAgentHCL(node *topology.Node, enableV2, enableV2Tena } }) } + + if cluster.Segments != nil { + b.format("segments = [") + for name, port := range cluster.Segments { + b.format("{") + b.add("name", name) + b.add("port", port) + b.format("},") + } + b.format("]") + } } else { if cluster.Enterprise && node.Images.GreaterThanVersion(topology.MinVersionAgentTokenPartition) { b.add("partition", node.Partition) diff --git a/testing/deployer/topology/topology.go b/testing/deployer/topology/topology.go index 46befdb128..8e842ca32d 100644 --- a/testing/deployer/topology/topology.go +++ b/testing/deployer/topology/topology.go @@ -290,6 +290,9 @@ type Cluster struct { // EnableV2Tenancy activates V2 tenancy on the servers. If not enabled, // V2 resources are bridged to V1 tenancy counterparts. EnableV2Tenancy bool `json:",omitempty"` + + // Segments is a map of network segment name and the ports + Segments map[string]int } func (c *Cluster) inheritFromExisting(existing *Cluster) { @@ -485,6 +488,11 @@ const ( NodeVersionV2 NodeVersion = "v2" ) +type NetworkSegment struct { + Name string + Port int +} + // TODO: rename pod type Node struct { Kind NodeKind @@ -530,6 +538,9 @@ type Node struct { // AutopilotConfig of the server agent AutopilotConfig map[string]string + + // Network segment of the agent - applicable to client agent only + Segment *NetworkSegment } func (n *Node) DockerName() string {