diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostSetupNetworksCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostSetupNetworksCommand.java index 32c85d55970..6832be2a1d1 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostSetupNetworksCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostSetupNetworksCommand.java @@ -340,28 +340,37 @@ protected void executeCommand() { try (EngineLock monitoringLock = acquireMonitorLock("Host setup networks")) { int timeout = getSetupNetworksTimeout(); - FutureVDSCall setupNetworksTask = invokeSetupNetworksCommand(timeout); try { - VDSReturnValue retVal = setupNetworksTask.get(timeout, TimeUnit.SECONDS); - if (retVal != null) { - if (!retVal.getSucceeded() && retVal.getVdsError() == null && getParameters().rollbackOnFailure()) { - throw new EngineException(EngineError.SETUP_NETWORKS_ROLLBACK, retVal.getExceptionString()); - } + boolean succeeded = true; - VdsHandler.handleVdsResult(retVal); + if (hasNetworkChanges()) { + succeeded = false; + // Update networks configuration on the host + FutureVDSCall setupNetworksTask = invokeSetupNetworksCommand(timeout); + VDSReturnValue retVal = setupNetworksTask.get(timeout, TimeUnit.SECONDS); + if (retVal != null) { + if (!retVal.getSucceeded() && retVal.getVdsError() == null && getParameters().rollbackOnFailure()) { + throw new EngineException(EngineError.SETUP_NETWORKS_ROLLBACK, retVal.getExceptionString()); + } - if (retVal.getSucceeded()) { + VdsHandler.handleVdsResult(retVal); - VDSReturnValue returnValue = - runVdsCommand(VDSCommandType.GetCapabilities, - new VdsIdAndVdsVDSCommandParametersBase(getVds())); - VDS updatedHost = (VDS) returnValue.getReturnValue(); - persistNetworkChanges(updatedHost); + succeeded = retVal.getSucceeded(); } + } - setSucceeded(true); + if (succeeded) { + // If host networks were updated successfully (or there were no host network changes, just changes + // in labels) then update networks configuration in the engine DB. + VDSReturnValue returnValue = + runVdsCommand(VDSCommandType.GetCapabilities, + new VdsIdAndVdsVDSCommandParametersBase(getVds())); + VDS updatedHost = (VDS) returnValue.getReturnValue(); + persistNetworkChanges(updatedHost); } + + setSucceeded(succeeded); } catch (TimeoutException e) { log.debug("Host Setup networks command timed out for {} seconds", timeout); } @@ -537,6 +546,10 @@ private boolean noChangesDetected() { return getParameters().isEmptyRequest(); } + private boolean hasNetworkChanges() { + return getParameters().hasNetworkChanges(); + } + private List getRemovedBonds() { if (removedBonds == null) { Set removedBondIds = getParameters().getRemovedBonds(); diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/HostSetupNetworksParameters.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/HostSetupNetworksParameters.java index bd46e9fe6e3..6f479d03df7 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/HostSetupNetworksParameters.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/HostSetupNetworksParameters.java @@ -84,6 +84,14 @@ public boolean isEmptyRequest() { removedLabels.isEmpty(); } + public boolean hasNetworkChanges() { + return !networkAttachments.isEmpty() || + !removedNetworkAttachments.isEmpty() || + !createOrUpdateBonds.isEmpty() || + !removedBonds.isEmpty() || + !removedUnmanagedNetworks.isEmpty(); + } + public boolean rollbackOnFailure() { return rollbackOnFailure; }