Skip to content

Commit

Permalink
fix a bug in upgrade test
Browse files Browse the repository at this point in the history
  • Loading branch information
huikang committed Aug 7, 2023
1 parent b1d2229 commit ad79429
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
27 changes: 21 additions & 6 deletions test/integration/consul-container/libs/cluster/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import (
"path/filepath"
"testing"

"github.com/hashicorp/go-version"
"github.com/stretchr/testify/require"
"golang.org/x/mod/semver"

"github.com/hashicorp/consul/test/integration/consul-container/libs/utils"
)

// TODO: switch from semver to go-version

const (
remoteCertDirectory = "/consul/config/certs"

Expand Down Expand Up @@ -68,6 +66,7 @@ type BuildOptions struct {
// cluster when none is specified.
ConsulImageName string

// TODO: switch from string to go-version.Version type
// ConsulVersion is the default Consul version for agents in the cluster
// when none is specified.
ConsulVersion string
Expand Down Expand Up @@ -207,7 +206,8 @@ func NewConfigBuilder(ctx *BuildContext) *Builder {
b.conf.Set("ports.http", 8500)
}

if ctx.consulVersion == "local" || semver.Compare("v"+ctx.consulVersion, "v1.14.0") >= 0 {
tmpVersion, _ := version.NewVersion(ctx.consulVersion)
if ctx.consulVersion == "local" || tmpVersion.GreaterThanOrEqual(utils.Version_1_14) {
// Enable GRPCTLS for version after v1.14.0
b.conf.Set("ports.grpc_tls", 8503)
}
Expand All @@ -220,7 +220,8 @@ func NewConfigBuilder(ctx *BuildContext) *Builder {

ls := string(ctx.logStore)
if ls != "" && (ctx.consulVersion == "local" ||
semver.Compare("v"+ctx.consulVersion, "v1.15.0") >= 0) {
// semver.Compare("v"+ctx.consulVersion, "v1.15.0") >= 0) {
tmpVersion.GreaterThanOrEqual(utils.Version_1_15)) {
// Enable logstore backend for version after v1.15.0
if ls != string(LogStore_WAL) && ls != string(LogStore_BoltDB) {
ls = string(LogStore_BoltDB)
Expand Down Expand Up @@ -269,6 +270,13 @@ func (b *Builder) Datacenter(name string) *Builder {
}

func (b *Builder) Peering(enable bool) *Builder {
if b.context.consulVersion != "local" {
tmpVersion, _ := version.NewVersion(b.context.consulVersion)
if tmpVersion.LessThan(utils.Version_1_14) {
return b
}
}

b.conf.Set("peering.enabled", enable)
return b
}
Expand Down Expand Up @@ -372,7 +380,14 @@ func (b *Builder) injectContextOptions(t *testing.T) {
if b.context.injectAutoEncryption {
if server {
b.conf.Set("auto_encrypt.allow_tls", true) // This setting is different between client and servers
b.conf.Set("tls.grpc.use_auto_cert", true) // This is required for peering to work over the non-GRPC_TLS port
if b.context.consulVersion == "local" {
b.conf.Set("tls.grpc.use_auto_cert", true) // This is required for peering to work over the non-GRPC_TLS port
} else {
tmpVersion, _ := version.NewVersion(b.context.consulVersion)
if tmpVersion.GreaterThanOrEqual(utils.Version_1_14) {
b.conf.Set("tls.grpc.use_auto_cert", true) // This is required for peering to work over the non-GRPC_TLS port
}
}
// VerifyIncoming does not apply to client agents for auto-encrypt
} else {
b.conf.Set("auto_encrypt.tls", true) // This setting is different between client and servers
Expand Down
1 change: 1 addition & 0 deletions test/integration/consul-container/libs/utils/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (

Debug bool
Version_1_14, _ = version.NewVersion("1.14")
Version_1_15, _ = version.NewVersion("1.15")
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,19 @@ var (
func TestStandardUpgradeToTarget_fromLatest(t *testing.T) {
tcs = append(tcs,
testcase{
// Use the case of "1.12.3" ==> "1.13.0" to verify the test can
// Use the case of "1.12.3" ==> "1.13.0" to verify the upgrade test can
// catch the upgrade bug found in snapshot of 1.13.0
oldVersion: "1.12.3",
targetVersion: "1.13.0",
expectErr: true,
},
testcase{
// Use the case of "1.12.3" ==> "1.13.1" to verify the upgrade test can
// pass after the above bug fixed in 1.13.1
oldVersion: "1.12.3",
targetVersion: "1.13.1",
expectErr: false,
},
)

tcs = append(tcs, testcase{
Expand All @@ -52,7 +59,7 @@ func TestStandardUpgradeToTarget_fromLatest(t *testing.T) {
const numServers = 1
buildOpts := &libcluster.BuildOptions{
ConsulImageName: utils.GetLatestImageName(),
ConsulVersion: utils.LatestVersion,
ConsulVersion: tc.oldVersion,
Datacenter: "dc1",
InjectAutoEncryption: true,
}
Expand Down Expand Up @@ -116,7 +123,7 @@ func TestStandardUpgradeToTarget_fromLatest(t *testing.T) {
require.Equal(r, serviceName, service[0].ServiceName)
})
} else {
require.ErrorContains(t, err, "context deadline exceeded")
require.ErrorContains(t, err, "failed to start container")
}
}

Expand Down

0 comments on commit ad79429

Please sign in to comment.