Skip to content

Commit ddf61e5

Browse files
author
gitlab
committed
Merge branch 'c-1' into 'zsv_4.10.28'
<test>[storage]: remove CreateVmInstance.dataDiskOfferingUuids usage See merge request zstackio/zstack!9092
2 parents fcc7f82 + 512ba72 commit ddf61e5

4 files changed

Lines changed: 160 additions & 97 deletions

File tree

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ public class LocalStorageMainAllocatorFlow extends NoRollbackFlow {
4343

4444
private class Result {
4545
List<PrimaryStorageVO> result;
46-
String errStr;
47-
List<ErrorCode> causes = new ArrayList<>();
46+
ErrorCode errorCode;
4847
}
4948

5049
@Transactional(readOnly = true)
@@ -77,7 +76,7 @@ private Result allocate(Map data) {
7776
query.setParameter("hstate", HostState.Enabled);
7877
query.setParameter("hstatus", HostStatus.Connected);
7978
query.setParameter("ptype", LocalStorageConstants.LOCAL_STORAGE_TYPE);
80-
ret.errStr = i18n("the required host[uuid:%s] cannot satisfy conditions[state: %s, status: %s, size > %s bytes]," +
79+
ret.errorCode = operr("the required host[uuid:%s] cannot satisfy conditions[state: %s, status: %s, size > %s bytes]," +
8180
" or doesn't belong to a local primary storage satisfying conditions[state: %s, status: %s]," +
8281
" or its cluster doesn't attach to any local primary storage",
8382
spec.getRequiredHostUuid(),
@@ -105,7 +104,7 @@ private Result allocate(Map data) {
105104
query.setParameter("hstate", HostState.Enabled);
106105
query.setParameter("hstatus", HostStatus.Connected);
107106
query.setParameter("ptype", LocalStorageConstants.LOCAL_STORAGE_TYPE);
108-
ret.errStr = i18n("no local primary storage in zone[uuid:%s] can satisfy conditions[state: %s, status: %s]" +
107+
ret.errorCode = operr("no local primary storage in zone[uuid:%s] can satisfy conditions[state: %s, status: %s]" +
109108
" or contain hosts satisfying conditions[state: %s, status: %s, size > %s bytes]",
110109
spec.getRequiredZoneUuid(),
111110
PrimaryStorageState.Enabled,
@@ -131,7 +130,7 @@ private Result allocate(Map data) {
131130
query.setParameter("hstatus", HostStatus.Connected);
132131
query.setParameter("ptype", LocalStorageConstants.LOCAL_STORAGE_TYPE);
133132

134-
ret.errStr = i18n("no local primary storage can satisfy conditions[state: %s, status: %s]" +
133+
ret.errorCode = operr("no local primary storage can satisfy conditions[state: %s, status: %s]" +
135134
" or contain hosts satisfying conditions[state: %s, status: %s, size > %s bytes]",
136135
PrimaryStorageState.Enabled,
137136
PrimaryStorageStatus.Connected,
@@ -173,13 +172,13 @@ private Result allocate(Map data) {
173172
LocalStorageHostRefVO ref = it.next();
174173
if (!physicalCapacityMgr.checkCapacityByRatio(ref.getPrimaryStorageUuid(), ref.getTotalPhysicalCapacity(), ref.getAvailablePhysicalCapacity())
175174
|| !physicalCapacityMgr.checkRequiredCapacityByRatio(ref.getPrimaryStorageUuid(), ref.getTotalPhysicalCapacity(), spec.getTotalSize())) {
176-
ret.causes.add(operr("{the physical capacity usage of the host[uuid:%s] has exceeded the threshold[%s]}",
175+
errs.add(operr("{the physical capacity usage of the host[uuid:%s] has exceeded the threshold[%s]}",
177176
ref.getHostUuid(), physicalCapacityMgr.getRatio(ref.getPrimaryStorageUuid())));
178177
it.remove();
179178
}
180179
}
181180
if (candidateHosts.isEmpty()) {
182-
ret.errStr = i18n("failed allocate localstorage");
181+
ret.errorCode = operr("failed allocate localstorage").withCause(errs);
183182
}
184183
}
185184
Set<String> candidates = new HashSet<>();
@@ -289,7 +288,7 @@ public void run(FlowTrigger trigger, Map data) {
289288
return;
290289
}
291290

292-
ErrorCode err = ret.causes.isEmpty() ? operr(ret.errStr) : multiErr(ret.causes, ret.errStr);
291+
ErrorCode err = ret.errorCode;
293292
trigger.fail(err);
294293
}
295294
}

test/src/test/groovy/org/zstack/test/integration/kvm/vm/CreateVmWithDesignatedPSCase.groovy

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package org.zstack.test.integration.kvm.vm
22

3-
import org.zstack.compute.vm.VmSystemTags
4-
import org.zstack.sdk.DiskOfferingInventory
3+
import org.zstack.core.Platform
4+
import org.zstack.sdk.HostInventory
55
import org.zstack.sdk.ImageInventory
6-
import org.zstack.sdk.InstanceOfferingInventory
76
import org.zstack.sdk.L3NetworkInventory
87
import org.zstack.sdk.PrimaryStorageInventory
98
import org.zstack.test.integration.kvm.KvmTest
109
import org.zstack.testlib.EnvSpec
1110
import org.zstack.testlib.SubCase
12-
import org.zstack.utils.data.SizeUnit
1311

1412

1513
class CreateVmWithDesignatedPSCase extends SubCase {
@@ -23,17 +21,6 @@ class CreateVmWithDesignatedPSCase extends SubCase {
2321
@Override
2422
void environment() {
2523
env = env {
26-
instanceOffering {
27-
name = "instanceOffering"
28-
memory = SizeUnit.GIGABYTE.toByte(8)
29-
cpu = 4
30-
}
31-
32-
diskOffering {
33-
name = "diskOffering"
34-
diskSize = SizeUnit.GIGABYTE.toByte(20)
35-
}
36-
3724
sftpBackupStorage {
3825
name = "sftp"
3926
url = "/sftp"
@@ -121,23 +108,55 @@ class CreateVmWithDesignatedPSCase extends SubCase {
121108
}
122109

123110
void TestCreateVmWithDesignatedPS() {
124-
PrimaryStorageInventory ps_1 = env.inventoryByName("local1")
125-
PrimaryStorageInventory ps_2 = env.inventoryByName("local2")
126-
InstanceOfferingInventory instanceOffering = env.inventoryByName("instanceOffering")
127-
DiskOfferingInventory diskOfferingInventory = env.inventoryByName("diskOffering")
128-
ImageInventory image = env.inventoryByName("image")
129-
L3NetworkInventory l3 = env.inventoryByName("l3")
130-
131-
expectError {
111+
def ps_1 = env.inventoryByName("local1") as PrimaryStorageInventory
112+
def ps_2 = env.inventoryByName("local2") as PrimaryStorageInventory
113+
def image = env.inventoryByName("image") as ImageInventory
114+
def l3 = env.inventoryByName("l3") as L3NetworkInventory
115+
116+
expectApiFailure({
132117
createVmInstance {
133118
name = "test_vm"
134-
instanceOfferingUuid = instanceOffering.uuid
119+
cpuNum = 4
120+
memorySize = gb(8)
135121
l3NetworkUuids = [l3.uuid]
136122
imageUuid = image.uuid
137-
primaryStorageUuidForRootVolume = ps_1.uuid
138-
dataDiskOfferingUuids = [diskOfferingInventory.uuid]
139-
systemTags = [VmSystemTags.PRIMARY_STORAGE_UUID_FOR_DATA_VOLUME.instantiateTag([(VmSystemTags.PRIMARY_STORAGE_UUID_FOR_DATA_VOLUME_TOKEN): ps_2.uuid])]
123+
diskAOs = [
124+
[
125+
"boot" : true,
126+
"primaryStorageUuid" : ps_1.uuid,
127+
],
128+
[
129+
"size" : gb(20),
130+
"primaryStorageUuid" : ps_2.uuid,
131+
]
132+
]
133+
}
134+
}) {
135+
// host1 -> ps_1
136+
// host2 -> ps_2
137+
assert delegate.code == "HOST_ALLOCATION.1001"
138+
assert delegate.opaque
139+
assert delegate.opaque["rejectedCandidates"] instanceof List
140+
def rejectedCandidates = (delegate.opaque["rejectedCandidates"] as List<Map<String, Object>>)
141+
assert rejectedCandidates.size() == 2
142+
143+
def kvm1 = env.inventoryByName("kvm1") as HostInventory
144+
def candidates1 = rejectedCandidates.findAll {
145+
return it["hostUuid"] == kvm1.uuid
146+
}
147+
assert candidates1.size() == 1
148+
assert candidates1[0]["hostName"] == "kvm1"
149+
assert candidates1[0]["reject"] == Platform.i18n("not accessible to the specific primary storage")
150+
assert candidates1[0]["rejectBy"] == "HostPrimaryStorageAllocatorFlow"
151+
152+
def kvm2 = env.inventoryByName("kvm2") as HostInventory
153+
def candidates2 = rejectedCandidates.findAll {
154+
return it["hostUuid"] == kvm2.uuid
140155
}
156+
assert candidates2.size() == 1
157+
assert candidates2[0]["hostName"] == "kvm2"
158+
assert candidates2[0]["reject"] == Platform.i18n("not accessible to the specific primary storage")
159+
assert candidates2[0]["rejectBy"] == "HostPrimaryStorageAllocatorFlow"
141160
}
142161
}
143162

test/src/test/groovy/org/zstack/test/integration/storage/primary/local/multips/CreateVmWithVolumeSpecifiedPsCase.groovy

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ package org.zstack.test.integration.storage.primary.local.multips
22

33
import org.zstack.core.db.Q
44
import org.zstack.header.image.ImageConstant
5-
import org.zstack.header.volume.Volume
65
import org.zstack.header.volume.VolumeVO
76
import org.zstack.header.volume.VolumeVO_
8-
import org.zstack.sdk.DiskOfferingInventory
97
import org.zstack.sdk.ImageInventory
108
import org.zstack.sdk.PrimaryStorageInventory
119
import org.zstack.sdk.VmInstanceInventory
@@ -30,17 +28,6 @@ class CreateVmWithVolumeSpecifiedPsCase extends SubCase {
3028
@Override
3129
void environment() {
3230
env = env {
33-
instanceOffering {
34-
name = "instanceOffering"
35-
memory = SizeUnit.GIGABYTE.toByte(1)
36-
cpu = 1
37-
}
38-
39-
diskOffering {
40-
name = "diskOffering"
41-
diskSize = SizeUnit.GIGABYTE.toByte(20)
42-
}
43-
4431
sftpBackupStorage {
4532
name = "sftp"
4633
url = "/sftp"
@@ -126,11 +113,14 @@ class CreateVmWithVolumeSpecifiedPsCase extends SubCase {
126113

127114
vm {
128115
name = "vm"
129-
useInstanceOffering("instanceOffering")
116+
cpu = 1
117+
memoryGB(1)
130118
useImage("image1")
131119
useL3Networks("pubL3")
132-
useRootDiskOffering("diskOffering")
133120
useHost("kvm")
121+
disk {
122+
sizeGB(20)
123+
}
134124
}
135125
}
136126
}
@@ -147,20 +137,26 @@ class CreateVmWithVolumeSpecifiedPsCase extends SubCase {
147137

148138
void testCreateVMPs1WithVolumePs1() {
149139
ImageInventory iso = env.inventoryByName("iso") as ImageInventory
150-
DiskOfferingInventory diskOffering = env.inventoryByName("diskOffering") as DiskOfferingInventory
151140
VmInstanceInventory vm = env.inventoryByName("vm") as VmInstanceInventory
152141
PrimaryStorageInventory local_ps1 = env.inventoryByName("local") as PrimaryStorageInventory
153-
PrimaryStorageInventory local_ps2 = env.inventoryByName("local2") as PrimaryStorageInventory
154142

155143
VmInstanceInventory newVm = createVmInstance {
156144
name = "new_vm"
157-
instanceOfferingUuid = vm.instanceOfferingUuid
158-
rootDiskOfferingUuid = diskOffering.uuid
159-
dataDiskOfferingUuids = [diskOffering.uuid]
145+
cpuNum = 1
146+
memorySize = gb(1)
160147
imageUuid = iso.uuid
161148
l3NetworkUuids = [vm.defaultL3NetworkUuid]
162-
primaryStorageUuidForRootVolume = local_ps1.uuid
163-
systemTags = ["primaryStorageUuidForDataVolume::${local_ps1.uuid}".toString()]
149+
diskAOs = [
150+
[
151+
"boot" : true,
152+
"size" : gb(20),
153+
"primaryStorageUuid" : local_ps1.uuid,
154+
],
155+
[
156+
"size" : gb(20),
157+
"primaryStorageUuid" : local_ps1.uuid,
158+
],
159+
]
164160
} as VmInstanceInventory
165161

166162
assert newVm.allVolumes.size() == 2
@@ -174,20 +170,27 @@ class CreateVmWithVolumeSpecifiedPsCase extends SubCase {
174170

175171
void testCreateVMPs1WithVolumePs2() {
176172
ImageInventory iso = env.inventoryByName("iso") as ImageInventory
177-
DiskOfferingInventory diskOffering = env.inventoryByName("diskOffering") as DiskOfferingInventory
178173
VmInstanceInventory vm = env.inventoryByName("vm") as VmInstanceInventory
179174
PrimaryStorageInventory local_ps1 = env.inventoryByName("local") as PrimaryStorageInventory
180175
PrimaryStorageInventory local_ps2 = env.inventoryByName("local2") as PrimaryStorageInventory
181176

182177
VmInstanceInventory newVm = createVmInstance {
183178
name = "new_vm"
184-
instanceOfferingUuid = vm.instanceOfferingUuid
185-
rootDiskOfferingUuid = diskOffering.uuid
186-
dataDiskOfferingUuids = [diskOffering.uuid]
179+
cpuNum = 1
180+
memorySize = gb(1)
187181
imageUuid = iso.uuid
188182
l3NetworkUuids = [vm.defaultL3NetworkUuid]
189-
primaryStorageUuidForRootVolume = local_ps1.uuid
190-
systemTags = ["primaryStorageUuidForDataVolume::${local_ps2.uuid}".toString()]
183+
diskAOs = [
184+
[
185+
"boot" : true,
186+
"size" : gb(20),
187+
"primaryStorageUuid" : local_ps1.uuid,
188+
],
189+
[
190+
"size" : gb(20),
191+
"primaryStorageUuid" : local_ps2.uuid,
192+
],
193+
]
191194
} as VmInstanceInventory
192195

193196
retryInSecs {
@@ -200,20 +203,26 @@ class CreateVmWithVolumeSpecifiedPsCase extends SubCase {
200203

201204
void testCreateVMPs2WithVolumePs2() {
202205
ImageInventory iso = env.inventoryByName("iso") as ImageInventory
203-
DiskOfferingInventory diskOffering = env.inventoryByName("diskOffering") as DiskOfferingInventory
204206
VmInstanceInventory vm = env.inventoryByName("vm") as VmInstanceInventory
205-
PrimaryStorageInventory local_ps1 = env.inventoryByName("local") as PrimaryStorageInventory
206207
PrimaryStorageInventory local_ps2 = env.inventoryByName("local2") as PrimaryStorageInventory
207208

208209
VmInstanceInventory newVm = createVmInstance {
209210
name = "new_vm"
210-
instanceOfferingUuid = vm.instanceOfferingUuid
211-
rootDiskOfferingUuid = diskOffering.uuid
212-
dataDiskOfferingUuids = [diskOffering.uuid]
211+
cpuNum = 1
212+
memorySize = gb(1)
213213
imageUuid = iso.uuid
214214
l3NetworkUuids = [vm.defaultL3NetworkUuid]
215-
primaryStorageUuidForRootVolume = local_ps2.uuid
216-
systemTags = ["primaryStorageUuidForDataVolume::${local_ps2.uuid}".toString()]
215+
diskAOs = [
216+
[
217+
"boot" : true,
218+
"size" : gb(20),
219+
"primaryStorageUuid" : local_ps2.uuid,
220+
],
221+
[
222+
"size" : gb(20),
223+
"primaryStorageUuid" : local_ps2.uuid,
224+
],
225+
]
217226
} as VmInstanceInventory
218227

219228
retryInSecs {
@@ -226,20 +235,27 @@ class CreateVmWithVolumeSpecifiedPsCase extends SubCase {
226235

227236
void testCreateVMPs2WithVolumePs1() {
228237
ImageInventory iso = env.inventoryByName("iso") as ImageInventory
229-
DiskOfferingInventory diskOffering = env.inventoryByName("diskOffering") as DiskOfferingInventory
230238
VmInstanceInventory vm = env.inventoryByName("vm") as VmInstanceInventory
231239
PrimaryStorageInventory local_ps1 = env.inventoryByName("local") as PrimaryStorageInventory
232240
PrimaryStorageInventory local_ps2 = env.inventoryByName("local2") as PrimaryStorageInventory
233241

234242
VmInstanceInventory newVm = createVmInstance {
235243
name = "new_vm"
236-
instanceOfferingUuid = vm.instanceOfferingUuid
237-
rootDiskOfferingUuid = diskOffering.uuid
238-
dataDiskOfferingUuids = [diskOffering.uuid]
244+
cpuNum = 1
245+
memorySize = gb(1)
239246
imageUuid = iso.uuid
240247
l3NetworkUuids = [vm.defaultL3NetworkUuid]
241-
primaryStorageUuidForRootVolume = local_ps2.uuid
242-
systemTags = ["primaryStorageUuidForDataVolume::${local_ps1.uuid}".toString()]
248+
diskAOs = [
249+
[
250+
"boot" : true,
251+
"size" : gb(20),
252+
"primaryStorageUuid" : local_ps2.uuid,
253+
],
254+
[
255+
"size" : gb(20),
256+
"primaryStorageUuid" : local_ps1.uuid,
257+
],
258+
]
243259
} as VmInstanceInventory
244260

245261
retryInSecs {

0 commit comments

Comments
 (0)