Skip to content

Commit 6581a1b

Browse files
test/vmware: add live migratevmwithvolume test and fix (#5289)
Co-authored-by: Gabriel Brascher <gabriel@apache.org>
1 parent 75b335e commit 6581a1b

2 files changed

Lines changed: 65 additions & 17 deletions

File tree

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848
import javax.naming.ConfigurationException;
4949
import javax.xml.datatype.XMLGregorianCalendar;
5050

51-
import com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer;
52-
import com.cloud.agent.api.GetStoragePoolCapabilitiesCommand;
5351
import org.apache.cloudstack.api.ApiConstants;
5452
import org.apache.cloudstack.storage.command.CopyCommand;
5553
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
@@ -96,19 +94,21 @@
9694
import com.cloud.agent.api.DeleteVMSnapshotCommand;
9795
import com.cloud.agent.api.GetHostStatsAnswer;
9896
import com.cloud.agent.api.GetHostStatsCommand;
97+
import com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer;
98+
import com.cloud.agent.api.GetStoragePoolCapabilitiesCommand;
9999
import com.cloud.agent.api.GetStorageStatsAnswer;
100100
import com.cloud.agent.api.GetStorageStatsCommand;
101101
import com.cloud.agent.api.GetUnmanagedInstancesAnswer;
102102
import com.cloud.agent.api.GetUnmanagedInstancesCommand;
103103
import com.cloud.agent.api.GetVmDiskStatsAnswer;
104104
import com.cloud.agent.api.GetVmDiskStatsCommand;
105105
import com.cloud.agent.api.GetVmIpAddressCommand;
106-
import com.cloud.agent.api.GetVmVncTicketCommand;
107-
import com.cloud.agent.api.GetVmVncTicketAnswer;
108106
import com.cloud.agent.api.GetVmNetworkStatsAnswer;
109107
import com.cloud.agent.api.GetVmNetworkStatsCommand;
110108
import com.cloud.agent.api.GetVmStatsAnswer;
111109
import com.cloud.agent.api.GetVmStatsCommand;
110+
import com.cloud.agent.api.GetVmVncTicketAnswer;
111+
import com.cloud.agent.api.GetVmVncTicketCommand;
112112
import com.cloud.agent.api.GetVncPortAnswer;
113113
import com.cloud.agent.api.GetVncPortCommand;
114114
import com.cloud.agent.api.GetVolumeStatsAnswer;
@@ -7541,7 +7541,7 @@ private List<VolumeObjectTO> relocateVirtualMachine(final VmwareHypervisorHost h
75417541
} else {
75427542
String msg = String.format("Successfully migrated VM: %s with its storage to target datastore(s)", vmName);
75437543
if (targetHyperHost != null) {
7544-
msg = String.format("% from host %s to %s", msg, sourceHyperHost.getHyperHostName(), targetHyperHost.getHyperHostName());
7544+
msg = String.format("%s from host %s to %s", msg, sourceHyperHost.getHyperHostName(), targetHyperHost.getHyperHostName());
75457545
}
75467546
s_logger.debug(msg);
75477547
}

test/integration/smoke/test_vm_life_cycle.py

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ def tearDown(self):
12261226

12271227
def get_target_host(self, virtualmachineid):
12281228
target_hosts = Host.listForMigration(self.apiclient,
1229-
virtualmachineid=virtualmachineid)[0]
1229+
virtualmachineid=virtualmachineid)
12301230
if len(target_hosts) < 1:
12311231
self.skipTest("No target hosts found")
12321232

@@ -1252,7 +1252,8 @@ def deploy_vm(self):
12521252
serviceofferingid=self.small_offering.id,
12531253
mode=self.services["mode"])
12541254

1255-
def migrate_vm_with_pools(self, target_pool, id):
1255+
def migrate_vm_to_pool(self, target_pool, id):
1256+
12561257
cmd = migrateVirtualMachine.migrateVirtualMachineCmd()
12571258

12581259
cmd.storageid = target_pool.id
@@ -1273,17 +1274,17 @@ def create_volume(self):
12731274
)
12741275

12751276
"""
1276-
BVT for Vmware Offline VM and Volume Migration
1277+
BVT for Vmware Offline and Live VM and Volume Migration
12771278
"""
12781279

12791280
@attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg", "security"], required_hardware="false")
1280-
def test_01_migrate_VM_and_root_volume(self):
1281+
def test_01_offline_migrate_VM_and_root_volume(self):
12811282
"""Test VM will be migrated with it's root volume"""
12821283
# Validate the following
12831284
# 1. Deploys a VM
1284-
# 2. Finds suitable host for migration
1285+
# 2. Stops the VM
12851286
# 3. Finds suitable storage pool for root volume
1286-
# 4. Migrate the VM to new host and storage pool and assert migration successful
1287+
# 4. Migrate the VM to new storage pool and assert migration successful
12871288

