@@ -13,6 +13,7 @@ import org.zstack.header.allocator.HostCapacityVO
13
13
import org.zstack.header.allocator.HostCapacityVO_
14
14
import org.zstack.header.host.HostVO
15
15
import org.zstack.header.host.HostVO_
16
+ import org.zstack.header.longjob.LongJobConstants
16
17
import org.zstack.header.longjob.LongJobVO
17
18
import org.zstack.header.longjob.LongJobVO_
18
19
import org.zstack.header.network.service.NetworkServiceType
@@ -28,7 +29,6 @@ import org.zstack.test.integration.ZStackTest
28
29
import org.zstack.testlib.EnvSpec
29
30
import org.zstack.testlib.SubCase
30
31
import org.zstack.utils.data.SizeUnit
31
- import org.zstack.utils.gson.JSONObjectUtil
32
32
33
33
/**
34
34
* Created by camile on 18-3-7.
@@ -190,6 +190,7 @@ class LiveMigrateVmJobCase extends SubCase {
190
190
testLiveMigrateVmLongJobCancel()
191
191
testLiveMigrateVmLongJobCancelFail()
192
192
testLiveMigrateVmLongJobCancelBeforeMigrate()
193
+ testLiveMigrateVmNoJobToCancel()
193
194
}
194
195
}
195
196
@@ -294,6 +295,68 @@ class LiveMigrateVmJobCase extends SubCase {
294
295
assert canceled
295
296
}
296
297
298
+ void testLiveMigrateVmNoJobToCancel () {
299
+ env. cleanSimulatorHandlers()
300
+
301
+ APIMigrateVmMsg msg = new APIMigrateVmMsg ()
302
+ msg. hostUuid = host2. uuid
303
+ msg. vmInstanceUuid = vm1. uuid
304
+ def canceled = false
305
+ def migrating = false
306
+
307
+ env. simulator(KVMConstant . KVM_MIGRATE_VM_PATH ) { HttpEntity<String > e ->
308
+ migrating = true
309
+ while (! canceled) {
310
+ sleep(500 )
311
+ }
312
+ return new KVMAgentCommands.MigrateVmResponse ()
313
+ }
314
+ KVMAgentCommands.CancelCmd cmd = null
315
+ env. simulator(AgentConstant . CANCEL_JOB ) { HttpEntity<String > e ->
316
+ cmd = json(e. body, KVMAgentCommands.CancelCmd . class)
317
+ canceled = true
318
+ def rsp = new KVMAgentCommands.CancelRsp ()
319
+ rsp. setError(LongJobConstants . NO_JOB_TO_CANCEL )
320
+ return rsp
321
+ }
322
+
323
+ LongJobInventory jobInv = submitLongJob {
324
+ jobName = msg. getClass(). getSimpleName()
325
+ jobData = gson. toJson(msg)
326
+ } as LongJobInventory
327
+
328
+ assert jobInv. jobName == msg. getClass(). getSimpleName()
329
+ assert jobInv. state == LongJobState.Running
330
+
331
+ while (! migrating) {
332
+ sleep(500 )
333
+ }
334
+ expectError {
335
+ cancelLongJob {
336
+ uuid = jobInv. uuid
337
+ }
338
+ }
339
+
340
+ retryInSecs() {
341
+ LongJobVO job = dbFindByUuid(jobInv. getUuid(), LongJobVO . class)
342
+ assert job. state. toString() == LongJobState.Succeeded . toString()
343
+ }
344
+ assert host2. uuid == dbf. findByUuid(vm1. uuid, VmInstanceVO . class). hostUuid
345
+ assert canceled
346
+ assert cmd. getInterval() == 1
347
+ assert cmd. getTimes() == 3
348
+
349
+ SQL . New (LongJobVO . class). eq(LongJobVO_ . uuid, jobInv. getUuid()). set(LongJobVO_ . state, org.zstack.header.longjob.LongJobState.Canceled ). update();
350
+
351
+ cancelLongJob {
352
+ uuid = jobInv. uuid
353
+ }
354
+
355
+ SQL . New (LongJobVO . class). eq(LongJobVO_ . uuid, jobInv. getUuid()). set(LongJobVO_ . state, org.zstack.header.longjob.LongJobState.Succeeded ). update();
356
+
357
+ env. cleanSimulatorHandlers()
358
+ }
359
+
297
360
void testLiveMigrateVmLongJobCancelFail () {
298
361
APIMigrateVmMsg msg = new APIMigrateVmMsg ()
299
362
msg. hostUuid = host1. uuid
@@ -366,7 +429,7 @@ class LiveMigrateVmJobCase extends SubCase {
366
429
return new KVMAgentCommands.MigrateVmResponse ()
367
430
}
368
431
369
- env. message(AllocateHostMsg . class){ AllocateHostMsg amsg , CloudBus bus ->
432
+ env. message(AllocateHostMsg . class) { AllocateHostMsg amsg , CloudBus bus ->
370
433
while (! canceled) {
371
434
sleep(500 )
372
435
}
@@ -376,7 +439,7 @@ class LiveMigrateVmJobCase extends SubCase {
376
439
long afterAllocateMemInByte = mem - instance. memorySize
377
440
long afterAllocateCpuCount = cpu - instance. cpuNum
378
441
379
- SQL . New (HostCapacityVO . class). eq(HostCapacityVO_ . uuid, host2. uuid)
442
+ SQL . New (HostCapacityVO . class). eq(HostCapacityVO_ . uuid, host2. uuid)
380
443
.set(HostCapacityVO_ . availableMemory, afterAllocateMemInByte)
381
444
.set(HostCapacityVO_ . availableCpu, afterAllocateCpuCount)
382
445
.update()
0 commit comments