E2E: allow Consul version to omit tags (#24024)

When we start the Consul agent in the `consulcompat` test package, we check that
the version matches the version we expect. But Consul agents may omit non-core
parts of the version string (ex. `1.20.0-rc1` displays `1.20.0`). Compare only
the core portions of the version string.
This commit is contained in:
Tim Gross
2024-09-20 14:46:01 -04:00
committed by GitHub
parent 8bb94ec32d
commit 9247dc9108

View File

@@ -13,6 +13,7 @@ import (
"time"
consulapi "github.com/hashicorp/consul/api"
"github.com/hashicorp/go-version"
"github.com/hashicorp/nomad/api"
nomadapi "github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/helper/uuid"
@@ -23,25 +24,37 @@ import (
// verifyConsulVersion ensures that we've successfully spun up a Consul cluster
// on the expected version (this ensures we don't have stray running Consul from
// previous runs or from the development environment)
func verifyConsulVersion(t *testing.T, consulAPI *consulapi.Client, version string) {
func verifyConsulVersion(t *testing.T, consulAPI *consulapi.Client, expectVersion string) {
self, err := consulAPI.Agent().Self()
must.NoError(t, err)
vers := self["Config"]["Version"].(string)
must.Eq(t, version, vers)
check, err := version.NewSemver(vers)
must.NoError(t, err)
expect, _ := version.NewSemver(expectVersion)
must.Eq(t, expect.Core(), check.Core())
}
// verifyConsulFingerprint ensures that we've successfully fingerprinted Consul
func verifyConsulFingerprint(t *testing.T, nc *nomadapi.Client, version, clusterName string) {
func verifyConsulFingerprint(t *testing.T, nc *nomadapi.Client, expectVersion, clusterName string) {
stubs, _, err := nc.Nodes().List(nil)
must.NoError(t, err)
must.Len(t, 1, stubs)
node, _, err := nc.Nodes().Info(stubs[0].ID, nil)
var vers string
if clusterName == "default" {
must.Eq(t, version, node.Attributes["consul.version"])
vers = node.Attributes["consul.version"]
} else {
must.Eq(t, version, node.Attributes["consul."+clusterName+".version"])
vers = node.Attributes["consul."+clusterName+".version"]
}
check, err := version.NewSemver(vers)
must.NoError(t, err)
expect, _ := version.NewSemver(expectVersion)
must.Eq(t, expect.Core(), check.Core())
}
// setupConsulACLsForServices installs a base set of ACL policies and returns a