From 871e603dcaf753ffb8b1fef1d41588a81068afc1 Mon Sep 17 00:00:00 2001 From: Matt Spilchen Date: Wed, 13 Sep 2023 07:07:33 -0400 Subject: [PATCH] Sync from server repo (fecd4672746) --- vclusterops/nma_download_file_op.go | 24 +++++++++++++++++++++--- vclusterops/util/util.go | 3 ++- vclusterops/util/util_test.go | 16 ++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/vclusterops/nma_download_file_op.go b/vclusterops/nma_download_file_op.go index 1eeb9a9..32fb09a 100644 --- a/vclusterops/nma_download_file_op.go +++ b/vclusterops/nma_download_file_op.go @@ -67,6 +67,21 @@ func (e *ClusterLeaseNotExpiredError) Error() string { e.Expiration) } +// ReviveDBNodeCountMismatchError is returned when the number of nodes in new cluster +// does not match the number of nodes in original cluster +type ReviveDBNodeCountMismatchError struct { + ReviveDBStep string + FailureHost string + NumOfNewNodes int + NumOfOldNodes int +} + +func (e *ReviveDBNodeCountMismatchError) Error() string { + return fmt.Sprintf(`[%s] nodes mismatch found on host %s: the number of the new nodes in --hosts is %d,`+ + ` but the number of the old nodes in description file is %d`, + e.ReviveDBStep, e.FailureHost, e.NumOfNewNodes, e.NumOfOldNodes) +} + func makeNMADownloadFileOp(newNodes []string, sourceFilePath, destinationFilePath, catalogPath string, communalStorageParameters map[string]string, vdb *VCoordinationDatabase, displayOnly, ignoreClusterLease bool) (NMADownloadFileOp, error) { op := NMADownloadFileOp{} @@ -195,9 +210,12 @@ func (op *NMADownloadFileOp) processResult(execContext *OpEngineExecContext) err } if len(descFileContent.NodeList) != len(op.newNodes) { - err := fmt.Errorf(`[%s] nodes mismatch found on host %s: the number of the new nodes in --hosts is %d,`+ - ` but the number of the old nodes in description file is %d`, - op.name, host, len(op.newNodes), len(descFileContent.NodeList)) + err := &ReviveDBNodeCountMismatchError{ + ReviveDBStep: op.name, + FailureHost: host, + NumOfNewNodes: len(op.newNodes), + NumOfOldNodes: len(descFileContent.NodeList), + } allErrs = errors.Join(allErrs, err) break } diff --git a/vclusterops/util/util.go b/vclusterops/util/util.go index db0f5e1..411a548 100644 --- a/vclusterops/util/util.go +++ b/vclusterops/util/util.go @@ -253,7 +253,8 @@ func GetCleanPath(path string) string { return path } cleanPath := strings.TrimSpace(path) - cleanPath = strings.ReplaceAll(cleanPath, "//", "/") + // clean and normalize the path + cleanPath = filepath.Clean(cleanPath) return cleanPath } diff --git a/vclusterops/util/util_test.go b/vclusterops/util/util_test.go index 5976c22..e738fe0 100644 --- a/vclusterops/util/util_test.go +++ b/vclusterops/util/util_test.go @@ -118,6 +118,22 @@ func TestGetCleanPath(t *testing.T) { res = GetCleanPath(path) assert.Equal(t, res, "/data") + path = "///data" + res = GetCleanPath(path) + assert.Equal(t, res, "/data") + + path = "////data" + res = GetCleanPath(path) + assert.Equal(t, res, "/data") + + path = "///data/" + res = GetCleanPath(path) + assert.Equal(t, res, "/data") + + path = "//scratch_b/qa/data/" + res = GetCleanPath(path) + assert.Equal(t, res, "/scratch_b/qa/data") + path = "//data " res = GetCleanPath(path) assert.Equal(t, res, "/data")