mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	server: remove registered userdata when cleanup an account (#7777)
This commit is contained in:
		
							parent
							
								
									fdb23dae40
								
							
						
					
					
						commit
						1605b2f0db
					
				| @ -25,4 +25,6 @@ public interface UserDataDao extends GenericDao<UserDataVO, Long> { | |||||||
| 
 | 
 | ||||||
|     public UserDataVO findByName(long accountId, long domainId, String name); |     public UserDataVO findByName(long accountId, long domainId, String name); | ||||||
| 
 | 
 | ||||||
|  |     int removeByAccountId(long accountId); | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -63,4 +63,11 @@ public class UserDataDaoImpl extends GenericDaoBase<UserDataVO, Long> implements | |||||||
| 
 | 
 | ||||||
|         return findOneBy(sc); |         return findOneBy(sc); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public int removeByAccountId(long accountId) { | ||||||
|  |         SearchCriteria<UserDataVO> sc = userdataSearch.create(); | ||||||
|  |         sc.setParameters("accountId", accountId); | ||||||
|  |         return remove(sc); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -162,6 +162,7 @@ import com.cloud.user.dao.AccountDao; | |||||||
| import com.cloud.user.dao.SSHKeyPairDao; | import com.cloud.user.dao.SSHKeyPairDao; | ||||||
| import com.cloud.user.dao.UserAccountDao; | import com.cloud.user.dao.UserAccountDao; | ||||||
| import com.cloud.user.dao.UserDao; | import com.cloud.user.dao.UserDao; | ||||||
|  | import com.cloud.user.dao.UserDataDao; | ||||||
| import com.cloud.utils.ConstantTimeComparator; | import com.cloud.utils.ConstantTimeComparator; | ||||||
| import com.cloud.utils.NumbersUtil; | import com.cloud.utils.NumbersUtil; | ||||||
| import com.cloud.utils.Pair; | import com.cloud.utils.Pair; | ||||||
| @ -292,6 +293,8 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M | |||||||
|     private GlobalLoadBalancerRuleDao _gslbRuleDao; |     private GlobalLoadBalancerRuleDao _gslbRuleDao; | ||||||
|     @Inject |     @Inject | ||||||
|     private SSHKeyPairDao _sshKeyPairDao; |     private SSHKeyPairDao _sshKeyPairDao; | ||||||
|  |     @Inject | ||||||
|  |     private UserDataDao userDataDao; | ||||||
| 
 | 
 | ||||||
|     private List<QuerySelector> _querySelectors; |     private List<QuerySelector> _querySelectors; | ||||||
| 
 | 
 | ||||||
| @ -1089,6 +1092,10 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M | |||||||
|             for (SSHKeyPairVO keypair : sshkeypairs) { |             for (SSHKeyPairVO keypair : sshkeypairs) { | ||||||
|                 _sshKeyPairDao.remove(keypair.getId()); |                 _sshKeyPairDao.remove(keypair.getId()); | ||||||
|             } |             } | ||||||
|  | 
 | ||||||
|  |             // Delete registered UserData | ||||||
|  |             userDataDao.removeByAccountId(accountId); | ||||||
|  | 
 | ||||||
|             return true; |             return true; | ||||||
|         } catch (Exception ex) { |         } catch (Exception ex) { | ||||||
|             s_logger.warn("Failed to cleanup account " + account + " due to ", ex); |             s_logger.warn("Failed to cleanup account " + account + " due to ", ex); | ||||||
|  | |||||||
| @ -164,6 +164,7 @@ public class AccountManagerImplTest extends AccountManagetImplTestBase { | |||||||
|         sshkeyList.add(sshkey); |         sshkeyList.add(sshkey); | ||||||
|         Mockito.when(_sshKeyPairDao.listKeyPairs(Mockito.anyLong(), Mockito.anyLong())).thenReturn(sshkeyList); |         Mockito.when(_sshKeyPairDao.listKeyPairs(Mockito.anyLong(), Mockito.anyLong())).thenReturn(sshkeyList); | ||||||
|         Mockito.when(_sshKeyPairDao.remove(Mockito.anyLong())).thenReturn(true); |         Mockito.when(_sshKeyPairDao.remove(Mockito.anyLong())).thenReturn(true); | ||||||
|  |         Mockito.when(userDataDao.removeByAccountId(Mockito.anyLong())).thenReturn(222); | ||||||
| 
 | 
 | ||||||
|         Assert.assertTrue(accountManagerImpl.deleteUserAccount(42l)); |         Assert.assertTrue(accountManagerImpl.deleteUserAccount(42l)); | ||||||
|         // assert that this was a clean delete |         // assert that this was a clean delete | ||||||
|  | |||||||
| @ -73,6 +73,7 @@ import com.cloud.user.dao.AccountDao; | |||||||
| import com.cloud.user.dao.SSHKeyPairDao; | import com.cloud.user.dao.SSHKeyPairDao; | ||||||
| import com.cloud.user.dao.UserAccountDao; | import com.cloud.user.dao.UserAccountDao; | ||||||
| import com.cloud.user.dao.UserDao; | import com.cloud.user.dao.UserDao; | ||||||
|  | import com.cloud.user.dao.UserDataDao; | ||||||
| import com.cloud.vm.VirtualMachineManager; | import com.cloud.vm.VirtualMachineManager; | ||||||
| import com.cloud.vm.dao.DomainRouterDao; | import com.cloud.vm.dao.DomainRouterDao; | ||||||
| import com.cloud.vm.dao.InstanceGroupDao; | import com.cloud.vm.dao.InstanceGroupDao; | ||||||
| @ -193,6 +194,8 @@ public class AccountManagetImplTestBase { | |||||||
|     OrchestrationService _orchSrvc; |     OrchestrationService _orchSrvc; | ||||||
|     @Mock |     @Mock | ||||||
|     SSHKeyPairDao _sshKeyPairDao; |     SSHKeyPairDao _sshKeyPairDao; | ||||||
|  |     @Mock | ||||||
|  |     UserDataDao userDataDao; | ||||||
| 
 | 
 | ||||||
|     @Spy |     @Spy | ||||||
|     @InjectMocks |     @InjectMocks | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user