mirror of https://github.com/apache/cloudstack.git
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.
This commit is contained in:
parent
1ba5915169
commit
948014dee6
|
|
@ -508,7 +508,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
|
|||
}
|
||||
addr.setState(assign ? IpAddress.State.Allocated : IpAddress.State.Allocating);
|
||||
|
||||
if (vlanUse != VlanType.DirectAttached || zone.getNetworkType() == NetworkType.Basic) {
|
||||
if (vlanUse != VlanType.DirectAttached) {
|
||||
addr.setAssociatedWithNetworkId(guestNetworkId);
|
||||
addr.setVpcId(vpcId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1479,8 +1479,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
|
|||
}
|
||||
|
||||
//Update Resource Count for the given account
|
||||
_resourceLimitMgr.incrementResourceCount(account.getId(),
|
||||
ResourceType.volume, new Long(volumes.size()));
|
||||
resourceCountIncrement(account.getId(), new Long(serviceOffering.getCpu()),
|
||||
new Long(serviceOffering.getRamSize()));
|
||||
txn.commit();
|
||||
|
|
@ -4878,6 +4876,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
|
|||
} else {
|
||||
newVol = volumeMgr.allocateDuplicateVolume(root, null);
|
||||
}
|
||||
// Save usage event and update resource count for user vm volumes
|
||||
if (vm instanceof UserVm) {
|
||||
_resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.volume);
|
||||
}
|
||||
|
||||
_volsDao.attachVolume(newVol.getId(), vmId, newVol.getDeviceId());
|
||||
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ import com.cloud.user.Account;
|
|||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.AccountService;
|
||||
import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.ResourceLimitService;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.user.UserVO;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
|
|
@ -104,6 +105,8 @@ public class UserVmManagerTest {
|
|||
@Mock List<VolumeVO> _rootVols;
|
||||
@Mock Account _accountMock2;
|
||||
@Mock ServiceOfferingDao _offeringDao;
|
||||
@Mock ResourceLimitService _resourceLimitMgr;
|
||||
|
||||
@Before
|
||||
public void setup(){
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
|
@ -121,6 +124,7 @@ public class UserVmManagerTest {
|
|||
_userVmMgr._configMgr = _configMgr;
|
||||
_userVmMgr._offeringDao= _offeringDao;
|
||||
_userVmMgr._capacityMgr = _capacityMgr;
|
||||
_userVmMgr._resourceLimitMgr = _resourceLimitMgr;
|
||||
_userVmMgr._scaleRetry = 2;
|
||||
|
||||
doReturn(3L).when(_account).getId();
|
||||
|
|
@ -488,4 +492,4 @@ public class UserVmManagerTest {
|
|||
_userVmMgr.moveVMToUser(cmd);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue