From b5d2fafd7af48f6db42f6c086b53f2258893ca8c Mon Sep 17 00:00:00 2001 From: cskh Date: Mon, 8 May 2023 12:02:31 -0400 Subject: [PATCH] Upgrade test target image (#17226) * upgrade test: add targetimage name as parameter to upgrade function - the image name of latest version and target version could be different. Add the parameter of targetImage to the upgrade function * fix a bug of expected error --- .../consul-container/libs/cluster/cluster.go | 3 ++- .../libs/topology/peering_topology.go | 3 +++ .../consul-container/libs/utils/version.go | 7 +++++++ .../peering/rotate_server_and_ca_then_fail_test.go | 2 +- .../consul-container/test/upgrade/acl_node_test.go | 3 ++- .../consul-container/test/upgrade/basic_test.go | 8 ++++---- .../test/upgrade/fullstopupgrade_test.go | 6 +++--- .../test/upgrade/ingress_gateway_grpc_test.go | 7 ++++--- .../test/upgrade/ingress_gateway_sds_test.go | 7 ++++--- .../test/upgrade/ingress_gateway_test.go | 7 ++++--- .../resolver_default_subset_test.go | 7 ++++--- .../test/upgrade/peering_control_plane_mgw_test.go | 6 +++--- .../test/upgrade/peering_http_test.go | 12 ++++++------ 13 files changed, 47 insertions(+), 31 deletions(-) diff --git a/test/integration/consul-container/libs/cluster/cluster.go b/test/integration/consul-container/libs/cluster/cluster.go index 98eb2419d..e5f6537c1 100644 --- a/test/integration/consul-container/libs/cluster/cluster.go +++ b/test/integration/consul-container/libs/cluster/cluster.go @@ -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 { @@ -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() { diff --git a/test/integration/consul-container/libs/topology/peering_topology.go b/test/integration/consul-container/libs/topology/peering_topology.go index 6e579db18..87c2743f3 100644 --- a/test/integration/consul-container/libs/topology/peering_topology.go +++ b/test/integration/consul-container/libs/topology/peering_topology.go @@ -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) { @@ -52,6 +53,7 @@ func BasicPeeringTwoClustersSetup( NumClients: 1, BuildOpts: &libcluster.BuildOptions{ Datacenter: "dc1", + ConsulImageName: consulImage, ConsulVersion: consulVersion, InjectAutoEncryption: true, }, @@ -63,6 +65,7 @@ func BasicPeeringTwoClustersSetup( NumClients: 1, BuildOpts: &libcluster.BuildOptions{ Datacenter: "dc2", + ConsulImageName: consulImage, ConsulVersion: consulVersion, InjectAutoEncryption: true, }, diff --git a/test/integration/consul-container/libs/utils/version.go b/test/integration/consul-container/libs/utils/version.go index 4d1ae5af0..705b09a90 100644 --- a/test/integration/consul-container/libs/utils/version.go +++ b/test/integration/consul-container/libs/utils/version.go @@ -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) { diff --git a/test/integration/consul-container/test/peering/rotate_server_and_ca_then_fail_test.go b/test/integration/consul-container/test/peering/rotate_server_and_ca_then_fail_test.go index 9a150d969..ccf5b206c 100644 --- a/test/integration/consul-container/test/peering/rotate_server_and_ca_then_fail_test.go +++ b/test/integration/consul-container/test/peering/rotate_server_and_ca_then_fail_test.go @@ -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 diff --git a/test/integration/consul-container/test/upgrade/acl_node_test.go b/test/integration/consul-container/test/upgrade/acl_node_test.go index 52b0728b5..94886a4e2 100644 --- a/test/integration/consul-container/test/upgrade/acl_node_test.go +++ b/test/integration/consul-container/test/upgrade/acl_node_test.go @@ -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, @@ -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 diff --git a/test/integration/consul-container/test/upgrade/basic_test.go b/test/integration/consul-container/test/upgrade/basic_test.go index e94227dbd..e9483f111 100644 --- a/test/integration/consul-container/test/upgrade/basic_test.go +++ b/test/integration/consul-container/test/upgrade/basic_test.go @@ -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 @@ -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) @@ -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) diff --git a/test/integration/consul-container/test/upgrade/fullstopupgrade_test.go b/test/integration/consul-container/test/upgrade/fullstopupgrade_test.go index dfe6e1a13..51ad8ea74 100644 --- a/test/integration/consul-container/test/upgrade/fullstopupgrade_test.go +++ b/test/integration/consul-container/test/upgrade/fullstopupgrade_test.go @@ -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, }) @@ -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) @@ -122,7 +122,7 @@ func TestStandardUpgradeToTarget_fromLatest(t *testing.T) { require.Equal(r, serviceName, service[0].ServiceName) }) } else { - require.Error(t, fmt.Errorf("context deadline exceeded")) + require.ErrorContains(t, err, "context deadline exceeded") } } diff --git a/test/integration/consul-container/test/upgrade/ingress_gateway_grpc_test.go b/test/integration/consul-container/test/upgrade/ingress_gateway_grpc_test.go index e7d3ff02d..873eabcf0 100644 --- a/test/integration/consul-container/test/upgrade/ingress_gateway_grpc_test.go +++ b/test/integration/consul-container/test/upgrade/ingress_gateway_grpc_test.go @@ -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, }) @@ -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()) diff --git a/test/integration/consul-container/test/upgrade/ingress_gateway_sds_test.go b/test/integration/consul-container/test/upgrade/ingress_gateway_sds_test.go index 3eec4a477..52ee91bac 100644 --- a/test/integration/consul-container/test/upgrade/ingress_gateway_sds_test.go +++ b/test/integration/consul-container/test/upgrade/ingress_gateway_sds_test.go @@ -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, }) @@ -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()) diff --git a/test/integration/consul-container/test/upgrade/ingress_gateway_test.go b/test/integration/consul-container/test/upgrade/ingress_gateway_test.go index 56852a52e..c0acfeb77 100644 --- a/test/integration/consul-container/test/upgrade/ingress_gateway_test.go +++ b/test/integration/consul-container/test/upgrade/ingress_gateway_test.go @@ -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, }) @@ -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()) diff --git a/test/integration/consul-container/test/upgrade/l7_traffic_management/resolver_default_subset_test.go b/test/integration/consul-container/test/upgrade/l7_traffic_management/resolver_default_subset_test.go index d2c99a3ce..d264366fb 100644 --- a/test/integration/consul-container/test/upgrade/l7_traffic_management/resolver_default_subset_test.go +++ b/test/integration/consul-container/test/upgrade/l7_traffic_management/resolver_default_subset_test.go @@ -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()) @@ -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()) @@ -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()) @@ -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, diff --git a/test/integration/consul-container/test/upgrade/peering_control_plane_mgw_test.go b/test/integration/consul-container/test/upgrade/peering_control_plane_mgw_test.go index e341c347a..4e9355657 100644 --- a/test/integration/consul-container/test/upgrade/peering_control_plane_mgw_test.go +++ b/test/integration/consul-container/test/upgrade/peering_control_plane_mgw_test.go @@ -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 @@ -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) diff --git a/test/integration/consul-container/test/upgrade/peering_http_test.go b/test/integration/consul-container/test/upgrade/peering_http_test.go index 76e38ca67..e1cffe470 100644 --- a/test/integration/consul-container/test/upgrade/peering_http_test.go +++ b/test/integration/consul-container/test/upgrade/peering_http_test.go @@ -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 @@ -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{ @@ -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{ @@ -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)