Skip to content

Commit cfb4d43

Browse files
Merge remote-tracking branch 'origin/4.19'
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2 parents 4de2f38 + a1f547a commit cfb4d43

File tree

6 files changed

+106
-33
lines changed

6 files changed

+106
-33
lines changed

plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java

+20-11
Original file line numberDiff line numberDiff line change
@@ -276,27 +276,35 @@ public boolean connectPhysicalDisk(String volumePath, KVMStoragePool pool, Map<S
276276
}
277277

278278
final DevelopersApi api = getLinstorAPI(pool);
279+
String rscName;
279280
try
280281
{
281-
final String rscName = getLinstorRscName(volumePath);
282+
rscName = getLinstorRscName(volumePath);
282283

283284
ResourceMakeAvailable rma = new ResourceMakeAvailable();
284285
ApiCallRcList answers = api.resourceMakeAvailableOnNode(rscName, localNodeName, rma);
285286
checkLinstorAnswersThrow(answers);
286287

288+
} catch (ApiException apiEx) {
289+
s_logger.error(apiEx);
290+
throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
291+
}
292+
293+
try
294+
{
287295
// allow 2 primaries for live migration, should be removed by disconnect on the other end
288296
ResourceDefinitionModify rdm = new ResourceDefinitionModify();
289297
Properties props = new Properties();
290298
props.put("DrbdOptions/Net/allow-two-primaries", "yes");
291299
rdm.setOverrideProps(props);
292-
answers = api.resourceDefinitionModify(rscName, rdm);
300+
ApiCallRcList answers = api.resourceDefinitionModify(rscName, rdm);
293301
if (answers.hasError()) {
294302
logger.error("Unable to set 'allow-two-primaries' on " + rscName);
295-
throw new CloudRuntimeException(answers.get(0).getMessage());
303+
// do not fail here as adding allow-two-primaries property is only a problem while live migrating
296304
}
297305
} catch (ApiException apiEx) {
298306
logger.error(apiEx);
299-
throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
307+
// do not fail here as adding allow-two-primaries property is only a problem while live migrating
300308
}
301309
return true;
302310
}
@@ -358,21 +366,22 @@ public boolean disconnectPhysicalDiskByPath(String localPath)
358366
ResourceDefinitionModify rdm = new ResourceDefinitionModify();
359367
rdm.deleteProps(Collections.singletonList("DrbdOptions/Net/allow-two-primaries"));
360368
ApiCallRcList answers = api.resourceDefinitionModify(rsc.get().getName(), rdm);
361-
if (answers.hasError())
362-
{
363-
logger.error("Failed to remove 'allow-two-primaries' on " + rsc.get().getName());
364-
throw new CloudRuntimeException(answers.get(0).getMessage());
369+
if (answers.hasError()) {
370+
logger.error(
371+
String.format("Failed to remove 'allow-two-primaries' on %s: %s",
372+
rsc.get().getName(), LinstorUtil.getBestErrorMessage(answers)));
373+
// do not fail here as removing allow-two-primaries property isn't fatal
365374
}
366375

367376
return true;
368377
}
369378
logger.warn("Linstor: Couldn't find resource for this path: " + localPath);
370379
} catch (ApiException apiEx) {
371-
logger.error(apiEx);
372-
throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
380+
logger.error(apiEx.getBestMessage());
381+
// do not fail here as removing allow-two-primaries property isn't fatal
373382
}
374383
}
375-
return false;
384+
return true;
376385
}
377386

378387
@Override

plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/driver/StorPoolPrimaryDataStoreDriver.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ public boolean grantAccess(DataObject data, Host host, DataStore dataStore) {
191191

192192
@Override
193193
public void revokeAccess(DataObject data, Host host, DataStore dataStore) {
194+
if (DataObjectType.VOLUME == data.getType()) {
195+
final VolumeVO volume = volumeDao.findById(data.getId());
196+
if (volume.getInstanceId() == null) {
197+
StorPoolUtil.spLog("Removing tags from detached volume=%s", volume.toString());
198+
SpConnectionDesc conn = StorPoolUtil.getSpConnection(dataStore.getUuid(), dataStore.getId(), storagePoolDetailsDao, primaryStoreDao);
199+
StorPoolUtil.volumeRemoveTags(StorPoolStorageAdaptor.getVolumeNameFromPath(volume.getPath(), true), conn);
200+
}
201+
}
202+
194203
}
195204

196205
private void updateStoragePool(final long poolId, final long deltaUsedBytes) {
@@ -1039,7 +1048,7 @@ public void revertSnapshot(final SnapshotInfo snapshot, final SnapshotInfo snaps
10391048
}
10401049

10411050
if (vinfo.getMaxIops() != null) {
1042-
response = StorPoolUtil.volumeUpdateTags(volumeName, null, vinfo.getMaxIops(), conn, null);
1051+
response = StorPoolUtil.volumeUpdateIopsAndTags(volumeName, null, vinfo.getMaxIops(), conn, null);
10431052
if (response.getError() != null) {
10441053
StorPoolUtil.spLog("Volume was reverted successfully but max iops could not be set due to %s", response.getError().getDescr());
10451054
}
@@ -1128,13 +1137,16 @@ public boolean isVmInfoNeeded() {
11281137
@Override
11291138
public void provideVmInfo(long vmId, long volumeId) {
11301139
VolumeVO volume = volumeDao.findById(volumeId);
1140+
if (volume.getInstanceId() == null) {
1141+
return;
1142+
}
11311143
StoragePoolVO poolVO = primaryStoreDao.findById(volume.getPoolId());
11321144
if (poolVO != null) {
11331145
try {
11341146
SpConnectionDesc conn = StorPoolUtil.getSpConnection(poolVO.getUuid(), poolVO.getId(), storagePoolDetailsDao, primaryStoreDao);
11351147
String volName = StorPoolStorageAdaptor.getVolumeNameFromPath(volume.getPath(), true);
11361148
VMInstanceVO userVM = vmInstanceDao.findById(vmId);
1137-
SpApiResponse resp = StorPoolUtil.volumeUpdateTags(volName, volume.getInstanceId() != null ? userVM.getUuid() : "", null, conn, getVcPolicyTag(vmId));
1149+
SpApiResponse resp = StorPoolUtil.volumeUpdateIopsAndTags(volName, volume.getInstanceId() != null ? userVM.getUuid() : "", null, conn, getVcPolicyTag(vmId));
11381150
if (resp.getError() != null) {
11391151
logger.warn(String.format("Could not update VC policy tags of a volume with id [%s]", volume.getUuid()));
11401152
}

plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/util/StorPoolUtil.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,14 @@ public static SpApiResponse volumeUpdate(final String name, final Long newSize,
534534
return POST("MultiCluster/VolumeUpdate/" + name, json, conn);
535535
}
536536

537-
public static SpApiResponse volumeUpdateTags(final String name, final String uuid, Long iops,
537+
public static SpApiResponse volumeRemoveTags(String name, SpConnectionDesc conn) {
538+
Map<String, Object> json = new HashMap<>();
539+
Map<String, String> tags = StorPoolHelper.addStorPoolTags(null, "", null, "");
540+
json.put("tags", tags);
541+
return POST("MultiCluster/VolumeUpdate/" + name, json, conn);
542+
}
543+
544+
public static SpApiResponse volumeUpdateIopsAndTags(final String name, final String uuid, Long iops,
538545
SpConnectionDesc conn, String vcPolicy) {
539546
Map<String, Object> json = new HashMap<>();
540547
Map<String, String> tags = StorPoolHelper.addStorPoolTags(null, uuid, null, vcPolicy);

plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/snapshot/StorPoolVMSnapshotStrategy.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public boolean revertVMSnapshot(VMSnapshot vmSnapshot) {
333333
}
334334
VolumeInfo vinfo = volFactory.getVolume(volumeObjectTO.getId());
335335
if (vinfo.getMaxIops() != null) {
336-
resp = StorPoolUtil.volumeUpdateTags(volumeName, null, vinfo.getMaxIops(), conn, null);
336+
resp = StorPoolUtil.volumeUpdateIopsAndTags(volumeName, null, vinfo.getMaxIops(), conn, null);
337337

338338
if (resp.getError() != null) {
339339
StorPoolUtil.spLog("Volume was reverted successfully but max iops could not be set due to %s",

test/integration/plugins/storpool/TestTagsOnStorPool.py

+59-16
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,19 @@ def setUpCloudStack(cls):
218218
hypervisor=cls.hypervisor,
219219
rootdisksize=10
220220
)
221+
cls.virtual_machine3 = VirtualMachine.create(
222+
cls.apiclient,
223+
{"name":"StorPool-%s" % uuid.uuid4() },
224+
zoneid=cls.zone.id,
225+
templateid=template.id,
226+
accountid=cls.account.name,
227+
domainid=cls.account.domainid,
228+
serviceofferingid=cls.service_offering.id,
229+
hypervisor=cls.hypervisor,
230+
diskofferingid=cls.disk_offerings.id,
231+
size=2,
232+
rootdisksize=10
233+
)
221234
cls.template = template
222235
cls.random_data_0 = random_gen(size=100)
223236
cls.test_dir = "/tmp"
@@ -270,7 +283,7 @@ def test_01_set_vcpolicy_tag_to_vm_with_attached_disks(self):
270283
virtualmachineid = self.virtual_machine.id, listall=True
271284
)
272285

273-
self.vc_policy_tags(volumes, vm_tags, vm)
286+
self.vc_policy_tags(volumes, vm_tags, vm, True)
274287

275288

276289
@attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true")
@@ -310,7 +323,7 @@ def test_03_create_vm_snapshot_vc_policy_tag(self):
310323
vm = list_virtual_machines(self.apiclient,id = self.virtual_machine.id, listall=True)
311324
vm_tags = vm[0].tags
312325

313-
self.vc_policy_tags(volumes, vm_tags, vm)
326+
self.vc_policy_tags(volumes, vm_tags, vm, True)
314327

315328

316329
self.assertEqual(volume_attached.id, self.volume.id, "Is not the same volume ")
@@ -442,7 +455,7 @@ def test_04_revert_vm_snapshots_vc_policy_tag(self):
442455
vm = list_virtual_machines(self.apiclient,id = self.virtual_machine.id, listall=True)
443456
vm_tags = vm[0].tags
444457

445-
self.vc_policy_tags(volumes, vm_tags, vm)
458+
self.vc_policy_tags(volumes, vm_tags, vm, True)
446459

447460
self.assertEqual(
448461
self.random_data_0,
@@ -490,18 +503,17 @@ def test_05_delete_vm_snapshots(self):
490503
def test_06_remove_vcpolicy_tag_when_disk_detached(self):
491504
""" Test remove vc-policy tag to disk detached from VM"""
492505
time.sleep(60)
493-
volume_detached = self.virtual_machine.detach_volume(
494-
self.apiclient,
495-
self.volume_2
496-
)
497506
vm = list_virtual_machines(self.apiclient,id = self.virtual_machine.id, listall=True)
498507
vm_tags = vm[0].tags
499508
volumes = list_volumes(
500509
self.apiclient,
501-
virtualmachineid = self.virtual_machine.id, listall=True
510+
id= self.volume_2.id, listall=True,
502511
)
503-
504-
self.vc_policy_tags( volumes, vm_tags, vm)
512+
volume_detached = self.virtual_machine.detach_volume(
513+
self.apiclient,
514+
self.volume_2
515+
)
516+
self.vc_policy_tags( volumes, vm_tags, vm, False)
505517

506518
@attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true")
507519
def test_07_delete_vcpolicy_tag(self):
@@ -538,7 +550,7 @@ def test_08_vcpolicy_tag_to_reverted_disk(self):
538550
virtualmachineid = self.virtual_machine2.id, listall=True,
539551
type = "ROOT"
540552
)
541-
self.vc_policy_tags(volume, vm_tags, vm)
553+
self.vc_policy_tags(volume, vm_tags, vm, True)
542554

543555
snapshot = Snapshot.create(
544556
self.apiclient,
@@ -560,21 +572,52 @@ def test_08_vcpolicy_tag_to_reverted_disk(self):
560572
vm_tags = vm[0].tags
561573

562574
vol = list_volumes(self.apiclient, id = snapshot.volumeid, listall=True)
563-
self.vc_policy_tags(vol, vm_tags, vm)
575+
self.vc_policy_tags(vol, vm_tags, vm, True)
576+
577+
@attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true")
578+
def test_09_remove_vm_tags_on_datadisks_attached_to_destroyed_vm(self):
579+
tag = Tag.create(
580+
self.apiclient,
581+
resourceIds=self.virtual_machine3.id,
582+
resourceType='UserVm',
583+
tags={'vc-policy': 'testing_vc-policy'}
584+
)
585+
vm = list_virtual_machines(self.apiclient,id = self.virtual_machine3.id, listall=True)
586+
vm_tags = vm[0].tags
587+
volumes = list_volumes(
588+
self.apiclient,
589+
virtualmachineid = self.virtual_machine3.id, listall=True
590+
)
564591

592+
self.vc_policy_tags(volumes, vm_tags, vm, True)
565593

566-
def vc_policy_tags(self, volumes, vm_tags, vm):
567-
flag = False
594+
volumes = list_volumes(
595+
self.apiclient,
596+
virtualmachineid = self.virtual_machine3.id, listall=True, type="DATADISK"
597+
)
598+
self.virtual_machine3.delete(self.apiclient, expunge=True)
599+
600+
self.vc_policy_tags(volumes, vm_tags, vm, False)
601+
602+
def vc_policy_tags(self, volumes, vm_tags, vm, should_tags_exists=None):
603+
vcPolicyTag = False
604+
cvmTag = False
568605
for v in volumes:
569606
name = v.path.split("/")[3]
570607
spvolume = self.spapi.volumeList(volumeName="~" + name)
571608
tags = spvolume[0].tags
572609
for t in tags:
573610
for vm_tag in vm_tags:
574611
if t == vm_tag.key:
575-
flag = True
612+
vcPolicyTag = True
576613
self.assertEqual(tags[t], vm_tag.value, "Tags are not equal")
577614
if t == 'cvm':
615+
cvmTag = True
578616
self.assertEqual(tags[t], vm[0].id, "CVM tag is not the same as vm UUID")
579617
#self.assertEqual(tag.tags., second, msg)
580-
self.assertTrue(flag, "There aren't volumes with vm tags")
618+
if should_tags_exists:
619+
self.assertTrue(vcPolicyTag, "There aren't volumes with vm tags")
620+
self.assertTrue(cvmTag, "There aren't volumes with vm tags")
621+
else:
622+
self.assertFalse(vcPolicyTag, "The tags should be removed")
623+
self.assertFalse(cvmTag, "The tags should be removed")

tools/marvin/marvin/lib/base.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ def create(cls, apiclient, services, templateid=None, accountid=None,
527527
customcpuspeed=None, custommemory=None, rootdisksize=None,
528528
rootdiskcontroller=None, vpcid=None, macaddress=None, datadisktemplate_diskoffering_list={},
529529
properties=None, nicnetworklist=None, bootmode=None, boottype=None, dynamicscalingenabled=None,
530-
userdataid=None, userdatadetails=None, extraconfig=None):
530+
userdataid=None, userdatadetails=None, extraconfig=None, size=None):
531531
"""Create the instance"""
532532

533533
cmd = deployVirtualMachine.deployVirtualMachineCmd()
@@ -649,7 +649,9 @@ def create(cls, apiclient, services, templateid=None, accountid=None,
649649
if rootdiskcontroller:
650650
cmd.details[0]["rootDiskController"] = rootdiskcontroller
651651

652-
if "size" in services:
652+
if size:
653+
cmd.size = size
654+
elif "size" in services:
653655
cmd.size = services["size"]
654656

655657
if group:

0 commit comments

Comments
 (0)