Repository: kubernetes-sigs/azurefile-csi-driver
Pull request #2404 (2025-03-04 13:22:48)

[release-1.31] fix: incomplete azcopy job state during volume snapshot restore and clone
This is an automated cherry-pick of #2403

/assign andyzhangx

```release-note
fix: incomplete azcopy job state during volume snapshot restore and clone
```


Patch:
diff --git a/pkg/util/util.go b/pkg/util/util.go
index e84466d0c..86abd83a1 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -136,7 +136,7 @@ func (ac *Azcopy) GetAzcopyJob(dstFileshare string, authAzcopyEnv []string) (Azc
 		klog.Warningf("failed to get azcopy job with error: %v, jobState: %v", err, jobState)
 		return AzcopyJobError, "", fmt.Errorf("couldn't parse azcopy job list in azcopy %v", err)
 	}
-	if jobState == AzcopyJobCompleted {
+	if jobState == AzcopyJobCompleted || jobState == AzcopyJobCompletedWithErrors || jobState == AzcopyJobCompletedWithSkipped || jobState == AzcopyJobCompletedWithErrorsAndSkipped {
 		return jobState, "100.0", err
 	}
 	if jobid == "" {
@@ -185,6 +185,12 @@ func parseAzcopyJobList(joblist string) (string, AzcopyJobState, error) {
 			jobid = segments[0]
 		case "Completed":
 			return jobid, AzcopyJobCompleted, nil
+		case "CompletedWithErrors":
+			return jobid, AzcopyJobCompletedWithErrors, nil
+		case "CompletedWithSkipped":
+			return jobid, AzcopyJobCompletedWithSkipped, nil
+		case "CompletedWithErrorsAndSkipped":
+			return jobid, AzcopyJobCompletedWithErrorsAndSkipped, nil
 		}
 	}
 	if jobid == "" {


Test patch:
diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go
index 6380f1775..969958614 100644
--- a/pkg/util/util_test.go
+++ b/pkg/util/util_test.go
@@ -115,6 +115,39 @@ func TestGetAzcopyJob(t *testing.T) {
 			expectedPercent:  "100.0",
 			expectedErr:      nil,
 		},
+		{
+			desc:             "run exec parse azcopy job CompletedWithErrors",
+			listStr:          "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: CompletedWithErrors\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false",
+			listErr:          nil,
+			enableShow:       false,
+			showStr:          "",
+			showErr:          nil,
+			expectedJobState: AzcopyJobCompletedWithErrors,
+			expectedPercent:  "100.0",
+			expectedErr:      nil,
+		},
+		{
+			desc:             "run exec parse azcopy job CompletedWithSkipped",
+			listStr:          "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: CompletedWithSkipped\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false",
+			listErr:          nil,
+			enableShow:       false,
+			showStr:          "",
+			showErr:          nil,
+			expectedJobState: AzcopyJobCompletedWithSkipped,
+			expectedPercent:  "100.0",
+			expectedErr:      nil,
+		},
+		{
+			desc:             "run exec parse azcopy job CompletedWithErrorsAndSkipped",
+			listStr:          "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: CompletedWithErrorsAndSkipped\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false",
+			listErr:          nil,
+			enableShow:       false,
+			showStr:          "",
+			showErr:          nil,
+			expectedJobState: AzcopyJobCompletedWithErrorsAndSkipped,
+			expectedPercent:  "100.0",
+			expectedErr:      nil,
+		},
 		{
 			desc:             "run exec get error in azcopy jobs show",
 			listStr:          "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: InProgress\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false",
@@ -247,6 +280,27 @@ func TestParseAzcopyJobList(t *testing.T) {
 			expectedJobState: AzcopyJobCompleted,
 			expectedErr:      nil,
 		},
+		{
+			desc:             "parse azcopy job CompletedWithErrors",
+			str:              "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: CompletedWithErrors\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false",
+			expectedJobid:    "",
+			expectedJobState: AzcopyJobCompletedWithErrors,
+			expectedErr:      nil,
+		},
+		{
+			desc:             "parse azcopy job CompletedWithSkipped",
+			str:              "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: CompletedWithSkipped\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false",
+			expectedJobid:    "",
+			expectedJobState: AzcopyJobCompletedWithSkipped,
+			expectedErr:      nil,
+		},
+		{
+			desc:             "parse azcopy job CompletedWithErrorsAndSkipped",
+			str:              "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: CompletedWithErrorsAndSkipped\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false",
+			expectedJobid:    "",
+			expectedJobState: AzcopyJobCompletedWithErrorsAndSkipped,
+			expectedErr:      nil,
+		},
 		{
 			desc:             "parse azcopy job InProgress",
 			str:              "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: InProgress\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false",