Skip to content

Commit d23f174

Browse files
rg9975Glover, Rene (rg9975)
andauthored
4.22 FC VOL LIVEMIGRATE (#1)
* initial updates for fiberchannel livemigrate * fix storagemotion test case issue * fix VMSnapshotStrategyKVMTest * fix checkstyle and compile error --------- Co-authored-by: Glover, Rene (rg9975) <rg9975@att.com>
1 parent 71f47d6 commit d23f174

File tree

5 files changed

+292
-4
lines changed

5 files changed

+292
-4
lines changed

engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,7 +2566,10 @@ protected void verifyLiveMigrationForKVM(Map<VolumeInfo, DataStore> volumeDataSt
25662566
}
25672567

25682568
boolean isSrcAndDestPoolPowerFlexStorage = srcStoragePoolVO.getPoolType().equals(Storage.StoragePoolType.PowerFlex) && destStoragePoolVO.getPoolType().equals(Storage.StoragePoolType.PowerFlex);
2569-
if (srcStoragePoolVO.isManaged() && !isSrcAndDestPoolPowerFlexStorage && srcStoragePoolVO.getId() != destStoragePoolVO.getId()) {
2569+
boolean isSrcAndDestPoolFiberChannelStorage = srcStoragePoolVO.getPoolType().equals(Storage.StoragePoolType.FiberChannel) && destStoragePoolVO.getPoolType().equals(Storage.StoragePoolType.FiberChannel);
2570+
boolean fiberChannelVmOnline = isSrcAndDestPoolFiberChannelStorage && volumeInfo.getAttachedVM() != null && volumeInfo.getAttachedVM().getState() == VirtualMachine.State.Running;
2571+
2572+
if (srcStoragePoolVO.isManaged() && !isSrcAndDestPoolPowerFlexStorage && !fiberChannelVmOnline && srcStoragePoolVO.getId() != destStoragePoolVO.getId()) {
25702573
throw new CloudRuntimeException("Migrating a volume online with KVM from managed storage is not currently supported.");
25712574
}
25722575

@@ -2766,6 +2769,27 @@ private Map<String, String> getVolumeDetails(VolumeInfo volumeInfo) {
27662769
return volumeDetails;
27672770
}
27682771

2772+
private boolean shouldAttemptLiveFiberChannelMigration(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo) {
2773+
if (srcVolumeInfo == null || destVolumeInfo == null) {
2774+
return false;
2775+
}
2776+
2777+
StoragePoolVO srcPool = _storagePoolDao.findById(srcVolumeInfo.getPoolId());
2778+
StoragePoolVO destPool = _storagePoolDao.findById(destVolumeInfo.getPoolId());
2779+
2780+
if (srcPool == null || destPool == null) {
2781+
return false;
2782+
}
2783+
2784+
if (srcPool.getPoolType() != StoragePoolType.FiberChannel || destPool.getPoolType() != StoragePoolType.FiberChannel) {
2785+
return false;
2786+
}
2787+
2788+
VirtualMachine attachedVm = srcVolumeInfo.getAttachedVM();
2789+
2790+
return attachedVm != null && attachedVm.getState() == VirtualMachine.State.Running;
2791+
}
2792+
27692793
private Map<String, String> getSnapshotDetails(SnapshotInfo snapshotInfo) {
27702794
Map<String, String> snapshotDetails = new HashMap<>();
27712795

@@ -3021,8 +3045,11 @@ private String migrateVolumeForKVM(VolumeInfo srcVolumeInfo, VolumeInfo destVolu
30213045

30223046
_volumeService.grantAccess(srcVolumeInfo, hostVO, srcVolumeInfo.getDataStore());
30233047

3048+
boolean fiberChannelOnline = shouldAttemptLiveFiberChannelMigration(srcVolumeInfo, destVolumeInfo);
3049+
int waitTimeout = fiberChannelOnline ? StorageManager.KvmStorageOnlineMigrationWait.value() : StorageManager.KvmStorageOfflineMigrationWait.value();
3050+
30243051
MigrateVolumeCommand migrateVolumeCommand = new MigrateVolumeCommand(srcVolumeInfo.getTO(), destVolumeInfo.getTO(),
3025-
srcDetails, destDetails, StorageManager.KvmStorageOfflineMigrationWait.value());
3052+
srcDetails, destDetails, waitTimeout);
30263053

30273054
_volumeService.grantAccess(srcVolumeInfo, hostVO, srcVolumeInfo.getDataStore());
30283055
handleQualityOfServiceForVolumeMigration(destVolumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.MIGRATION);

engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageSystemDataMotionTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ public class KvmNonManagedStorageSystemDataMotionTest {
124124
Host host1;
125125
@Mock
126126
Host host2;
127+
@Mock
128+
com.cloud.vm.VirtualMachine attachedVm;
127129

128130
Map<VolumeInfo, DataStore> migrationMap;
129131

@@ -478,6 +480,23 @@ public void testVerifyLiveMigrationMapForKVM() {
478480
kvmNonManagedStorageDataMotionStrategy.verifyLiveMigrationForKVM(migrationMap);
479481
}
480482

483+
@Test
484+
public void testVerifyLiveMigrationMapForKVMManagedFiberChannelAllowed() {
485+
lenient().when(pool1.isManaged()).thenReturn(true);
486+
lenient().when(pool2.isManaged()).thenReturn(true);
487+
lenient().when(pool1.getPoolType()).thenReturn(Storage.StoragePoolType.FiberChannel);
488+
lenient().when(pool2.getPoolType()).thenReturn(Storage.StoragePoolType.FiberChannel);
489+
lenient().when(pool1.getId()).thenReturn(POOL_1_ID);
490+
lenient().when(pool2.getId()).thenReturn(POOL_2_ID);
491+
lenient().when(volumeInfo1.getAttachedVM()).thenReturn(attachedVm);
492+
when(attachedVm.getState()).thenReturn(com.cloud.vm.VirtualMachine.State.Running);
493+
494+
Map<VolumeInfo, DataStore> fiberChannelMigrationMap = new HashMap<>();
495+
fiberChannelMigrationMap.put(volumeInfo1, dataStore2);
496+
497+
kvmNonManagedStorageDataMotionStrategy.verifyLiveMigrationForKVM(fiberChannelMigrationMap);
498+
}
499+
481500
@Test(expected = CloudRuntimeException.class)
482501
public void testVerifyLiveMigrationMapForKVMNotExistingSource() {
483502
when(primaryDataStoreDao.findById(POOL_1_ID)).thenReturn(null);

engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyKVMTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import org.springframework.test.context.ContextConfiguration;
6161
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
6262
import org.springframework.test.context.support.AnnotationConfigContextLoader;
63+
import org.springframework.test.util.ReflectionTestUtils;
6364

6465
import com.cloud.agent.AgentManager;
6566
import com.cloud.agent.api.DeleteVMSnapshotAnswer;
@@ -94,6 +95,10 @@
9495
import com.cloud.vm.snapshot.VMSnapshotVO;
9596
import com.cloud.vm.snapshot.dao.VMSnapshotDao;
9697
import com.cloud.vm.snapshot.dao.VMSnapshotDetailsDao;
98+
import com.cloud.event.dao.UsageEventDao;
99+
import com.cloud.event.UsageEventUtils;
100+
import com.cloud.user.dao.AccountDao;
101+
import com.cloud.dc.dao.DataCenterDao;
97102

98103
import junit.framework.TestCase;
99104

@@ -144,10 +149,33 @@ public class VMSnapshotStrategyKVMTest extends TestCase{
144149
@Inject
145150
VMSnapshotDetailsDao vmSnapshotDetailsDao;
146151

152+
private UsageEventDao usageEventDao;
153+
private AccountDao accountDao;
154+
private DataCenterDao dataCenterDao;
155+
147156
@Override
148157
@Before
149158
public void setUp() throws Exception {
150159
ComponentContext.initComponentsLifeCycle();
160+
initialiseUsageEventUtils();
161+
}
162+
163+
private void initialiseUsageEventUtils() {
164+
usageEventDao = Mockito.mock(UsageEventDao.class);
165+
accountDao = Mockito.mock(AccountDao.class);
166+
dataCenterDao = Mockito.mock(DataCenterDao.class);
167+
ConfigurationDao configDao = Mockito.mock(ConfigurationDao.class);
168+
169+
UsageEventUtils usageEventUtils = new UsageEventUtils();
170+
ReflectionTestUtils.setField(usageEventUtils, "usageEventDao", usageEventDao);
171+
ReflectionTestUtils.setField(usageEventUtils, "accountDao", accountDao);
172+
ReflectionTestUtils.setField(usageEventUtils, "dcDao", dataCenterDao);
173+
ReflectionTestUtils.setField(usageEventUtils, "configDao", configDao);
174+
ReflectionTestUtils.invokeMethod(usageEventUtils, "init");
175+
176+
Mockito.lenient().when(usageEventDao.persist(Mockito.any())).thenAnswer(invocation -> invocation.getArgument(0));
177+
Mockito.lenient().doNothing().when(usageEventDao).saveDetails(Mockito.anyLong(), Mockito.anyMap());
178+
Mockito.lenient().when(configDao.getValue("publish.usage.events")).thenReturn("false");
151179
}
152180

153181
@Test

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,10 @@ public void setSerial(String serial) {
11321132
this._serial = serial;
11331133
}
11341134

1135+
public String getSerial() {
1136+
return _serial;
1137+
}
1138+
11351139
public void setLibvirtDiskEncryptDetails(LibvirtDiskEncryptDetails details)
11361140
{
11371141
this.encryptDetails = details;

0 commit comments

Comments
 (0)