ConfigurationServerImpl extends ManagerBase implements ConfigurationServer { @DB protected void updateSystemvmPassword() { String userid = System.getProperty("user.name"); if (!userid.startsWith("cloud")) { return; } if (!Boolean.valueOf(_configDao.getValue("system.vm.random.password"))) { return; } String already = _configDao.getValue("system.vm.password"); if (already == null) { TransactionLegacy txn = TransactionLegacy.currentTxn(); try { String rpassword = _mgrService.generateRandomPassword(); String wSql = "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " + "VALUES ('Secure','DEFAULT', 'management-server','system.vm.password', ?,'randmon password generated each management server starts for system vm')"; PreparedStatement stmt = txn.prepareAutoCloseStatement(wSql); stmt.setString(1, DBEncryptionUtil.encrypt(rpassword)); stmt.executeUpdate(); s_logger.info("Updated systemvm password in database"); } catch (SQLException e) { s_logger.error("Cannot retrieve systemvm password", e); } } } ConfigurationServerImpl(); @Override boolean configure(String name, Map<String, Object> params); @Override void persistDefaultValues(); @DB void saveUser(); @Override @DB void updateKeyPairs(); @Override List<ConfigurationVO> getConfigListByScope(String scope, Long resourceId); @DB void updateResourceCount(); Map<String, String> getServicesAndProvidersForNetwork(long networkOfferingId); static final Logger s_logger; }
@Test public void testUpdateSystemvmPassword() { String realusername = System.getProperty("user.name"); System.setProperty("user.name", "cloud"); Mockito.when(_configDao.getValue("system.vm.random.password")).thenReturn(String.valueOf(true)); TransactionLegacy.open("cloud"); Mockito.when(_mgrService.generateRandomPassword()).thenReturn("randomPassword"); configurationServer.updateSystemvmPassword(); Mockito.verify(_mgrService, Mockito.times(1)).generateRandomPassword(); System.setProperty("user.name", realusername); }