Skip to content

Commit 7332e6d

Browse files
authored
[NSX] Fix DHCP relay config deletion was missing zone name (#8068)
1 parent 5ec4552 commit 7332e6d

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/DeleteNsxSegmentCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import com.cloud.network.dao.NetworkVO;
2020

2121
public class DeleteNsxSegmentCommand extends CreateNsxSegmentCommand {
22-
public DeleteNsxSegmentCommand(String accountName, String vpcName, NetworkVO network) {
23-
super(null, network.getDataCenterId(), accountName, network.getAccountId(), vpcName, network);
22+
public DeleteNsxSegmentCommand(String zoneName, String accountName, String vpcName, NetworkVO network) {
23+
super(zoneName, network.getDataCenterId(), accountName, network.getAccountId(), vpcName, network);
2424
}
2525
}

plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/resource/NsxResource.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,12 @@ private NsxAnswer executeRequest(DeleteNsxSegmentCommand cmd) {
417417
Thread.sleep(30*1000);
418418
String segmentName = getSegmentName(cmd.getAccountName(), cmd.getTierNetwork().getName(), cmd.getVpcName());
419419
Segments segmentService = (Segments) nsxService.apply(Segments.class);
420+
LOGGER.debug(String.format("Removing the segment with ID %s", segmentName));
420421
segmentService.delete(segmentName);
421422
DhcpRelayConfigs dhcpRelayConfig = (DhcpRelayConfigs) nsxService.apply(DhcpRelayConfigs.class);
422-
dhcpRelayConfig.delete(getDhcpRelayId(cmd.getZoneName(), cmd.getAccountName(), cmd.getVpcName(), cmd.getTierNetwork().getName()));
423+
String dhcpRelayId = getDhcpRelayId(cmd.getZoneName(), cmd.getAccountName(), cmd.getVpcName(), cmd.getTierNetwork().getName());
424+
LOGGER.debug(String.format("Removing the DHCP relay config with ID %s", dhcpRelayId));
425+
dhcpRelayConfig.delete(dhcpRelayId);
423426
} catch (Exception e) {
424427
LOGGER.error(String.format("Failed to delete NSX segment: %s", getSegmentName(cmd.getAccountName(), cmd.getTierNetwork().getName(), cmd.getVpcName())));
425428
return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage()));

plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxElement.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import com.cloud.user.AccountManager;
6060
import com.cloud.utils.Pair;
6161
import com.cloud.utils.component.AdapterBase;
62+
import com.cloud.utils.exception.CloudRuntimeException;
6263
import com.cloud.vm.NicProfile;
6364
import com.cloud.vm.ReservationContext;
6465
import com.cloud.vm.VirtualMachineProfile;
@@ -195,7 +196,13 @@ public boolean shutdown(Network network, ReservationContext context, boolean cle
195196
public boolean destroy(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
196197
Account account = accountMgr.getAccount(network.getAccountId());
197198
NetworkVO networkVO = networkDao.findById(network.getId());
198-
return nsxService.deleteNetwork(account.getAccountName(), networkVO);
199+
DataCenterVO zone = dataCenterDao.findById(network.getDataCenterId());
200+
if (Objects.isNull(zone)) {
201+
String msg = String.format("Cannot fing zone with ID %s", network.getDataCenterId());
202+
LOGGER.error(msg);
203+
throw new CloudRuntimeException(msg);
204+
}
205+
return nsxService.deleteNetwork(zone.getName(), account.getAccountName(), networkVO);
199206
}
200207

201208
@Override

plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ public boolean deleteVpcNetwork(Long zoneId, String zoneName, Long accountId, St
4747
return result.getResult();
4848
}
4949

50-
public boolean deleteNetwork(String accountName, NetworkVO network) {
50+
public boolean deleteNetwork(String zoneName, String accountName, NetworkVO network) {
5151
String vpcName = null;
5252
if (Objects.nonNull(network.getVpcId())) {
5353
VpcVO vpc = vpcDao.findById(network.getVpcId());
5454
vpcName = Objects.nonNull(vpc) ? vpc.getName() : null;
5555
}
56-
DeleteNsxSegmentCommand deleteNsxSegmentCommand = new DeleteNsxSegmentCommand(accountName, vpcName, network);
56+
DeleteNsxSegmentCommand deleteNsxSegmentCommand = new DeleteNsxSegmentCommand(zoneName, accountName, vpcName, network);
5757
NsxAnswer result = nsxControllerUtils.sendNsxCommand(deleteNsxSegmentCommand, network.getDataCenterId());
5858
return result.getResult();
5959
}

0 commit comments

Comments
 (0)