This is an automated email from the ASF dual-hosted git repository.
Pearl1594 pushed a commit to branch trunk-nics-fixes
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/trunk-nics-fixes by this push:
new 1373f10da09 Trunk NICs: address review findings on #14803
1373f10da09 is described below
commit 1373f10da09ce36610726ec8e0b65ed0d6cbe397
Author: Pearl1594 <[email protected]>
AuthorDate: Mon Nov 23 17:29:37 2026 -0500
Trunk NICs: address review findings on #14803
- Retry the post-migration command with a non-empty failure reason for
every failed attempt
- Continue past a failing NIC in the post-migration loop, cut off every NIC
that could not get its VLANs, and report one error
- Restore a cut-off NIC's link on migration when the destination applies no
manual VLAN membership; keep it down until post-migration where it does
- Alert when the post-migration command fails during a migration with
storage, through a shared PostMigrationAlerts helper
- Skip plain VLAN NICs in the memory snapshot revert VLAN update when the
zone setting is off
- Restore the NIC's enabled state, not always link up, after hot-plug and
replug
- Log a WARN when a plain VLAN NIC is on a VLAN-aware bridge although the
zone setting is off
- Document the effect of turning multi.network.nic.enabled off in the
setting description
---
.../cloud/agent/api/VlanTrunkMigrationHelper.java | 20 +++++--
.../service/NetworkOrchestrationService.java | 5 +-
.../java/com/cloud/alert/PostMigrationAlerts.java | 38 ++++++++++++
.../com/cloud/vm/VirtualMachineManagerImpl.java | 12 +---
.../motion/StorageSystemDataMotionStrategy.java | 13 ++++-
.../kvm/resource/LibvirtComputingResource.java | 14 ++++-
.../wrapper/LibvirtMigrateCommandWrapper.java | 68 ++++++++++++++++++++++
.../wrapper/LibvirtPlugNicCommandWrapper.java | 2 +-
.../LibvirtPostMigrationCommandWrapper.java | 30 ++++++----
.../wrapper/LibvirtReplugNicCommandWrapper.java | 2 +-
.../LibvirtReplugNicCommandWrapperTest.java | 1 +
.../storage/motion/LinstorDataMotionStrategy.java | 13 ++++-
.../storage/motion/StorPoolDataMotionStrategy.java | 13 ++++-
.../java/com/cloud/network/NetworkServiceImpl.java | 3 +-
14 files changed, 200 insertions(+), 34 deletions(-)
diff --git
a/core/src/main/java/com/cloud/agent/api/VlanTrunkMigrationHelper.java
b/core/src/main/java/com/cloud/agent/api/VlanTrunkMigrationHelper.java
index d185a65a988..cf4a0d6d696 100644
--- a/core/src/main/java/com/cloud/agent/api/VlanTrunkMigrationHelper.java
+++ b/core/src/main/java/com/cloud/agent/api/VlanTrunkMigrationHelper.java
@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import com.cloud.agent.api.to.VirtualMachineTO;
@@ -141,20 +142,26 @@ public class VlanTrunkMigrationHelper {
&&
"1".equals(Networks.BroadcastDomainType.getValue(broadcastUri));
}
+ // A plain VLAN nic only rides the shared bridge, and so needs manual
membership, when the zone opt-in is on; a trunk nic always does.
+ public static boolean nicNeedsManualVlanMembership(NicVO nic, boolean
vlanFilteringEnabled, boolean sharedVlanBridgeEnabled) {
+ return nicNeedsManualVlanMembership(nic, vlanFilteringEnabled &&
(nic.getMultiNetwork() || sharedVlanBridgeEnabled));
+ }
+
public static boolean nicNeedsManualVlanMembership(NicVO nic, boolean
vlanFilteringEnabled) {
return nic.getBroadcastUri() != null &&
Networks.BroadcastDomainType.getSchemeValue(nic.getBroadcastUri()) ==
Networks.BroadcastDomainType.Vlan
&& (nic.getMultiNetwork() || vlanFilteringEnabled);
}
- public static void
sendPostMigrationVlanTrunkMembershipIfNeeded(VirtualMachineTO vmTO, long
dstHostId,
+ // returns null when nothing was needed or the tasks completed, else the
last failure so the caller can alert
+ public static String
sendPostMigrationVlanTrunkMembershipIfNeeded(VirtualMachineTO vmTO, long
dstHostId,
NicDao nicDao, HostDetailsDao hostDetailsDao, CommandSender
commandSender, Logger logger) {
- sendPostMigrationVlanTrunkMembershipIfNeeded(vmTO, dstHostId, nicDao,
hostDetailsDao, commandSender, logger, POST_MIGRATION_RETRY_DELAY_MS);
+ return sendPostMigrationVlanTrunkMembershipIfNeeded(vmTO, dstHostId,
nicDao, hostDetailsDao, commandSender, logger, POST_MIGRATION_RETRY_DELAY_MS);
}
- static void sendPostMigrationVlanTrunkMembershipIfNeeded(VirtualMachineTO
vmTO, long dstHostId,
+ static String
sendPostMigrationVlanTrunkMembershipIfNeeded(VirtualMachineTO vmTO, long
dstHostId,
NicDao nicDao, HostDetailsDao hostDetailsDao, CommandSender
commandSender, Logger logger, long retryDelayMs) {
if (!vmNeedsPostMigrationVlanTrunkMembership(vmTO.getId(), dstHostId,
nicDao, hostDetailsDao)) {
- return;
+ return null;
}
String failure = sendPostMigrationCommandWithRetry(vmTO, dstHostId,
commandSender, logger, retryDelayMs);
if (failure != null) {
@@ -162,6 +169,7 @@ public class VlanTrunkMigrationHelper {
+ "Migration completed but its tap may still be on the
bridge's default VLAN; correct the VLAN membership or restart the VM.",
vmTO, dstHostId, failure);
}
+ return failure;
}
// returns null once an attempt succeeds, else the last failure after all
attempts
@@ -192,9 +200,9 @@ public class VlanTrunkMigrationHelper {
if (postMigrationAnswer != null &&
postMigrationAnswer.getResult()) {
return null;
}
- return postMigrationAnswer != null ?
postMigrationAnswer.getDetails() : "null answer returned";
+ return postMigrationAnswer != null ?
StringUtils.defaultIfBlank(postMigrationAnswer.getDetails(), "no details
returned") : "null answer returned";
} catch (Exception e) {
- return e.getMessage();
+ return StringUtils.defaultIfBlank(e.getMessage(), e.toString());
}
}
diff --git
a/engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java
b/engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java
index dfc3144675d..5c6e8dc4525 100644
---
a/engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java
+++
b/engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java
@@ -99,7 +99,10 @@ public interface NetworkOrchestrationService {
"Whether to allow or deny promiscuous mode on NICs for applicable
network elements such as for vswitch/dvswitch portgroups.", true);
ConfigKey<Boolean> MultiNetworkNicEnabled = new ConfigKey<>("Advanced",
Boolean.class, "multi.network.nic.enabled", "false",
- "Allow a NIC to be associated with more than one network
(multi-VLAN trunk NICs)", true, ConfigKey.Scope.Zone);
+ "Allow a NIC to be associated with more than one network
(multi-VLAN trunk NICs). When on, VLAN NICs also use the shared VLAN-aware
guest bridge on KVM hosts "
+ + "with vlan_filtering. Turning it off does not move
running Instances: restart them without migrating or reverting them first, "
+ + "or their plain VLAN NICs can end up on VLAN 1.",
+ true, ConfigKey.Scope.Zone);
ConfigKey<Boolean> MacAddressChanges = new ConfigKey<>("Advanced",
Boolean.class, "network.mac.address.changes", "true",
"Whether to allow or deny mac address changes on NICs for
applicable network elements such as for vswitch/dvswitch porgroups.", true);
diff --git
a/engine/components-api/src/main/java/com/cloud/alert/PostMigrationAlerts.java
b/engine/components-api/src/main/java/com/cloud/alert/PostMigrationAlerts.java
new file mode 100644
index 00000000000..624f7efd06e
--- /dev/null
+++
b/engine/components-api/src/main/java/com/cloud/alert/PostMigrationAlerts.java
@@ -0,0 +1,38 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.alert;
+
+import com.cloud.vm.VirtualMachine;
+
+public final class PostMigrationAlerts {
+
+ private PostMigrationAlerts() {
+ }
+
+ public static void sendFailureAlert(AlertManager alertMgr,
VirtualMachine.Type vmType, long zoneId, Long podId, String vmName, String
destHostUuid, String details) {
+ AlertManager.AlertType alertType =
AlertManager.AlertType.ALERT_TYPE_USERVM_MIGRATE;
+ if (VirtualMachine.Type.DomainRouter.equals(vmType)) {
+ alertType =
AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER_MIGRATE;
+ } else if (VirtualMachine.Type.ConsoleProxy.equals(vmType)) {
+ alertType =
AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY_MIGRATE;
+ }
+ alertMgr.sendAlert(alertType, zoneId, podId,
+ String.format("Post-migration tasks failed for VM %s on
destination host %s.", vmName, destHostUuid),
+ String.format("Post-migration tasks failed: %s. VM
network/storage configuration on the destination may be incomplete. "
+ + "If a VLAN nic of the Instance could not get its
VLAN membership, its link is set down; restart the Instance to apply it.",
details));
+ }
+}
diff --git
a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
index ab733ba4ec5..52dc004d19f 100755
---
a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
+++
b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -50,6 +50,7 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException;
import javax.persistence.EntityExistsException;
+import com.cloud.alert.PostMigrationAlerts;
import com.cloud.storage.clvm.ClvmPoolManager;
import com.cloud.hypervisor.KVMGuru;
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
@@ -3403,16 +3404,7 @@ public class VirtualMachineManagerImpl extends
ManagerBase implements VirtualMac
}
private void alertPostMigrationFailure(VMInstanceVO vm, String
dstHostUuid, String details) {
- AlertManager.AlertType alertType =
AlertManager.AlertType.ALERT_TYPE_USERVM_MIGRATE;
- if (VirtualMachine.Type.DomainRouter.equals(vm.getType())) {
- alertType =
AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER_MIGRATE;
- } else if (VirtualMachine.Type.ConsoleProxy.equals(vm.getType())) {
- alertType =
AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY_MIGRATE;
- }
- _alertMgr.sendAlert(alertType, vm.getDataCenterId(),
vm.getPodIdToDeployIn(),
- String.format("Post-migration tasks failed for VM %s on
destination host %s.", vm.getInstanceName(), dstHostUuid),
- String.format("Post-migration tasks failed: %s. VM
network/storage configuration on the destination may be incomplete. "
- + "A VLAN trunk nic whose VLAN membership could not be
applied has its link set down; restart the VM to apply it.", details));
+ PostMigrationAlerts.sendFailureAlert(_alertMgr, vm.getType(),
vm.getDataCenterId(), vm.getPodIdToDeployIn(), vm.getInstanceName(),
dstHostUuid, details);
}
/**
diff --git
a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java
b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java
index 6d37059eb20..85103a320a6 100644
---
a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java
+++
b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java
@@ -32,6 +32,8 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
+import com.cloud.alert.PostMigrationAlerts;
+import com.cloud.alert.AlertManager;
import com.cloud.agent.api.CheckVirtualMachineAnswer;
import com.cloud.agent.api.CheckVirtualMachineCommand;
import com.cloud.agent.api.PrepareForMigrationAnswer;
@@ -186,6 +188,8 @@ public class StorageSystemDataMotionStrategy implements
DataMotionStrategy {
@Inject
private NicDao nicDao;
@Inject
+ private AlertManager alertMgr;
+ @Inject
protected PrimaryDataStoreDao _storagePoolDao;
@Inject
private SnapshotDao _snapshotDao;
@@ -2235,7 +2239,8 @@ public class StorageSystemDataMotionStrategy implements
DataMotionStrategy {
handlePostMigration(success, srcVolumeInfoToDestVolumeInfo, vmTO,
srcHost, destHost);
if (success) {
-
VlanTrunkMigrationHelper.sendPostMigrationVlanTrunkMembershipIfNeeded(vmTO,
destHost.getId(), nicDao, hostDetailsDao, agentManager::send, logger);
+ alertOnPostMigrationFailure(vmTO, destHost,
VlanTrunkMigrationHelper.sendPostMigrationVlanTrunkMembershipIfNeeded(
+ vmTO, destHost.getId(), nicDao, hostDetailsDao,
agentManager::send, logger));
}
if (!success) {
@@ -3390,4 +3395,10 @@ public class StorageSystemDataMotionStrategy implements
DataMotionStrategy {
return supportedTypes.contains(storagePoolTypeToValidate);
};
+
+ private void alertOnPostMigrationFailure(VirtualMachineTO vmTO, Host
destHost, String failure) {
+ if (failure != null) {
+ PostMigrationAlerts.sendFailureAlert(alertMgr, vmTO.getType(),
destHost.getDataCenterId(), destHost.getPodId(), vmTO.getName(),
destHost.getUuid(), failure);
+ }
+ }
}
diff --git
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
index 60265d5950e..d9d9fc40d7d 100644
---
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -6383,6 +6383,18 @@ public class LibvirtComputingResource extends
ServerResourceBase implements Serv
}
}
+ // A plain VLAN nic plugged while multi.network.nic.enabled was on stays
on the shared VLAN-aware bridge after the setting is turned off,
+ // but its VLAN membership is then no longer managed.
+ public void warnIfNicOnVlanAwareBridgeDespiteOptOut(InterfaceDef
liveInterface, NicTO nic, String vmName) {
+ if (nic.getBroadcastType() != BroadcastDomainType.Vlan ||
nic.isTrunkVlan() || nic.isSharedVlanBridgeEnabled()
+ || StringUtils.isBlank(liveInterface.getBrName()) ||
!isBridgeVlanFilteringEnabled(liveInterface.getBrName())) {
+ return;
+ }
+ LOGGER.warn("Nic {} of VM {} is on the VLAN-aware guest bridge {}
although multi.network.nic.enabled is off for its zone, because it was plugged
while the "
+ + "setting was on. Its VLAN membership is no longer managed,
so after a migration or a memory snapshot revert it may sit on the bridge's
default VLAN. "
+ + "Restart the VM to move it to a dedicated per-VLAN bridge.",
nic.getMac(), vmName, liveInterface.getBrName());
+ }
+
public void setGuestTrafficLabel(String guestTrafficLabel) {
this.guestTrafficLabel = guestTrafficLabel;
}
@@ -6392,7 +6404,7 @@ public class LibvirtComputingResource extends
ServerResourceBase implements Serv
return StringUtils.isNotBlank(guestTrafficLabel) ? guestTrafficLabel :
guestBridgeName;
}
- protected boolean isBridgeVlanFilteringEnabled(String bridgeName) {
+ public boolean isBridgeVlanFilteringEnabled(String bridgeName) {
if (StringUtils.isBlank(bridgeName)) {
return false;
}
diff --git
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java
index 76c85b4ed5a..d417c7a84d8 100644
---
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java
+++
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java
@@ -23,6 +23,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -33,6 +34,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import java.util.regex.Pattern;
import java.util.concurrent.TimeoutException;
import javax.xml.parsers.DocumentBuilder;
@@ -97,6 +99,8 @@ public final class LibvirtMigrateCommandWrapper extends
CommandWrapper<MigrateCo
private static final String GRAPHICS_ELEM_END = "/graphics>";
private static final String GRAPHICS_ELEM_START = "<graphics";
+ // quote style differs between libvirt's own XML (single) and XML
re-serialized by an earlier rewrite step (double)
+ private static final Pattern LINK_DOWN_ELEMENT =
Pattern.compile("<link\\s+state\\s*=\\s*['\"]down['\"]");
private static final String CONTENTS_WILDCARD = "(?s).*";
private static final String CDROM_LABEL = "hdc";
@@ -236,6 +240,10 @@ public final class LibvirtMigrateCommandWrapper extends
CommandWrapper<MigrateCo
xmlDesc = replaceVlanTrunkInterfaces(xmlDesc, command,
libvirtComputingResource);
+ xmlDesc = restoreCutOffNicLinks(xmlDesc, command, vmName);
+
+ warnAboutNicsOnVlanAwareBridgeDespiteOptOut(ifaces, command,
libvirtComputingResource, vmName);
+
xmlDesc = updateVmSharesIfNeeded(command, xmlDesc,
libvirtComputingResource);
xmlDesc = updateGpuDevicesIfNeeded(command, xmlDesc,
libvirtComputingResource);
@@ -696,6 +704,66 @@ public final class LibvirtMigrateCommandWrapper extends
CommandWrapper<MigrateCo
}
// Trunk nics always need it; ordinary nics only when the zone opted in to
the shared VLAN-aware bridge
+ // A VLAN nic cut off by a failed post-migration is link-down in the
source XML, which migration carries to the destination. Where the
+ // destination applies no VLAN membership by hand (libvirt does it from
the XML, or it has dedicated per-VLAN bridges) nothing would ever bring
+ // the link back, so an enabled nic arrives up. Where the post-migration
command will run it must stay down until that has applied the VLANs,
+ // so the nic is not exposed on VLAN 1 meanwhile. Other nics are left as
they are.
+ protected String restoreCutOffNicLinks(String xmlDesc, MigrateCommand
command, String vmName)
+ throws ParserConfigurationException, IOException, SAXException,
TransformerException {
+ NicTO[] nics = command.getVirtualMachine().getNics();
+ if (!destinationAppliesNoManualVlanMembership(command) ||
!LINK_DOWN_ELEMENT.matcher(xmlDesc).find() || nics == null
+ || Arrays.stream(nics).noneMatch(this::isEnabledVlanNic)) {
+ return xmlDesc;
+ }
+ Document doc =
ParserUtils.getSaferDocumentBuilderFactory().newDocumentBuilder().parse(IOUtils.toInputStream(xmlDesc));
+ boolean restored = false;
+ NodeList interfaces = doc.getElementsByTagName("interface");
+ for (int i = 0; i < interfaces.getLength(); i++) {
+ Element interfaceElement = (Element) interfaces.item(i);
+ String mac = findInterfaceMacAddress(interfaceElement);
+ NicTO nic = mac == null ? null : findNicByMac(nics, mac);
+ if (nic != null && isEnabledVlanNic(nic) &&
setLinkUp(interfaceElement)) {
+ logger.info("The link of nic {} of VM {} is down on the
source; it is set up in the destination definition because the nic is enabled",
mac, vmName);
+ restored = true;
+ }
+ }
+ return restored ? LibvirtXMLParser.getXml(doc) : xmlDesc;
+ }
+
+ private void
warnAboutNicsOnVlanAwareBridgeDespiteOptOut(List<InterfaceDef> liveInterfaces,
MigrateCommand command,
+ LibvirtComputingResource libvirtComputingResource, String vmName) {
+ NicTO[] nics = command.getVirtualMachine().getNics();
+ if (nics == null) {
+ return;
+ }
+ for (InterfaceDef liveInterface : liveInterfaces) {
+ NicTO nic = liveInterface.getMacAddress() == null ? null :
findNicByMac(nics, liveInterface.getMacAddress());
+ if (nic != null) {
+
libvirtComputingResource.warnIfNicOnVlanAwareBridgeDespiteOptOut(liveInterface,
nic, vmName);
+ }
+ }
+ }
+
+ private boolean destinationAppliesNoManualVlanMembership(MigrateCommand
command) {
+ return Boolean.TRUE.equals(command.getDestVlanTrunkXmlSupported()) ||
Boolean.FALSE.equals(command.getDestVlanFilteringEnabled());
+ }
+
+ private boolean isEnabledVlanNic(NicTO nic) {
+ return nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan &&
nic.isEnabled();
+ }
+
+ private boolean setLinkUp(Element interfaceElement) {
+ NodeList links = interfaceElement.getElementsByTagName("link");
+ for (int i = 0; i < links.getLength(); i++) {
+ Element link = (Element) links.item(i);
+ if ("down".equals(link.getAttribute("state"))) {
+ link.setAttribute("state", "up");
+ return true;
+ }
+ }
+ return false;
+ }
+
private boolean needsVlanRewrite(NicTO nic, boolean
sourceVlanFilteringEnabled, boolean destVlanFilteringEnabled) {
return nic.isTrunkVlan() || (nic.isSharedVlanBridgeEnabled() &&
(sourceVlanFilteringEnabled || destVlanFilteringEnabled));
}
diff --git
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPlugNicCommandWrapper.java
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPlugNicCommandWrapper.java
index 5f29c5250c3..9f7a007fab5 100644
---
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPlugNicCommandWrapper.java
+++
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPlugNicCommandWrapper.java
@@ -106,7 +106,7 @@ public final class LibvirtPlugNicCommandWrapper extends
CommandWrapper<PlugNicCo
}
}
if (linkDownUntilVlansApplied) {
- interfaceDef.setLinkStateUp(true);
+ interfaceDef.setLinkStateUp(nic.isEnabled());
vm.updateDeviceFlags(interfaceDef.toString(),
Domain.DeviceModifyFlags.LIVE);
}
diff --git
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPostMigrationCommandWrapper.java
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPostMigrationCommandWrapper.java
index 698d00b7037..0903c4c29f7 100644
---
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPostMigrationCommandWrapper.java
+++
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPostMigrationCommandWrapper.java
@@ -88,29 +88,39 @@ public final class LibvirtPostMigrationCommandWrapper
extends CommandWrapper<Pos
}
private void applyManualVlanTrunkMembership(Connect conn, String vmName,
NicTO[] nics, LibvirtComputingResource libvirtComputingResource)
- throws InternalErrorException, LibvirtException {
+ throws InternalErrorException {
if (nics == null) {
return;
}
- InternalErrorException firstFailure = null;
+ Exception firstFailure = null;
for (NicTO nic : nics) {
if (nic.getBroadcastType() != Networks.BroadcastDomainType.Vlan) {
continue;
}
- LibvirtVMDef.InterfaceDef liveInterface =
libvirtComputingResource.getInterface(conn, vmName, nic.getMac());
try {
- libvirtComputingResource.getVifDriver(nic.getType(),
nic.getName()).ensureVlanTrunkMembership(liveInterface, nic);
- } catch (InternalErrorException e) {
+ applyVlanMembershipOrFailClosed(conn, vmName, nic,
libvirtComputingResource);
+ } catch (Exception e) {
// keep going so every other nic of the VM is also applied or
cut off, not left on VLAN 1
- failClosed(conn, vmName, nic, libvirtComputingResource);
+ logger.error("Failed to set up the VLAN membership of nic {}
of VM {}: {}", nic.getMac(), vmName, e.getMessage(), e);
firstFailure = firstFailure == null ? e : firstFailure;
- continue;
}
- restoreLinkIfCutOff(conn, vmName, nic, liveInterface,
libvirtComputingResource);
}
if (firstFailure != null) {
- throw firstFailure;
+ throw new InternalErrorException(String.format("VLAN membership
could not be set up for every nic of VM %s: %s", vmName,
firstFailure.getMessage()));
+ }
+ }
+
+ private void applyVlanMembershipOrFailClosed(Connect conn, String vmName,
NicTO nic, LibvirtComputingResource libvirtComputingResource) throws Exception {
+ LibvirtVMDef.InterfaceDef liveInterface;
+ try {
+ liveInterface = libvirtComputingResource.getInterface(conn,
vmName, nic.getMac());
+ libvirtComputingResource.getVifDriver(nic.getType(),
nic.getName()).ensureVlanTrunkMembership(liveInterface, nic);
+ } catch (Exception e) {
+ failClosed(conn, vmName, nic, libvirtComputingResource);
+ throw e;
}
+
libvirtComputingResource.warnIfNicOnVlanAwareBridgeDespiteOptOut(liveInterface,
nic, vmName);
+ restoreLinkIfCutOff(conn, vmName, nic, liveInterface,
libvirtComputingResource);
}
// Without its VLANs the tap sits on the bridge's default VLAN 1, so cut
the nic off rather than leave it there
@@ -122,7 +132,7 @@ public final class LibvirtPostMigrationCommandWrapper
extends CommandWrapper<Pos
setNicLinkState(conn, vmName, nic, false,
libvirtComputingResource);
logger.error("Could not apply the VLAN membership of nic {} of VM
{}; its link was set down so it does not sit on the bridge's default VLAN. "
+ "The link is restored once the membership is applied;
otherwise correct it or restart the VM.", nic.getMac(), vmName);
- } catch (LibvirtException e) {
+ } catch (Exception e) {
logger.error("Could not apply the VLAN membership of nic {} of VM
{} and could not set its link down either, so it may still be on the bridge's
default VLAN: {}",
nic.getMac(), vmName, e.getMessage());
}
diff --git
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtReplugNicCommandWrapper.java
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtReplugNicCommandWrapper.java
index 06647d0960b..3830e5a4233 100644
---
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtReplugNicCommandWrapper.java
+++
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtReplugNicCommandWrapper.java
@@ -91,7 +91,7 @@ public final class LibvirtReplugNicCommandWrapper extends
CommandWrapper<ReplugN
newVifDriver.ensureVlanTrunkMembership(liveInterface, nic);
}
- interfaceDef.setLinkStateUp(true);
+ interfaceDef.setLinkStateUp(nic.isEnabled());
logger.debug("ReplugNic: Updating interface" + interfaceDef);
vm.updateDeviceFlags(interfaceDef.toString(),
DomainAffect.LIVE.getValue());
diff --git
a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtReplugNicCommandWrapperTest.java
b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtReplugNicCommandWrapperTest.java
index 470e6f8c33b..0022d8d4fa8 100644
---
a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtReplugNicCommandWrapperTest.java
+++
b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtReplugNicCommandWrapperTest.java
@@ -296,6 +296,7 @@ public class LibvirtReplugNicCommandWrapperTest {
nic.setName(GUEST_BR);
nic.setBroadcastType(Networks.BroadcastDomainType.Vlan);
nic.setMac("02:00:7c:98:00:02");
+ nic.setEnabled(true);
nic.setBroadcastUri(Networks.BroadcastDomainType.Vlan.toUri(100));
final ReplugNicCommand command = new ReplugNicCommand(nic,
"i-85-285-VM", VirtualMachine.Type.User);
final Answer result = wrapper.execute(command, res);
diff --git
a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/motion/LinstorDataMotionStrategy.java
b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/motion/LinstorDataMotionStrategy.java
index 35b1521f4d4..addf94ae4b5 100644
---
a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/motion/LinstorDataMotionStrategy.java
+++
b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/motion/LinstorDataMotionStrategy.java
@@ -34,6 +34,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import com.cloud.alert.PostMigrationAlerts;
+import com.cloud.alert.AlertManager;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.CheckVirtualMachineAnswer;
@@ -127,6 +129,8 @@ public class LinstorDataMotionStrategy implements
DataMotionStrategy {
@Inject
private NicDao nicDao;
@Inject
+ private AlertManager alertMgr;
+ @Inject
private PrimaryDataStoreDao _storagePoolDao;
@Override
@@ -560,7 +564,8 @@ public class LinstorDataMotionStrategy implements
DataMotionStrategy {
throw new CloudRuntimeException(errMsg);
}
-
VlanTrunkMigrationHelper.sendPostMigrationVlanTrunkMembershipIfNeeded(vmTO,
destHost.getId(), nicDao, hostDetailsDao, _agentManager::send, logger);
+ alertOnPostMigrationFailure(vmTO, destHost,
VlanTrunkMigrationHelper.sendPostMigrationVlanTrunkMembershipIfNeeded(
+ vmTO, destHost.getId(), nicDao, hostDetailsDao,
_agentManager::send, logger));
} catch (AgentUnavailableException | OperationTimedoutException |
CloudRuntimeException ex) {
errMsg = String.format(
"Copy volume(s) of VM [%s] to storage(s) [%s] and VM to
host [%s] failed in LinstorDataMotionStrategy.copyAsync. Error message: [%s].",
@@ -585,4 +590,10 @@ public class LinstorDataMotionStrategy implements
DataMotionStrategy {
callback.complete(result);
}
}
+
+ private void alertOnPostMigrationFailure(VirtualMachineTO vmTO, Host
destHost, String failure) {
+ if (failure != null) {
+ PostMigrationAlerts.sendFailureAlert(alertMgr, vmTO.getType(),
destHost.getDataCenterId(), destHost.getPodId(), vmTO.getName(),
destHost.getUuid(), failure);
+ }
+ }
}
diff --git
a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/motion/StorPoolDataMotionStrategy.java
b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/motion/StorPoolDataMotionStrategy.java
index 16b176844fa..d6301dcb07e 100644
---
a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/motion/StorPoolDataMotionStrategy.java
+++
b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/motion/StorPoolDataMotionStrategy.java
@@ -19,6 +19,8 @@
package org.apache.cloudstack.storage.motion;
+import com.cloud.alert.PostMigrationAlerts;
+import com.cloud.alert.AlertManager;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
@@ -128,6 +130,8 @@ public class StorPoolDataMotionStrategy implements
DataMotionStrategy {
@Inject
private NicDao nicDao;
@Inject
+ private AlertManager alertMgr;
+ @Inject
private SnapshotDetailsDao _snapshotDetailsDao;
@Inject
private VMTemplateDetailsDao _vmTemplateDetailsDao;
@@ -389,7 +393,8 @@ public class StorPoolDataMotionStrategy implements
DataMotionStrategy {
handlePostMigration(success, srcVolumeInfoToDestVolumeInfo, vmTO,
destHost);
if (success) {
-
VlanTrunkMigrationHelper.sendPostMigrationVlanTrunkMembershipIfNeeded(vmTO,
destHost.getId(), nicDao, hostDetailsDao, _agentManager::send, logger);
+ alertOnPostMigrationFailure(vmTO, destHost,
VlanTrunkMigrationHelper.sendPostMigrationVlanTrunkMembershipIfNeeded(
+ vmTO, destHost.getId(), nicDao, hostDetailsDao,
_agentManager::send, logger));
}
if (migrateAnswer == null) {
@@ -597,4 +602,10 @@ public class StorPoolDataMotionStrategy implements
DataMotionStrategy {
MigrateCommand.MigrateDiskInfo.DiskType.BLOCK,
MigrateCommand.MigrateDiskInfo.DriverType.RAW,
MigrateCommand.MigrateDiskInfo.Source.DEV, destPath);
}
+
+ private void alertOnPostMigrationFailure(VirtualMachineTO vmTO, Host
destHost, String failure) {
+ if (failure != null) {
+ PostMigrationAlerts.sendFailureAlert(alertMgr, vmTO.getType(),
destHost.getDataCenterId(), destHost.getPodId(), vmTO.getName(),
destHost.getUuid(), failure);
+ }
+ }
}
diff --git a/server/src/main/java/com/cloud/network/NetworkServiceImpl.java
b/server/src/main/java/com/cloud/network/NetworkServiceImpl.java
index ef87d9d6895..db5653384bb 100644
--- a/server/src/main/java/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/main/java/com/cloud/network/NetworkServiceImpl.java
@@ -1335,8 +1335,9 @@ public class NetworkServiceImpl extends ManagerBase
implements NetworkService, C
}
DetailVO vlanFilteringDetail =
_hostDetailsDao.findDetail(vm.getHostId(), Host.HOST_VLAN_FILTERING_ENABLED);
boolean vlanFilteringEnabled = vlanFilteringDetail != null &&
Boolean.parseBoolean(vlanFilteringDetail.getValue());
+ boolean sharedVlanBridgeEnabled =
NetworkOrchestrationService.MultiNetworkNicEnabled.valueIn(vm.getDataCenterId());
for (NicVO nic : _nicDao.listByVmId(vm.getId())) {
- if (VlanTrunkMigrationHelper.nicNeedsManualVlanMembership(nic,
vlanFilteringEnabled)) {
+ if (VlanTrunkMigrationHelper.nicNeedsManualVlanMembership(nic,
vlanFilteringEnabled, sharedVlanBridgeEnabled)) {
updateLiveVlanTrunkMembership(vm, nic);
}
}