Skip to content

vmware: fix inter-cluster stopped vm and volume migration - #4895

Merged
yadvr merged 7 commits into
apache:4.15from
shapeblue:fix-intercluster-migration-4838
Apr 10, 2021
Merged

vmware: fix inter-cluster stopped vm and volume migration#4895
yadvr merged 7 commits into
apache:4.15from
shapeblue:fix-intercluster-migration-4838

Conversation

@shwstppr

@shwstpprshwstppr commented Apr 5, 2021

Copy link
Copy Markdown
Contributor

Description

Fixes#4838

For inter-cluster migration without shared storage, VMware needs a host to be specified. Fix is to specify an appropriate host in the target cluster during a stopped VM migration. Also, find target datastore using the host in the target cluster.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

Fixesapache#4838
For inter-cluster migration without shared storage, VMware needs a host to be specified. Fix is to specify an appropriate host in the target cluster.
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
@shwstpprshwstppr added this to the 4.15.1.0 milestone Apr 5, 2021
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
@shwstpprshwstppr changed the title vmware: fix inter-cluster stopped vm migrationvmware: fix inter-cluster stopped vm and volume migrationApr 6, 2021
@shwstppr
shwstppr marked this pull request as ready for review April 6, 2021 07:40
@shwstppr

Copy link
Copy Markdown
ContributorAuthor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@shwstppr a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✔️ centos7 ✔️ centos8 ✔️ debian. SL-JID 336

@shwstppr

Copy link
Copy Markdown
ContributorAuthor

@blueorangutan test centos7 vmware-67u3

@blueorangutan

Copy link
Copy Markdown

@shwstppr a Trillian-Jenkins test job (centos7 mgmt + vmware-67u3) has been kicked to run smoke tests

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>

@DaanHooglandDaanHoogland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly structural change requests so far.

