From 7fc0d93ee21fd18b68a337051f6fea01b31af5a7 Mon Sep 17 00:00:00 2001 From: Aman Mangal Date: Wed, 2 Aug 2023 16:06:14 +0530 Subject: [PATCH] fix(upgrade): look for version string in logs bottom up (#8926) For in place upgrade, the container remains the same and the logs have the version string twice, one for the old container and one for the new container. We want the version string in the logs for the new container. Hence, we look for the string in the logs bottom up by using strings.LastIndex instead of strings.Index. --- dgraphtest/image.go | 3 ++- dgraphtest/local_cluster.go | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/dgraphtest/image.go b/dgraphtest/image.go index 26d08e106f0..c36ef78f23d 100644 --- a/dgraphtest/image.go +++ b/dgraphtest/image.go @@ -23,6 +23,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "github.com/pkg/errors" ) @@ -137,7 +138,7 @@ func getHash(ref string) (string, error) { if out, err := cmd.CombinedOutput(); err != nil { return "", errors.Wrapf(err, "error while running rev-parse on [%v]\noutput:%v", ref, string(out)) } else { - return string(out), nil + return strings.TrimSpace(string(out)), nil } } diff --git a/dgraphtest/local_cluster.go b/dgraphtest/local_cluster.go index a2c72a5a425..39eac9a2400 100644 --- a/dgraphtest/local_cluster.go +++ b/dgraphtest/local_cluster.go @@ -796,7 +796,11 @@ func (c *LocalCluster) checkDgraphVersion(containerID string) error { if err != nil { return errors.Wrapf(err, "error during checkDgraphVersion for container [%v]", containerID) } - index := strings.Index(contLogs, "Commit SHA-1 : ") + + // During in-place upgrade, container remains same but logs have version string twice + // once for old version, once for new. Want new version string. Look bottom-up using + // LastIndex to get latest version's string. + index := strings.LastIndex(contLogs, "Commit SHA-1 : ") running := strings.Fields(contLogs[index : index+70])[3] // 70 is arbitrary chash, err := getHash(c.GetVersion()) if err != nil { @@ -807,7 +811,7 @@ func (c *LocalCluster) checkDgraphVersion(containerID string) error { return errors.Wrapf(err, "error while getting hash for %v", running) } if chash != rhash { - return errors.Errorf("found different dgraph version than expected [%v]", c.GetVersion()) + return errors.Errorf("found different dgraph version [%v] than expected [%v]", rhash, chash) } return nil }