Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unexpected exception on assigning labels on host networks #892

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -340,28 +340,37 @@ protected void executeCommand() {

try (EngineLock monitoringLock = acquireMonitorLock("Host setup networks")) {
int timeout = getSetupNetworksTimeout();
FutureVDSCall<VDSReturnValue> 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<VDSReturnValue> 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);
}
Expand Down Expand Up @@ -537,6 +546,10 @@ private boolean noChangesDetected() {
return getParameters().isEmptyRequest();
}

private boolean hasNetworkChanges() {
return getParameters().hasNetworkChanges();
}

private List<VdsNetworkInterface> getRemovedBonds() {
if (removedBonds == null) {
Set<Guid> removedBondIds = getParameters().getRemovedBonds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down