Comment on lines +230 to +239
List<VolumeVO> volumes = _volumeDao.findByInstanceAndType(vmId, Volume.Type.ROOT);
if (CollectionUtils.isNotEmpty(volumes)) {
VolumeVO rootVolume = volumes.get(0);
if (rootVolume.getPoolId() != null) {
StoragePoolVO pool = _storagePoolDao.findById(rootVolume.getPoolId());
if (pool != null && pool.getClusterId() != null) {
clusterId = pool.getClusterId();
}
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please extract into a separate method. i.e. Long getPoolFromRootVolume(...)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +1093 to +1109
final boolean isInterClusterMigration = srcClusterId != null && destClusterId != null && ! srcClusterId.equals(destClusterId);
Host hostInTargetCluster = null;
if (isInterClusterMigration) {
// Without host vMotion might fail between non-shared storages with error similar to,
// https://kb.vmware.com/s/article/1003795
// As this is offline migration VM won't be started on this host
List<HostVO> hosts = _hostDao.findHypervisorHostInCluster(destClusterId);
if (CollectionUtils.isNotEmpty(hosts)) {
hostInTargetCluster = hosts.get(0);
}
if (hostInTargetCluster == null) {
throw new CloudRuntimeException("Migration failed, unable to find suitable target host for VM placement while migrating between storage pools of different clusters without shared storages");
}
}
MigrateVmToPoolCommand migrateVmToPoolCommand = new MigrateVmToPoolCommand(vm.getInstanceName(),
vols, destination.getUuid(), hostInTargetCluster == null ? null : hostInTargetCluster.getGuid(), true);
commands.add(migrateVmToPoolCommand);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please restructure this in smaller methods

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private Answer migrateAndAnswer(VirtualMachineMO vmMo, String poolUuid, VmwareHypervisorHost hyperHost, Command cmd) throws Exception {
ManagedObjectReference morDs = getTargetDatastoreMOReference(poolUuid, hyperHost);

private Answer migrateAndAnswer(VirtualMachineMO vmMo, String poolUuid, VmwareHypervisorHost sourceHyperHost,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please restructure this method (at least extract the new pieces)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

morDcOfTargetHost = tgtHyperHost.getHyperHostDatacenter();
if (!morDc.getValue().equalsIgnoreCase(morDcOfTargetHost.getValue())) {
String msg = "Source host & target host are in different datacentesr";
String msg = "Source host & target host are in different datacenter";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +4855 to +4859
VmwareHypervisorHost hyperHostInTargetCluster = null;
if (cmd.getHostGuidInTargetCluster() != null) {
hyperHostInTargetCluster = VmwareHelper.getHostMOFromHostName(getServiceContext(), cmd.getHostGuidInTargetCluster());
}
VmwareHypervisorHost targetDSHost = hyperHostInTargetCluster != null ? hyperHostInTargetCluster : hyperHost;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this merrits a call to a specific method

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaanHoogland which specific method? I didn't get you

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like

Suggested change
VmwareHypervisorHosthyperHostInTargetCluster = null;
if (cmd.getHostGuidInTargetCluster() != null) {
hyperHostInTargetCluster = VmwareHelper.getHostMOFromHostName(getServiceContext(), cmd.getHostGuidInTargetCluster());
}
VmwareHypervisorHosttargetDSHost = hyperHostInTargetCluster != null ? hyperHostInTargetCluster : hyperHost;
VmwareHypervisorHosttargetDSHost = getTargetHostFromTargetCluster(cmd);

and

Suggested change
VmwareHypervisorHosthyperHostInTargetCluster = null;
if (cmd.getHostGuidInTargetCluster() != null) {
hyperHostInTargetCluster = VmwareHelper.getHostMOFromHostName(getServiceContext(), cmd.getHostGuidInTargetCluster());
}
VmwareHypervisorHosttargetDSHost = hyperHostInTargetCluster != null ? hyperHostInTargetCluster : hyperHost;
privateVmwareHypervisorHostgetTargetHostFromTargetCluster(MigrateVolumeCmdcmd) {
VmwareHypervisorHosthyperHostInTargetCluster = null;
if (cmd.getHostGuidInTargetCluster() != null) {
hyperHostInTargetCluster = VmwareHelper.getHostMOFromHostName(getServiceContext(), cmd.getHostGuidInTargetCluster());
}
returnhyperHostInTargetCluster != null ? hyperHostInTargetCluster : hyperHost;
}

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaanHoogland both hyperHostInTargetCluster and targetDSHost are used in the method later multiple times. I used two different variables to prevent using if..else multiple times.

Comment on lines +4884 to +4891
String hardwareVersion = null;
if (hyperHostInTargetCluster != null) {
Integer sourceHardwareVersion = HypervisorHostHelper.getHostHardwareVersion(hyperHost);
Integer destinationHardwareVersion = HypervisorHostHelper.getHostHardwareVersion(hyperHostInTargetCluster);
if (sourceHardwareVersion != null && destinationHardwareVersion != null && !sourceHardwareVersion.equals(destinationHardwareVersion)) {
hardwareVersion = String.valueOf(Math.min(sourceHardwareVersion, destinationHardwareVersion));
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please extract

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +182 to +207
ScopeType targetScopeType = destData.getDataStore().getScope().getScopeType();
Long hostId = null;
String hostGuidInTargetCluster = null;
if (ScopeType.CLUSTER.equals(sourceScopeType)) {
// Find Volume source cluster and select any Vmware hypervisor host to attach worker VM
hostId = findSuitableHostIdForWorkerVmPlacement(sourcePool.getClusterId());
if (hostId == null) {
throw new CloudRuntimeException("Offline Migration failed, unable to find suitable host for worker VM placement in the cluster of storage pool: " + sourcePool.getName());
}
if (ScopeType.CLUSTER.equals(targetScopeType) && !sourcePool.getClusterId().equals(targetPool.getClusterId())) {
// Without host vMotion might fail between non-shared storages with error similar to,
// https://kb.vmware.com/s/article/1003795
List<HostVO> hosts = hostDao.findHypervisorHostInCluster(targetPool.getClusterId());
if (CollectionUtils.isNotEmpty(hosts)) {
hostGuidInTargetCluster = hosts.get(0).getGuid();
}
if (hostGuidInTargetCluster == null) {
throw new CloudRuntimeException("Offline Migration failed, unable to find suitable target host for worker VM placement while migrating between storage pools of different cluster without shared storages");
}
}
} else if (ScopeType.CLUSTER.equals(targetScopeType)) {
hostId = findSuitableHostIdForWorkerVmPlacement(targetPool.getClusterId());
if (hostId == null) {
throw new CloudRuntimeException("Offline Migration failed, unable to find suitable host for worker VM placement in the cluster of storage pool: " + targetPool.getName());
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please extract getTargetScopeType(..) and possibly more methods from that.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blueorangutan

Copy link
Copy Markdown

Trillian test result (tid-357)
Environment: vmware-67u3 (x2), Advanced Networking with Mgmt server 7
Total time taken: 37216 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr4895-t357-vmware-67u3.zip
Intermittent failure detected: /marvin/tests/smoke/test_kubernetes_clusters.py
Intermittent failure detected: /marvin/tests/smoke/test_vm_life_cycle.py
Smoke tests completed. 84 look OK, 2 have error(s)
Only failed tests results shown below:

TestResultTime (s)Test File
test_01_deploy_kubernetes_clusterFailure91.50test_kubernetes_clusters.py
test_02_invalid_upgrade_kubernetes_clusterFailure82.93test_kubernetes_clusters.py
test_03_deploy_and_upgrade_kubernetes_clusterFailure61.53test_kubernetes_clusters.py
test_04_deploy_and_scale_kubernetes_clusterFailure65.72test_kubernetes_clusters.py
test_05_delete_kubernetes_clusterFailure71.91test_kubernetes_clusters.py
test_07_deploy_kubernetes_ha_clusterFailure80.17test_kubernetes_clusters.py
test_08_deploy_and_upgrade_kubernetes_ha_clusterFailure71.87test_kubernetes_clusters.py
test_09_delete_kubernetes_ha_clusterFailure66.15test_kubernetes_clusters.py
ContextSuite context=TestKubernetesCluster>:teardownError110.82test_kubernetes_clusters.py
ContextSuite context=TestVAppsVM>:setupError43.81test_vm_life_cycle.py

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
@shwstppr

Copy link
Copy Markdown
ContributorAuthor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@shwstppr a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✔️ centos7 ✔️ centos8 ✔️ debian. SL-JID 342

@shwstpprshwstppr mentioned this pull request Apr 7, 2021
12 tasks
@shwstppr

Copy link
Copy Markdown
ContributorAuthor

@blueorangutan test centos7 vmware-67u3

@blueorangutan

Copy link
Copy Markdown

@shwstppr a Trillian-Jenkins test job (centos7 mgmt + vmware-67u3) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

Trillian test result (tid-370)
Environment: vmware-67u3 (x2), Advanced Networking with Mgmt server 7
Total time taken: 38520 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr4895-t370-vmware-67u3.zip
Intermittent failure detected: /marvin/tests/smoke/test_diagnostics.py
Intermittent failure detected: /marvin/tests/smoke/test_kubernetes_clusters.py
Intermittent failure detected: /marvin/tests/smoke/test_vm_life_cycle.py
Intermittent failure detected: /marvin/tests/smoke/test_vpc_vpn.py
Smoke tests completed. 83 look OK, 4 have error(s)
Only failed tests results shown below:

TestResultTime (s)Test File
test_10_traceroute_in_vrFailure61.23test_diagnostics.py
test_01_deploy_kubernetes_clusterFailure96.60test_kubernetes_clusters.py
test_02_invalid_upgrade_kubernetes_clusterFailure99.39test_kubernetes_clusters.py
test_03_deploy_and_upgrade_kubernetes_clusterFailure65.70test_kubernetes_clusters.py
test_04_deploy_and_scale_kubernetes_clusterFailure64.58test_kubernetes_clusters.py
test_05_delete_kubernetes_clusterFailure58.55test_kubernetes_clusters.py
test_07_deploy_kubernetes_ha_clusterFailure54.61test_kubernetes_clusters.py
test_08_deploy_and_upgrade_kubernetes_ha_clusterFailure66.72test_kubernetes_clusters.py
test_09_delete_kubernetes_ha_clusterFailure82.07test_kubernetes_clusters.py
ContextSuite context=TestKubernetesCluster>:teardownError121.47test_kubernetes_clusters.py
ContextSuite context=TestVAppsVM>:setupError44.65test_vm_life_cycle.py
test_01_redundant_vpc_site2site_vpnFailure373.50test_vpc_vpn.py

VM can have multiple ROOT volumes and some can be on zone-wide store therefore iterate over all of them till a cluster ID is found.
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
@shwstppr

Copy link
Copy Markdown
ContributorAuthor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@shwstppr a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✔️ centos7 ✔️ centos8 ✔️ debian. SL-JID 358

@borisstoyanov

Copy link
Copy Markdown
Contributor

@blueorangutan test centos7 vmware-67u3

@blueorangutan

Copy link
Copy Markdown

@borisstoyanov a Trillian-Jenkins test job (centos7 mgmt + vmware-67u3) has been kicked to run smoke tests

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
@shwstppr

Copy link
Copy Markdown
ContributorAuthor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@shwstppr a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✔️ centos7 ✔️ centos8 ✔️ debian. SL-JID 361

@borisstoyanov

Copy link
Copy Markdown
Contributor

@blueorangutan test centos7 vmware-67u3

@blueorangutan

Copy link
Copy Markdown

@borisstoyanov a Trillian-Jenkins test job (centos7 mgmt + vmware-67u3) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

Trillian test result (tid-385)
Environment: vmware-67u3 (x2), Advanced Networking with Mgmt server 7
Total time taken: 35028 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr4895-t385-vmware-67u3.zip
Intermittent failure detected: /marvin/tests/smoke/test_kubernetes_clusters.py
Intermittent failure detected: /marvin/tests/smoke/test_vm_life_cycle.py
Smoke tests completed. 85 look OK, 2 have error(s)
Only failed tests results shown below:

TestResultTime (s)Test File
test_01_deploy_kubernetes_clusterFailure89.55test_kubernetes_clusters.py
test_02_invalid_upgrade_kubernetes_clusterFailure56.36test_kubernetes_clusters.py
test_03_deploy_and_upgrade_kubernetes_clusterFailure55.27test_kubernetes_clusters.py
test_04_deploy_and_scale_kubernetes_clusterFailure56.29test_kubernetes_clusters.py
test_05_delete_kubernetes_clusterFailure53.22test_kubernetes_clusters.py
test_07_deploy_kubernetes_ha_clusterFailure100.16test_kubernetes_clusters.py
test_08_deploy_and_upgrade_kubernetes_ha_clusterFailure59.30test_kubernetes_clusters.py
test_09_delete_kubernetes_ha_clusterFailure57.29test_kubernetes_clusters.py
ContextSuite context=TestKubernetesCluster>:teardownError101.95test_kubernetes_clusters.py
ContextSuite context=TestVAppsVM>:setupError45.65test_vm_life_cycle.py

@borisstoyanovborisstoyanov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tested on VMware with single and successive migration of VM

@yadvr

yadvr commented Apr 9, 2021

Copy link
Copy Markdown
Member

@nvazquez are you lgtm on the PR? Will hold merging until your confirmation.

@yadvr
yadvr requested a review from nvazquezApril 9, 2021 07:38

@nvazqueznvazquez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @shwstppr for addressing the comments, LGTM

@yadvr
yadvr merged commit fdefee7 into apache:4.15Apr 10, 2021
@yadvr

Copy link
Copy Markdown
Member

Merged based on Bobby, Nicolas's review and testing, and smoketests.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@shwstppr@blueorangutan@borisstoyanov@yadvr@DaanHoogland@nvazquez