Skip to content

Commit

Permalink
upgrade test: add targetimage name as parameter to upgrade function
Browse files Browse the repository at this point in the history
- the image name of latest version and target version could be
  different. Add the parameter of targetImage to the upgrade
  function
  • Loading branch information
huikang committed May 8, 2023
1 parent 166d7a3 commit e7d8714
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 30 deletions.
3 changes: 2 additions & 1 deletion test/integration/consul-container/libs/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (c *Cluster) Remove(n Agent) error {
// helpers below.
//
// This lets us have tests that assert that an upgrade will fail.
func (c *Cluster) StandardUpgrade(t *testing.T, ctx context.Context, targetVersion string) error {
func (c *Cluster) StandardUpgrade(t *testing.T, ctx context.Context, targetImage string, targetVersion string) error {
var err error
// We take a snapshot, but note that we currently do nothing with it.
if c.ACLEnabled {
Expand Down Expand Up @@ -348,6 +348,7 @@ func (c *Cluster) StandardUpgrade(t *testing.T, ctx context.Context, targetVersi

upgradeFn := func(agent Agent, clientFactory func() (*api.Client, error)) error {
config := agent.GetConfig()
config.Image = targetImage
config.Version = targetVersion

if agent.IsServer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type BuiltCluster struct {
// It returns objects of the accepting cluster, dialing cluster, staticServerSvc, and staticClientSvcSidecar
func BasicPeeringTwoClustersSetup(
t *testing.T,
consulImage string,
consulVersion string,
peeringThroughMeshgateway bool,
) (*BuiltCluster, *BuiltCluster) {
Expand All @@ -52,6 +53,7 @@ func BasicPeeringTwoClustersSetup(
NumClients: 1,
BuildOpts: &libcluster.BuildOptions{
Datacenter: "dc1",
ConsulImageName: consulImage,
ConsulVersion: consulVersion,
InjectAutoEncryption: true,
},
Expand All @@ -63,6 +65,7 @@ func BasicPeeringTwoClustersSetup(
NumClients: 1,
BuildOpts: &libcluster.BuildOptions{
Datacenter: "dc2",
ConsulImageName: consulImage,
ConsulVersion: consulVersion,
InjectAutoEncryption: true,
},
Expand Down
7 changes: 7 additions & 0 deletions test/integration/consul-container/libs/utils/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ func GetTargetImageName() string {
return targetImageName
}

func GetLatestImageName() string {
if Debug {
return LatestImageName + "-dbg"
}
return LatestImageName
}

func DockerImage(image, version string) string {
v := image + ":" + version
if image == DefaultImageNameENT && isSemVer(version) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import (
func TestPeering_RotateServerAndCAThenFail_(t *testing.T) {
t.Parallel()

accepting, dialing := libtopology.BasicPeeringTwoClustersSetup(t, utils.TargetVersion, false)
accepting, dialing := libtopology.BasicPeeringTwoClustersSetup(t, utils.GetTargetImageName(), utils.TargetVersion, false)
var (
acceptingCluster = accepting.Cluster
dialingCluster = dialing.Cluster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestACL_NodeToken(t *testing.T) {
NumClients: 1,
BuildOpts: &libcluster.BuildOptions{
Datacenter: "dc1",
ConsulImageName: utils.GetLatestImageName(),
ConsulVersion: utils.LatestVersion,
InjectAutoEncryption: false,
ACLEnabled: true,
Expand All @@ -38,7 +39,7 @@ func TestACL_NodeToken(t *testing.T) {
cluster.Agents[1].GetAgentName())
require.NoError(t, err)

err = cluster.StandardUpgrade(t, context.Background(), utils.TargetVersion)
err = cluster.StandardUpgrade(t, context.Background(), utils.GetTargetImageName(), utils.TargetVersion)
require.NoError(t, err)

// Post upgrade validation: agent token can be used to query the node
Expand Down
8 changes: 4 additions & 4 deletions test/integration/consul-container/test/upgrade/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func TestBasic(t *testing.T) {
t.Parallel()

configCtx := libcluster.NewBuildContext(t, libcluster.BuildOptions{
ConsulImageName: utils.GetTargetImageName(),
ConsulVersion: utils.TargetVersion,
ConsulImageName: utils.GetLatestImageName(),
ConsulVersion: utils.LatestVersion,
})

const numServers = 1
Expand All @@ -32,7 +32,7 @@ func TestBasic(t *testing.T) {
Bootstrap(numServers).
ToAgentConfig(t)
t.Logf("Cluster config:\n%s", serverConf.JSON)
require.Equal(t, utils.TargetVersion, serverConf.Version) // TODO: remove
require.Equal(t, utils.LatestVersion, serverConf.Version) // TODO: remove

cluster, err := libcluster.NewN(t, *serverConf, numServers)
require.NoError(t, err)
Expand All @@ -53,7 +53,7 @@ func TestBasic(t *testing.T) {

// upgrade the cluster to the Target version
t.Logf("initiating standard upgrade to version=%q", utils.TargetVersion)
err = cluster.StandardUpgrade(t, context.Background(), utils.TargetVersion)
err = cluster.StandardUpgrade(t, context.Background(), utils.GetTargetImageName(), utils.TargetVersion)

require.NoError(t, err)
libcluster.WaitForLeader(t, cluster, client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestStandardUpgradeToTarget_fromLatest(t *testing.T) {

run := func(t *testing.T, tc testcase) {
configCtx := libcluster.NewBuildContext(t, libcluster.BuildOptions{
ConsulImageName: utils.GetTargetImageName(),
ConsulImageName: utils.GetLatestImageName(),
ConsulVersion: tc.oldVersion,
})

Expand Down Expand Up @@ -107,7 +107,7 @@ func TestStandardUpgradeToTarget_fromLatest(t *testing.T) {

// upgrade the cluster to the Target version
t.Logf("initiating standard upgrade to version=%q", tc.targetVersion)
err = cluster.StandardUpgrade(t, context.Background(), tc.targetVersion)
err = cluster.StandardUpgrade(t, context.Background(), utils.GetTargetImageName(), tc.targetVersion)

if !tc.expectErr {
require.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ func TestIngressGateway_GRPC_UpgradeToTarget_fromLatest(t *testing.T) {
NumServers: 1,
NumClients: 1,
BuildOpts: &libcluster.BuildOptions{
Datacenter: "dc1",
ConsulVersion: utils.LatestVersion,
Datacenter: "dc1",
ConsulImageName: utils.GetLatestImageName(),
ConsulVersion: utils.LatestVersion,
},
ApplyDefaultProxySettings: true,
})
Expand Down Expand Up @@ -117,7 +118,7 @@ func TestIngressGateway_GRPC_UpgradeToTarget_fromLatest(t *testing.T) {
}

t.Logf("Upgrade to version %s", utils.TargetVersion)
err = cluster.StandardUpgrade(t, context.Background(), utils.TargetVersion)
err = cluster.StandardUpgrade(t, context.Background(), utils.GetTargetImageName(), utils.TargetVersion)
require.NoError(t, err)
require.NoError(t, igw.Restart())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ func TestIngressGateway_SDS_UpgradeToTarget_fromLatest(t *testing.T) {
NumServers: 1,
NumClients: 2,
BuildOpts: &libcluster.BuildOptions{
Datacenter: "dc1",
ConsulVersion: utils.LatestVersion,
Datacenter: "dc1",
ConsulImageName: utils.GetLatestImageName(),
ConsulVersion: utils.LatestVersion,
},
ApplyDefaultProxySettings: true,
})
Expand Down Expand Up @@ -274,7 +275,7 @@ func TestIngressGateway_SDS_UpgradeToTarget_fromLatest(t *testing.T) {

// Upgrade the cluster to utils.TargetVersion
t.Logf("Upgrade to version %s", utils.TargetVersion)
err = cluster.StandardUpgrade(t, context.Background(), utils.TargetVersion)
err = cluster.StandardUpgrade(t, context.Background(), utils.GetTargetImageName(), utils.TargetVersion)
require.NoError(t, err)
require.NoError(t, igw.Restart())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ func TestIngressGateway_UpgradeToTarget_fromLatest(t *testing.T) {
NumServers: 1,
NumClients: 2,
BuildOpts: &libcluster.BuildOptions{
Datacenter: "dc1",
ConsulVersion: utils.LatestVersion,
Datacenter: "dc1",
ConsulImageName: utils.GetLatestImageName(),
ConsulVersion: utils.LatestVersion,
},
ApplyDefaultProxySettings: true,
})
Expand Down Expand Up @@ -481,7 +482,7 @@ func TestIngressGateway_UpgradeToTarget_fromLatest(t *testing.T) {

// Upgrade the cluster to utils.utils.TargetVersion
t.Logf("Upgrade to version %s", utils.TargetVersion)
err = cluster.StandardUpgrade(t, context.Background(), utils.TargetVersion)
err = cluster.StandardUpgrade(t, context.Background(), utils.GetTargetImageName(), utils.TargetVersion)
require.NoError(t, err)
require.NoError(t, igw.Restart())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestTrafficManagement_ResolveDefaultSubset(t *testing.T) {
assertionFn()

// Upgrade cluster, restart sidecars then begin service traffic validation
require.NoError(t, cluster.StandardUpgrade(t, context.Background(), utils.TargetVersion))
require.NoError(t, cluster.StandardUpgrade(t, context.Background(), utils.GetTargetImageName(), utils.TargetVersion))
require.NoError(t, staticClientProxy.Restart())
require.NoError(t, staticServerProxy.Restart())
require.NoError(t, serverConnectProxyV1.Restart())
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestTrafficManagement_ResolverDefaultOnlyPassing(t *testing.T) {
assertionFn()

// Upgrade cluster, restart sidecars then begin service traffic validation
require.NoError(t, cluster.StandardUpgrade(t, context.Background(), utils.TargetVersion))
require.NoError(t, cluster.StandardUpgrade(t, context.Background(), utils.GetTargetImageName(), utils.TargetVersion))
require.NoError(t, staticClientProxy.Restart())
require.NoError(t, staticServerProxy.Restart())
require.NoError(t, serverConnectProxyV1.Restart())
Expand Down Expand Up @@ -307,7 +307,7 @@ func TestTrafficManagement_ResolverSubsetRedirect(t *testing.T) {
assertionFn()

// Upgrade cluster, restart sidecars then begin service traffic validation
require.NoError(t, cluster.StandardUpgrade(t, context.Background(), utils.TargetVersion))
require.NoError(t, cluster.StandardUpgrade(t, context.Background(), utils.GetTargetImageName(), utils.TargetVersion))
require.NoError(t, staticClientProxy.Restart())
require.NoError(t, staticServerProxy.Restart())
require.NoErrorf(t, server2ConnectProxy.Restart(), "%s", server2ConnectProxy.GetName())
Expand All @@ -320,6 +320,7 @@ func TestTrafficManagement_ResolverSubsetRedirect(t *testing.T) {

func setup(t *testing.T) (*libcluster.Cluster, libservice.Service, libservice.Service) {
buildOpts := &libcluster.BuildOptions{
ConsulImageName: utils.GetLatestImageName(),
ConsulVersion: utils.LatestVersion,
Datacenter: "dc1",
InjectAutoEncryption: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
func TestPeering_ControlPlaneMGW(t *testing.T) {
t.Parallel()

accepting, dialing := libtopology.BasicPeeringTwoClustersSetup(t, utils.LatestVersion, true)
accepting, dialing := libtopology.BasicPeeringTwoClustersSetup(t, utils.GetLatestImageName(), utils.LatestVersion, true)
var (
acceptingCluster = accepting.Cluster
dialingCluster = dialing.Cluster
Expand All @@ -51,11 +51,11 @@ func TestPeering_ControlPlaneMGW(t *testing.T) {
"upstream_cx_total", 1)

// Upgrade the accepting cluster and assert peering is still ACTIVE
require.NoError(t, acceptingCluster.StandardUpgrade(t, context.Background(), utils.TargetVersion))
require.NoError(t, acceptingCluster.StandardUpgrade(t, context.Background(), utils.GetTargetImageName(), utils.TargetVersion))
libassert.PeeringStatus(t, acceptingClient, libtopology.AcceptingPeerName, api.PeeringStateActive)
libassert.PeeringStatus(t, dialingClient, libtopology.DialingPeerName, api.PeeringStateActive)

require.NoError(t, dialingCluster.StandardUpgrade(t, context.Background(), utils.TargetVersion))
require.NoError(t, dialingCluster.StandardUpgrade(t, context.Background(), utils.GetTargetImageName(), utils.TargetVersion))
libassert.PeeringStatus(t, acceptingClient, libtopology.AcceptingPeerName, api.PeeringStateActive)
libassert.PeeringStatus(t, dialingClient, libtopology.DialingPeerName, api.PeeringStateActive)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (

func TestPeering_Basic(t *testing.T) {
t.Parallel()
accepting, dialing := libtopology.BasicPeeringTwoClustersSetup(t, utils.LatestVersion, false)
accepting, dialing := libtopology.BasicPeeringTwoClustersSetup(t, utils.GetLatestImageName(), utils.LatestVersion, false)
peeringUpgrade(t, accepting, dialing, utils.TargetVersion)
peeringPostUpgradeValidation(t, dialing)
}

func TestPeering_HTTPRouter(t *testing.T) {
t.Parallel()
accepting, dialing := libtopology.BasicPeeringTwoClustersSetup(t, utils.LatestVersion, false)
accepting, dialing := libtopology.BasicPeeringTwoClustersSetup(t, utils.GetLatestImageName(), utils.LatestVersion, false)
acceptingCluster := accepting.Cluster

// Create a second static-server at the client agent of accepting cluster and
Expand Down Expand Up @@ -90,7 +90,7 @@ func TestPeering_HTTPRouter(t *testing.T) {
func TestPeering_HTTPResolverAndFailover(t *testing.T) {
t.Parallel()

accepting, dialing := libtopology.BasicPeeringTwoClustersSetup(t, utils.LatestVersion, false)
accepting, dialing := libtopology.BasicPeeringTwoClustersSetup(t, utils.GetLatestImageName(), utils.LatestVersion, false)
dialingCluster := dialing.Cluster

require.NoError(t, dialingCluster.ConfigEntryWrite(&api.ProxyConfigEntry{
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestPeering_HTTPResolverAndFailover(t *testing.T) {
func TestPeering_HTTPResolverAndSplitter(t *testing.T) {
t.Parallel()

accepting, dialing := libtopology.BasicPeeringTwoClustersSetup(t, utils.LatestVersion, false)
accepting, dialing := libtopology.BasicPeeringTwoClustersSetup(t, utils.GetLatestImageName(), utils.LatestVersion, false)
dialingCluster := dialing.Cluster

require.NoError(t, dialingCluster.ConfigEntryWrite(&api.ProxyConfigEntry{
Expand Down Expand Up @@ -295,11 +295,11 @@ func peeringUpgrade(t *testing.T, accepting, dialing *libtopology.BuiltCluster,
_, staticClientPort := dialing.Container.GetAddr()

// Upgrade the accepting cluster and assert peering is still ACTIVE
require.NoError(t, accepting.Cluster.StandardUpgrade(t, context.Background(), targetVersion))
require.NoError(t, accepting.Cluster.StandardUpgrade(t, context.Background(), utils.GetTargetImageName(), targetVersion))
libassert.PeeringStatus(t, acceptingClient, libtopology.AcceptingPeerName, api.PeeringStateActive)
libassert.PeeringStatus(t, dialingClient, libtopology.DialingPeerName, api.PeeringStateActive)

require.NoError(t, dialing.Cluster.StandardUpgrade(t, context.Background(), targetVersion))
require.NoError(t, dialing.Cluster.StandardUpgrade(t, context.Background(), utils.GetTargetImageName(), targetVersion))
libassert.PeeringStatus(t, acceptingClient, libtopology.AcceptingPeerName, api.PeeringStateActive)
libassert.PeeringStatus(t, dialingClient, libtopology.DialingPeerName, api.PeeringStateActive)

Expand Down

0 comments on commit e7d8714

Please sign in to comment.