12881289
vm = self.deploy_vm()
12891290

@@ -1293,19 +1294,19 @@ def test_01_migrate_VM_and_root_volume(self):
12931294

12941295
vm.stop(self.apiclient)
12951296

1296-
self.migrate_vm_with_pools(target_pool, vm.id)
1297+
self.migrate_vm_to_pool(target_pool, vm.id)
12971298

12981299
root_volume = self.get_vm_volumes(vm.id)[0]
12991300
self.assertEqual(root_volume.storageid, target_pool.id, "Pool ID was not as expected")
13001301

13011302
@attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg", "security"], required_hardware="false")
1302-
def test_02_migrate_VM_with_two_data_disks(self):
1303+
def test_02_offline_migrate_VM_with_two_data_disks(self):
13031304
"""Test VM will be migrated with it's root volume"""
13041305
# Validate the following
13051306
# 1. Deploys a VM and attaches 2 data disks
1306-
# 2. Finds suitable host for migration
1307+
# 2. Stops the VM
13071308
# 3. Finds suitable storage pool for volumes
1308-
# 4. Migrate the VM to new host and storage pool and assert migration successful
1309+
# 4. Migrate the VM to new storage pool and assert migration successful
13091310

13101311
vm = self.deploy_vm()
13111312

@@ -1321,7 +1322,7 @@ def test_02_migrate_VM_with_two_data_disks(self):
13211322

13221323
vm.stop(self.apiclient)
13231324

1324-
self.migrate_vm_with_pools(target_pool, vm.id)
1325+
self.migrate_vm_to_pool(target_pool, vm.id)
13251326

13261327
volume1 = Volume.list(self.apiclient, id=volume1.id)[0]
13271328
volume2 = Volume.list(self.apiclient, id=volume2.id)[0]
@@ -1332,7 +1333,54 @@ def test_02_migrate_VM_with_two_data_disks(self):
13321333
self.assertEqual(volume2.storageid, target_pool.id, "Pool ID was not as expected")
13331334

13341335
@attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg", "security"], required_hardware="false")
1335-
def test_03_migrate_detached_volume(self):
1336+
def test_03_live_migrate_VM_with_two_data_disks(self):
1337+
"""Test VM will be migrated with it's root volume"""
1338+
# Validate the following
1339+
# 1. Deploys a VM and attaches 2 data disks
1340+
# 2. Finds suitable host for migration
1341+
# 3. Finds suitable storage pool for volumes
1342+
# 4. Migrate the VM to new host and storage pool and assert migration successful
1343+
1344+
vm = self.deploy_vm()
1345+
1346+
root_volume = self.get_vm_volumes(vm.id)[0]
1347+
volume1 = self.create_volume()
1348+
volume2 = self.create_volume()
1349+
vm.attach_volume(self.apiclient, volume1)
1350+
vm.attach_volume(self.apiclient, volume2)
1351+
1352+
target_host = self.get_target_host(vm.id)
1353+
target_pool = self.get_target_pool(root_volume.id)
1354+
volume1.target_pool = self.get_target_pool(volume1.id)
1355+
volume2.target_pool = self.get_target_pool(volume2.id)
1356+
1357+
cmd = migrateVirtualMachineWithVolume.migrateVirtualMachineWithVolumeCmd()
1358+
cmd.migrateto = [{"volume": str(root_volume.id), "pool": str(target_pool.id)},
1359+
{"volume": str(volume1.id), "pool": str(volume1.target_pool.id)},
1360+
{"volume": str(volume2.id), "pool": str(volume2.target_pool.id)}]
1361+
cmd.virtualmachineid = vm.id
1362+
cmd.hostid = target_host.id
1363+
1364+
response = self.apiclient.migrateVirtualMachineWithVolume(cmd)
1365+
1366+
self.assertEqual(Volume.list(self.apiclient, id=root_volume.id)[0].storageid,
1367+
target_pool.id,
1368+
"Pool ID not as expected")
1369+
1370+
self.assertEqual(Volume.list(self.apiclient, id=volume1.id)[0].storageid,
1371+
volume1.target_pool.id,
1372+
"Pool ID not as expected")
1373+
1374+
self.assertEqual(Volume.list(self.apiclient, id=volume2.id)[0].storageid,
1375+
volume2.target_pool.id,
1376+
"Pool ID not as expected")
1377+
1378+
self.assertEqual(response.hostid,
1379+
target_host.id,
1380+
"HostID not as expected")
1381+
1382+
@attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg", "security"], required_hardware="false")
1383+
def test_04_migrate_detached_volume(self):
13361384
"""Test VM will be migrated with it's root volume"""
13371385
# Validate the following
13381386
# 1. Deploys a VM and attaches 1 data disk

0 commit comments

Comments
 (0)