From 792730bfc12ed2252b45b63c963a86f9b3e79623 Mon Sep 17 00:00:00 2001 From: Sharon Gratch Date: Thu, 5 Sep 2024 17:58:59 +0300 Subject: [PATCH] Fix Negative number for plan/migration status's VMs count On both plan and migration status fields, the number of displayed migrated VMs within the status' progress bar label is sometimes negative, i.e. the value of X within "X out of Y VMs migrated" is sometimes negative. This is reproduced when at least one VM failed to migrated. The reason is that failed VMs is often marked with an error but their completed value is still set to false since VM's migration was not finished yet. So the calculation of migrated = completed - error < 0. Signed-off-by: Sharon Gratch --- .../src/modules/Plans/utils/helpers/getMigrationVmsCounts.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/forklift-console-plugin/src/modules/Plans/utils/helpers/getMigrationVmsCounts.ts b/packages/forklift-console-plugin/src/modules/Plans/utils/helpers/getMigrationVmsCounts.ts index 4d46b9100..e548cec37 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/utils/helpers/getMigrationVmsCounts.ts +++ b/packages/forklift-console-plugin/src/modules/Plans/utils/helpers/getMigrationVmsCounts.ts @@ -18,13 +18,14 @@ export const getMigrationVmsCounts = (vms: V1beta1PlanStatusMigrationVms[]): Mig ); const vmsCompleted = vms.filter((vm) => vm?.completed); const vmsError = vms.filter((vm) => vm?.error); + const success = vmsCompleted.length - vmsError.length - vmsCanceled.length; return { completed: vmsCompleted.length, total: vms.length, canceled: vmsCanceled.length, error: vmsError.length, - success: vmsCompleted.length - vmsError.length - vmsCanceled.length, + success: success >= 0 ? success : 0, }; };