Skip to content

Commit 1028c63

Browse files
author
shan.wu
committed
<fix>[migration]: precheck qemu/libvirt/cpumodel/hostept for storage migration.
precheck qemu/libvirt/cpumodel/hostept for storage migration. Resolves/Related: ZSTAC-75332 Change-Id: I6170776d786a787777797078737a68737a636772
1 parent a763663 commit 1028c63

File tree

6 files changed

+38
-6
lines changed

6 files changed

+38
-6
lines changed

compute/src/main/java/org/zstack/compute/allocator/AttachedVolumePrimaryStorageAllocatorFlow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class AttachedVolumePrimaryStorageAllocatorFlow extends AbstractHostAlloc
3131
public void allocate() {
3232
throwExceptionIfIAmTheFirstFlow();
3333

34-
if (VmOperation.NewCreate.toString().equals(spec.getVmOperation())) {
34+
if (VmOperation.NewCreate.toString().equals(spec.getVmOperation()) || VmOperation.MigrateStorage.toString().equals(spec.getVmOperation())) {
3535
next(candidates);
3636
return;
3737
}

compute/src/main/java/org/zstack/compute/allocator/HostPrimaryStorageAllocatorFlow.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ private List<HostVO> filterHostHavingAccessiblePrimaryStorage(List<String> huuid
141141
private List<HostVO> allocateFromCandidates() {
142142
List<String> huuids = getHostUuidsFromCandidates();
143143
Set<String> requiredPsUuids = spec.getRequiredPrimaryStorageUuids();
144-
if (!VmOperation.NewCreate.toString().equals(spec.getVmOperation())) {
145-
return filterHostHavingAccessiblePrimaryStorage(huuids, spec);
146-
} else {
144+
if (VmOperation.NewCreate.toString().equals(spec.getVmOperation()) || VmOperation.MigrateStorage.toString().equals(spec.getVmOperation())) {
147145
huuids = filterHostHavingAccessiblePrimaryStorage(huuids, spec)
148146
.stream().map(ResourceVO::getUuid).collect(Collectors.toList());
147+
} else {
148+
return filterHostHavingAccessiblePrimaryStorage(huuids, spec);
149149
}
150150

151151
if (huuids.isEmpty()) {

header/src/main/java/org/zstack/header/vm/VmInstanceConstant.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ enum VmOperation {
5959
Reboot,
6060
Destroy,
6161
Migrate,
62+
MigrateStorage,
6263
AttachVolume,
6364
AttachNic,
6465
ChangeNicNetwork,

plugin/kvm/src/main/java/org/zstack/kvm/KVMHostAllocatorFilterExtensionPoint.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.zstack.header.allocator.HostAllocatorSpec;
66
import org.zstack.header.host.HostVO;
77
import org.zstack.header.vm.VmInstanceConstant;
8+
import org.zstack.header.vm.VmInstanceConstant.VmOperation;
89
import org.zstack.utils.Utils;
910
import org.zstack.utils.logging.CLogger;
1011

@@ -171,7 +172,7 @@ public List<HostVO> filterHostCandidates(List<HostVO> candidates, HostAllocatorS
171172
return candidates;
172173
}
173174

174-
if (!VmInstanceConstant.VmOperation.Migrate.toString().equals(spec.getVmOperation())) {
175+
if (!VmOperation.Migrate.toString().equals(spec.getVmOperation()) && !VmOperation.MigrateStorage.toString().equals(spec.getVmOperation())) {
175176
return candidates;
176177
}
177178

plugin/localstorage/src/main/java/org/zstack/storage/primary/local/LocalStorageAllocatorFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public boolean stop() {
107107
public List<HostVO> filterHostCandidates(List<HostVO> candidates, HostAllocatorSpec spec) {
108108
long reservedCapacity = SizeUtils.sizeStringToBytes(PrimaryStorageGlobalConfig.RESERVED_CAPACITY.value());
109109

110-
if (VmOperation.NewCreate.toString().equals(spec.getVmOperation())) {
110+
if (VmOperation.NewCreate.toString().equals(spec.getVmOperation()) || VmOperation.MigrateStorage.toString().equals(spec.getVmOperation())) {
111111
List<String> huuids = getNeedCheckHostLocalStorageList(candidates, spec);
112112
if (huuids.isEmpty()) {
113113
return candidates;

test/src/test/groovy/org/zstack/test/integration/kvm/host/MigrateVmCheckKvmPropertyCase.groovy

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class MigrateVmCheckKvmPropertyCase extends SubCase {
8383
}
8484

8585
attachPrimaryStorage("nfs")
86+
attachPrimaryStorage("nfs2")
8687
attachL2Network("l2")
8788
}
8889

@@ -103,6 +104,7 @@ class MigrateVmCheckKvmPropertyCase extends SubCase {
103104
}
104105

105106
attachPrimaryStorage("nfs")
107+
attachPrimaryStorage("nfs2")
106108
attachL2Network("l2")
107109
}
108110

@@ -111,6 +113,11 @@ class MigrateVmCheckKvmPropertyCase extends SubCase {
111113
url = "localhost:/nfs_ps"
112114
}
113115

116+
nfsPrimaryStorage {
117+
name = "nfs2"
118+
url = "127.0.0.6:/nfs_ps"
119+
}
120+
114121
l2NoVlanNetwork {
115122
name = "l2"
116123
physicalInterface = "eth0"
@@ -199,11 +206,34 @@ class MigrateVmCheckKvmPropertyCase extends SubCase {
199206
confirmMigrateAvailable(vm1)
200207
confirmMigrateAvailable(vm2)
201208

209+
primaryStorageMigrateVm {
210+
vmInstanceUuid = vm1.uuid
211+
dstPrimaryStorageUuid = env.inventoryByName("nfs2").uuid
212+
withSnapshots = false
213+
}
214+
215+
cleanUpTrashOnPrimaryStorage {
216+
uuid = env.inventoryByName("nfs").uuid
217+
}
218+
219+
primaryStorageMigrateVm {
220+
vmInstanceUuid = vm1.uuid
221+
dstPrimaryStorageUuid = env.inventoryByName("nfs").uuid
222+
withSnapshots = false
223+
}
224+
202225
// change qemu-img version to different value, both vms expected can not be migrated
203226
KVMSystemTags.QEMU_IMG_VERSION.updateTagByToken(host2.uuid, KVMSystemTags.QEMU_IMG_VERSION_TOKEN, mockWrongValue(qemuImgVersion))
204227
confirmMigrateUnavailable(vm1)
205228
confirmMigrateUnavailable(vm2)
206229

230+
expectError {
231+
primaryStorageMigrateVm {
232+
vmInstanceUuid = vm1.uuid
233+
dstPrimaryStorageUuid = env.inventoryByName("nfs2").uuid
234+
withSnapshots = false
235+
}
236+
}
207237
// change qemu-img version back confirm can migrate again
208238
KVMSystemTags.QEMU_IMG_VERSION.updateTagByToken(host2.uuid, KVMSystemTags.QEMU_IMG_VERSION_TOKEN, qemuImgVersion)
209239
confirmMigrateAvailable(vm1)

0 commit comments

Comments
 (0)