diff --git a/plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/capacity/CephOsdGroupCapacityHelper.java b/plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/capacity/CephOsdGroupCapacityHelper.java index ddd4c2f9901..f9dc2d01fe6 100644 --- a/plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/capacity/CephOsdGroupCapacityHelper.java +++ b/plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/capacity/CephOsdGroupCapacityHelper.java @@ -1,6 +1,7 @@ package org.zstack.storage.ceph.primary.capacity; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowire; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Configurable; @@ -238,7 +239,7 @@ public Long calculateAvailableCapacityByRatio(CephOsdGroupVO osdGroup, String pr for (String poolName : poolNames) { String installPathPrefix = String.format("ceph://%s", poolName); long volSize = volumes.parallelStream() - .filter(v -> v.getInstallPath() != null && v.getInstallPath() + .filter(v -> !StringUtils.isEmpty(v.getInstallPath()) && v.getInstallPath() .substring(0, v.getInstallPath().lastIndexOf("/")) .equals((installPathPrefix))) .map(VolumeVO::getSize) @@ -246,7 +247,7 @@ public Long calculateAvailableCapacityByRatio(CephOsdGroupVO osdGroup, String pr .reduce(0L, Long::sum); long imageCacheSize = imageCaches.parallelStream() - .filter(v -> v.getInstallUrl() != null && v.getInstallUrl() + .filter(v -> !StringUtils.isEmpty(v.getInstallUrl()) && v.getInstallUrl() .substring(0, v.getInstallUrl().lastIndexOf("/")) .equals((installPathPrefix))) .map(ImageCacheVO::getSize) @@ -254,7 +255,7 @@ public Long calculateAvailableCapacityByRatio(CephOsdGroupVO osdGroup, String pr .reduce(0L, Long::sum); long snapShotSize = snapshots.parallelStream() - .filter(v -> v.getPrimaryStorageInstallPath() != null && v.getPrimaryStorageInstallPath() + .filter(v -> !StringUtils.isEmpty(v.getPrimaryStorageInstallPath()) && v.getPrimaryStorageInstallPath() .substring(0, v.getPrimaryStorageInstallPath().lastIndexOf("/")) .equals((installPathPrefix))) .map(VolumeSnapshotVO::getSize) diff --git a/test/src/test/groovy/org/zstack/test/integration/storage/primary/ceph/xsky/capacity/CephXskyPoolCapacityCase.groovy b/test/src/test/groovy/org/zstack/test/integration/storage/primary/ceph/xsky/capacity/CephXskyPoolCapacityCase.groovy index 356599909f6..4049b6a3c9c 100644 --- a/test/src/test/groovy/org/zstack/test/integration/storage/primary/ceph/xsky/capacity/CephXskyPoolCapacityCase.groovy +++ b/test/src/test/groovy/org/zstack/test/integration/storage/primary/ceph/xsky/capacity/CephXskyPoolCapacityCase.groovy @@ -51,6 +51,7 @@ class CephXskyPoolCapacityCase extends SubCase { env.create { testReconnectPrimaryStorage() testSkipCalculateCapacityWhichInstallPathIsNull() + testSkipCalculateCapacityWhichInstallPathIsEmpty() } } @@ -205,4 +206,33 @@ class CephXskyPoolCapacityCase extends SubCase { SQL.New(VolumeSnapshotVO.class).eq(VolumeSnapshotVO_.uuid, rootSnapshot.uuid) .set(VolumeSnapshotVO_.primaryStorageInstallPath, volumeSnapshotInstallPath).update() } + + void testSkipCalculateCapacityWhichInstallPathIsEmpty() { + PrimaryStorageInventory ps = env.inventoryByName("ceph-pri") as PrimaryStorageInventory + VmInstanceInventory vm = env.inventoryByName("test-vm") as VmInstanceInventory + + VolumeSnapshotInventory rootSnapshot = createVolumeSnapshot { + name = "root-volume-snapshot-empty-path" + volumeUuid = vm.rootVolumeUuid + } as VolumeSnapshotInventory + + String volumeInstallPath = Q.New(VolumeVO.class).eq(VolumeVO_.uuid, vm.rootVolumeUuid).select(VolumeVO_.installPath) + .findValue() + String volumeSnapshotInstallPath = Q.New(VolumeSnapshotVO.class).eq(VolumeSnapshotVO_.uuid, rootSnapshot.uuid) + .select(VolumeSnapshotVO_.primaryStorageInstallPath) + .findValue() + + // mock install path is empty string + SQL.New(VolumeVO.class).eq(VolumeVO_.uuid, vm.rootVolumeUuid).set(VolumeVO_.installPath, "").update() + SQL.New(VolumeSnapshotVO.class).eq(VolumeSnapshotVO_.uuid, rootSnapshot.uuid) + .set(VolumeSnapshotVO_.primaryStorageInstallPath, "").update() + + reconnectPrimaryStorage { + uuid = ps.uuid + } + + SQL.New(VolumeVO.class).eq(VolumeVO_.uuid, vm.rootVolumeUuid).set(VolumeVO_.installPath, volumeInstallPath).update() + SQL.New(VolumeSnapshotVO.class).eq(VolumeSnapshotVO_.uuid, rootSnapshot.uuid) + .set(VolumeSnapshotVO_.primaryStorageInstallPath, volumeSnapshotInstallPath).update() + } }