Skip to content

Commit 971e0c9

Browse files
committed
addressed Copilot reviews
1 parent 642b20f commit 971e0c9

5 files changed

Lines changed: 34 additions & 17 deletions

File tree

‎plugins/backup/nas/src/test/java/org/apache/cloudstack/backup/NASBackupProviderTest.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,11 +802,11 @@ private void mockSourceVolume(String volUuid, String name) {
802802
Mockito.when(volumeDao.findByUuid(volUuid)).thenReturn(srcVolume);
803803
}
804804

805-
private void mockThinDiskOffering(Long diskOfferingId) {
805+
private void mockThinDiskOffering(String diskOfferingUuid, Long diskOfferingId) {
806806
DiskOfferingVO diskOffering = mock(DiskOfferingVO.class);
807807
Mockito.when(diskOffering.getId()).thenReturn(diskOfferingId);
808808
Mockito.when(diskOffering.getProvisioningType()).thenReturn(Storage.ProvisioningType.THIN);
809-
Mockito.when(diskOfferingDao.findByUuid(Mockito.anyString())).thenReturn(diskOffering);
809+
Mockito.when(diskOfferingDao.findByUuid(diskOfferingUuid)).thenReturn(diskOffering);
810810
}
811811

812812
private void mockStorPoolPoolByUuid(String dsUuid, Long poolId) {
@@ -877,7 +877,7 @@ public void restoreBackedUpVolumeUsesQcow2FormatAndRealPathForStorPool()
877877
String realStorPoolPath = "/dev/storpool-byid/t.t.t";
878878

879879
mockSourceVolume(volUuid, "data-sp");
880-
mockThinDiskOffering(6L);
880+
mockThinDiskOffering("disk-offering-uuid", 6L);
881881
mockStorPoolPoolByUuid(dsUuid, poolId);
882882
mockHostByIp(hostIp, 8L);
883883
mockNasRepository(backupOfferingId);

‎plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,10 @@ public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool, Phys
481481
throw new CloudRuntimeException("Encrypted StorPool volumes are not supported");
482482
}
483483

484+
if (!PhysicalDiskFormat.RAW.equals(format)) {
485+
throw new CloudRuntimeException(String.format("StorPool volumes can only be created as RAW, %s was requested", format));
486+
}
487+
484488
if (size <= 0) {
485489
throw new CloudRuntimeException("Size must be greater than 0 to create a StorPool volume");
486490
}

‎scripts/vm/hypervisor/kvm/nasbackup.sh‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,12 @@ backup_stopped_vm() {
951951
cleanup
952952
exit 1
953953
fi
954-
sp_clone_name=$(sp_volume_name_from_path "$read_disk")
954+
if ! sp_clone_name=$(sp_volume_name_from_path "$read_disk"); then
955+
log -ne "Failed to resolve the StorPool volume name of backup source volume $read_disk, it must be deleted manually"
956+
echo "Failed to resolve the StorPool volume name of backup source volume $read_disk"
957+
cleanup
958+
exit 1
959+
fi
955960
# Register the clone here, in the parent shell, right after the command substitution
956961
# above returns — sp_create_backup_source_disk cannot do this itself (see its comment).
957962
SP_CLEANUP_VOLUMES+=("$sp_clone_name")

‎test/integration/plugins/storpool/TestNasBackupStorPool.py‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ def _setup_common(cls):
8989
StorPoolHelper.logger = cls
9090

9191
zone_cfg = config.zones[0]
92-
assert zone_cfg is not None
92+
if zone_cfg is None:
93+
raise Exception("No zone configured in the Marvin config")
9394
cls.zone_cfg = zone_cfg
9495

9596
testClient = super(TestNasBackupStorPool, cls).getClsTestClient()
@@ -106,8 +107,10 @@ def _setup_common(cls):
106107

107108
cls.services = testClient.getParsedTestDataConfig()
108109
cls.domain = get_domain(cls.apiclient)
109-
cls.zone = list_zones(cls.apiclient, name=zone_cfg.name)[0]
110-
assert cls.zone is not None
110+
zones = list_zones(cls.apiclient, name=zone_cfg.name)
111+
if not zones:
112+
raise Exception("Zone %s not found" % zone_cfg.name)
113+
cls.zone = zones[0]
111114
cls.services["mode"] = cls.zone.networktype
112115

113116
cls.hypervisor = get_hypervisor_type(cls.apiclient)
@@ -127,7 +130,7 @@ def _setup_common(cls):
127130

128131
template = get_template(cls.apiclient, cls.zone.id, account="system")
129132
if template == FAILED:
130-
assert False, "get_template() failed to return a system template"
133+
raise Exception("get_template() failed to return a system template")
131134
cls.template = template
132135

133136
offerings = BackupOffering.listByZone(cls.apiclient, cls.zone.id) or []
@@ -202,7 +205,7 @@ def _setup_common(cls):
202205
@classmethod
203206
def _get_or_create_disk_offering(cls, tag, displaytext):
204207
disk_offerings = list_disk_offering(cls.apiclient, name=tag)
205-
if disk_offerings is None:
208+
if not disk_offerings:
206209
disk_offering = DiskOffering.create(
207210
cls.apiclient,
208211
{
@@ -237,7 +240,8 @@ def _create_test_vm(cls, name, diskofferingid):
237240
@classmethod
238241
def _verify_setup_volumes(cls, vm):
239242
volumes = Volume.list(cls.apiclient, virtualmachineid=vm.id, listall=True)
240-
assert isinstance(volumes, list) and len(volumes) >= 1
243+
if not isinstance(volumes, list) or not volumes:
244+
raise Exception("No volumes found for VM %s" % vm.id)
241245
for vol in volumes:
242246
if cls.nfs_storage_pool and vol.storageid == cls.nfs_storage_pool.id:
243247
continue
@@ -678,7 +682,7 @@ def _setup_nfs_environment(cls):
678682
@classmethod
679683
def _get_or_create_nfs_service_offering(cls):
680684
service_offerings = list_service_offering(cls.apiclient, name=cls.nfs_tag)
681-
if service_offerings is None:
685+
if not service_offerings:
682686
service_offering = ServiceOffering.create(
683687
cls.apiclient,
684688
{

‎test/integration/plugins/storpool/sp_util.py‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -710,16 +710,20 @@ def check_storpool_volume_size(cls, volume, spapi):
710710

711711
@classmethod
712712
def check_storpool_volume_iops(cls, spapi, volume,):
713-
spvolume = cls.get_storpool_volume_by_path(spapi, volume.path)
714-
logging.debug(spvolume.iops)
715-
logging.debug(volume.maxiops)
716-
if spvolume.iops != volume.maxiops:
717-
raise Exception("Storpool volume size is not the same as CloudStack db size")
713+
name = volume.path.split("/")[3]
714+
try:
715+
spvolume = spapi.volumeList(volumeName = "~" + name)
716+
logging.debug(spvolume[0].iops)
717+
logging.debug(volume.maxiops)
718+
if spvolume[0].iops != volume.maxiops:
719+
raise Exception("Storpool volume size is not the same as CloudStack db size")
720+
except spapi.ApiError as err:
721+
raise Exception(err)
718722

719723
@classmethod
720724
def verify_storpool_volume(cls, spapi, volume, check_size=True):
721725
"""Assert the CloudStack volume exists on StorPool; optionally compare size."""
722-
if not volume.path or not volume.path.startswith("/dev/storpool"):
726+
if not volume.path or not volume.path.startswith("/dev/storpool-byid/"):
723727
raise Exception("Volume %s does not have a StorPool device path: %s" %
724728
(volume.id, volume.path))
725729
spvolume = cls.get_storpool_volume_by_path(spapi, volume.path)

0 commit comments

Comments
 (0)