Skip to content

Commit 948014d

Browse files
committed
CLOUDSTACK-4566: fix incorrect values in resource_count table for resource limitation
There are three issues in resource_count table (1) expunge a vm, the public_ip decreases and becomes -1 in basic zone. (2) recover a vm, the volume increase. (3) restore a vm, the volume decrease.
1 parent 1ba5915 commit 948014d

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

‎server/src/com/cloud/network/NetworkManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ public PublicIp fetchNewPublicIp(long dcId, Long podId, List<Long> vlanDbIds, Ac
508508
}
509509
addr.setState(assign ? IpAddress.State.Allocated : IpAddress.State.Allocating);
510510

511-
if (vlanUse != VlanType.DirectAttached || zone.getNetworkType() == NetworkType.Basic) {
511+
if (vlanUse != VlanType.DirectAttached) {
512512
addr.setAssociatedWithNetworkId(guestNetworkId);
513513
addr.setVpcId(vpcId);
514514
}

‎server/src/com/cloud/vm/UserVmManagerImpl.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,8 +1479,6 @@ public UserVm recoverVirtualMachine(RecoverVMCmd cmd)
14791479
}
14801480

14811481
//Update Resource Count for the given account
1482-
_resourceLimitMgr.incrementResourceCount(account.getId(),
1483-
ResourceType.volume, new Long(volumes.size()));
14841482
resourceCountIncrement(account.getId(), new Long(serviceOffering.getCpu()),
14851483
new Long(serviceOffering.getRamSize()));
14861484
txn.commit();
@@ -4878,6 +4876,10 @@ public UserVm restoreVMInternal(Account caller, UserVmVO vm, Long newTemplateId)
48784876
} else {
48794877
newVol = volumeMgr.allocateDuplicateVolume(root, null);
48804878
}
4879+
// Save usage event and update resource count for user vm volumes
4880+
if (vm instanceof UserVm) {
4881+
_resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.volume);
4882+
}
48814883

48824884
_volsDao.attachVolume(newVol.getId(), vmId, newVol.getDeviceId());
48834885

‎server/test/com/cloud/vm/UserVmManagerTest.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import com.cloud.user.AccountManager;
6969
import com.cloud.user.AccountService;
7070
import com.cloud.user.AccountVO;
71+
import com.cloud.user.ResourceLimitService;
7172
import com.cloud.user.UserContext;
7273
import com.cloud.user.UserVO;
7374
import com.cloud.user.dao.AccountDao;
@@ -104,6 +105,8 @@ public class UserVmManagerTest {
104105
@Mock List<VolumeVO> _rootVols;
105106
@Mock Account _accountMock2;
106107
@Mock ServiceOfferingDao _offeringDao;
108+
@Mock ResourceLimitService _resourceLimitMgr;
109+
107110
@Before
108111
public void setup(){
109112
MockitoAnnotations.initMocks(this);
@@ -121,6 +124,7 @@ public void setup(){
121124
_userVmMgr._configMgr = _configMgr;
122125
_userVmMgr._offeringDao= _offeringDao;
123126
_userVmMgr._capacityMgr = _capacityMgr;
127+
_userVmMgr._resourceLimitMgr = _resourceLimitMgr;
124128
_userVmMgr._scaleRetry = 2;
125129

126130
doReturn(3L).when(_account).getId();
@@ -488,4 +492,4 @@ public void testMoveVmToUser2() throws Exception {
488492
_userVmMgr.moveVMToUser(cmd);
489493
}
490494

491-
}
495+
}

0 commit comments

Comments
 (0)