Skip to content

Commit 262a982

Browse files
author
Daan Hoogland
committed
clear operational reservations on delete account
1 parent c151ad5 commit 262a982

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

engine/schema/src/main/java/com/cloud/dc/dao/DataCenterVnetDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public interface DataCenterVnetDao extends GenericDao<DataCenterVnetVO, Long> {
4545

4646
public void release(String vnet, long physicalNetworkId, long accountId, String reservationId);
4747

48+
public void releaseForAccount(long accountId);
49+
4850
public void releaseDedicatedGuestVlans(Long dedicatedGuestVlanRangeId);
4951

5052
public int countVnetsAllocatedToAccount(long dcId, long accountId);

engine/schema/src/main/java/com/cloud/dc/dao/DataCenterVnetDaoImpl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,18 @@ public void release(String vnet, long physicalNetworkId, long accountId, String
237237
update(vo.getId(), vo);
238238
}
239239

240+
@Override
241+
public void releaseForAccount(long accountId) {
242+
SearchCriteria<DataCenterVnetVO> sc = VnetDcSearchAllocated.create();
243+
sc.setParameters("account", accountId);
244+
245+
DataCenterVnetVO vo = findOneIncludingRemovedBy(sc);
246+
vo.setTakenAt(null);
247+
vo.setAccountId(null);
248+
vo.setReservationId(null);
249+
update(vo.getId(), vo);
250+
}
251+
240252
@Override
241253
public void releaseDedicatedGuestVlans(Long dedicatedGuestVlanRangeId) {
242254
SearchCriteria<DataCenterVnetVO> sc = DedicatedGuestVlanRangeSearch.create();

server/src/main/java/com/cloud/user/AccountManagerImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,11 @@ public int compare(NetworkVO network1, NetworkVO network2) {
11201120
accountCleanupNeeded = true;
11211121
}
11221122
}
1123+
// this is clearing the operational reservations or vlans for the account
1124+
// this should have happened before and covours up the release issues for the vlans
1125+
// but as it is purely operational and no business logic is involved we clean now
1126+
// as a last resort, to prevent allocation issue on the long run.
1127+
_dataCenterVnetDao.releaseForAccount(accountId);
11231128
}
11241129

11251130
// Delete Site 2 Site VPN customer gateway

test/integration/smoke/test_migration.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,14 @@ def test_01_native_to_native_network_migration(self):
194194
self.cleanup.append(isolated_network)
195195

196196
self.migrate_network(
197-
self.network_offering_nouserdata,
198-
isolated_network, resume=False)
197+
self.network_offering_nouserdata,
198+
isolated_network,
199+
resume=False)
199200

200201
self.migrate_network(
201-
self.network_offering_all,
202-
isolated_network, resume=False)
202+
self.network_offering_all,
203+
isolated_network,
204+
resume=False)
203205

204206
deployVmResponse = VirtualMachine.create(
205207
self.apiclient,
@@ -209,16 +211,14 @@ def test_01_native_to_native_network_migration(self):
209211
serviceofferingid=self.service_offering.id,
210212
networkids=[str(isolated_network.id)],
211213
templateid=self.template.id,
212-
zoneid=self.zone.id
213-
)
214+
zoneid=self.zone.id)
214215
self.cleanup.append(deployVmResponse)
215216

216217
vms = list_virtual_machines(
217218
self.apiclient,
218219
account=self.account.name,
219220
domainid=self.account.domainid,
220-
id=deployVmResponse.id
221-
)
221+
id=deployVmResponse.id)
222222
self.assertTrue(len(vms) > 0, "There are no Vms deployed in the account"
223223
" %s" % self.account.name)
224224
vm = vms[0]
@@ -227,12 +227,14 @@ def test_01_native_to_native_network_migration(self):
227227
self.assertTrue(vm.state == "Running", "VM is not in Running state")
228228

229229
self.migrate_network(
230-
self.network_offering_nouserdata,
231-
isolated_network, resume=False)
230+
self.network_offering_nouserdata,
231+
isolated_network,
232+
resume=False)
232233

233234
self.migrate_network(
234-
self.network_offering_all,
235-
isolated_network, resume=False)
235+
self.network_offering_all,
236+
isolated_network,
237+
resume=False)
236238

237239
@skipTestIf("hypervisorNotSupported")
238240
@attr(tags=["advanced", "smoke", "nativevpconly"],

0 commit comments

Comments
 (0)