From ff34b048e702a389a62c2cb1dba33c1197021c94 Mon Sep 17 00:00:00 2001 From: hc-github-team-nomad-core <82989552+hc-github-team-nomad-core@users.noreply.github.com> Date: Fri, 20 Sep 2024 14:56:33 -0400 Subject: [PATCH] Backport of E2E: allow Consul version to omit tags into release/1.8.x (#24027) Co-authored-by: Tim Gross --- e2e/consulcompat/shared_run_test.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/e2e/consulcompat/shared_run_test.go b/e2e/consulcompat/shared_run_test.go index 33fd4f3bb5a..239edcbf1ca 100644 --- a/e2e/consulcompat/shared_run_test.go +++ b/e2e/consulcompat/shared_run_test.go @@ -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