Skip to content

Commit

Permalink
Fix unexpected exception on assigning labels on host networks
Browse files Browse the repository at this point in the history
Signed-off-by: Stepan Ermakov <sermakov@orionsoft.ru>
  • Loading branch information
sermakov-orion committed Nov 21, 2023
1 parent d48b5f1 commit 37c9ba4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,26 +340,43 @@ 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 networksUpdated = false;
boolean succeeded = false;

if (hasNetworkChanges()) {
//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());
}

VdsHandler.handleVdsResult(retVal);

networksUpdated = retVal.getSucceeded();
succeeded = true;
}
} else {
//We have just changes in labels that should not be reflected on the host itself. So nothing to do
//on the host.
networksUpdated = true;
succeeded = true;
}

VdsHandler.handleVdsResult(retVal);

if (retVal.getSucceeded()) {

VDSReturnValue returnValue =
runVdsCommand(VDSCommandType.GetCapabilities,
new VdsIdAndVdsVDSCommandParametersBase(getVds()));
VDS updatedHost = (VDS) returnValue.getReturnValue();
persistNetworkChanges(updatedHost);
}
if (networksUpdated) {
//If host networks were updated successfully then update networks configuration (including changes
//in labels) in the engine DB.
VDSReturnValue returnValue =
runVdsCommand(VDSCommandType.GetCapabilities,
new VdsIdAndVdsVDSCommandParametersBase(getVds()));
VDS updatedHost = (VDS) returnValue.getReturnValue();
persistNetworkChanges(updatedHost);
}

if (succeeded) {
setSucceeded(true);
}
} catch (TimeoutException e) {
Expand Down Expand Up @@ -537,6 +554,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

0 comments on commit 37c9ba4

Please sign in to comment.