use of com.cloud.legacymodel.communication.command.UpdateHostPasswordCommand in project cosmic by MissionCriticalCloud.
the class NotAValidCommand method testUpdateHostPasswordCommand.
@Test
public void testUpdateHostPasswordCommand() {
final XenServerUtilitiesHelper xenServerUtilitiesHelper = Mockito.mock(XenServerUtilitiesHelper.class);
final Pair<Boolean, String> result = Mockito.mock(Pair.class);
final UpdateHostPasswordCommand updatePwd = new UpdateHostPasswordCommand("test", "123", "127.0.0.1");
when(this.citrixResourceBase.getPwdFromQueue()).thenReturn("password");
final String hostIp = updatePwd.getHostIp();
final String username = updatePwd.getUsername();
final String hostPasswd = this.citrixResourceBase.getPwdFromQueue();
final String newPassword = updatePwd.getNewPassword();
final StringBuilder cmdLine = new StringBuilder();
cmdLine.append(XenServerUtilitiesHelper.SCRIPT_CMD_PATH).append(VRScripts.UPDATE_HOST_PASSWD).append(' ').append(username).append(' ').append(newPassword);
when(this.citrixResourceBase.getXenServerUtilitiesHelper()).thenReturn(xenServerUtilitiesHelper);
when(xenServerUtilitiesHelper.buildCommandLine(XenServerUtilitiesHelper.SCRIPT_CMD_PATH, VRScripts.UPDATE_HOST_PASSWD, username, newPassword)).thenReturn(cmdLine.toString());
try {
when(xenServerUtilitiesHelper.executeSshWrapper(hostIp, 22, username, null, hostPasswd, cmdLine.toString())).thenReturn(result);
when(result.first()).thenReturn(true);
when(result.second()).thenReturn("");
} catch (final Exception e) {
fail(e.getMessage());
}
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(updatePwd, this.citrixResourceBase);
verify(this.citrixResourceBase, times(2)).getPwdFromQueue();
verify(this.citrixResourceBase, times(1)).getXenServerUtilitiesHelper();
verify(xenServerUtilitiesHelper, times(1)).buildCommandLine(XenServerUtilitiesHelper.SCRIPT_CMD_PATH, VRScripts.UPDATE_HOST_PASSWD, username, newPassword);
try {
verify(xenServerUtilitiesHelper, times(1)).executeSshWrapper(hostIp, 22, username, null, hostPasswd, cmdLine.toString());
} catch (final Exception e) {
fail(e.getMessage());
}
verify(result, times(1)).first();
verify(result, times(1)).second();
assertTrue(answer.getResult());
}
use of com.cloud.legacymodel.communication.command.UpdateHostPasswordCommand in project cosmic by MissionCriticalCloud.
the class ResourceManagerImpl method doUpdateHostPassword.
private boolean doUpdateHostPassword(final long hostId) {
if (!this._agentMgr.isAgentAttached(hostId)) {
return false;
}
DetailVO nv = this._hostDetailsDao.findDetail(hostId, ApiConstants.USERNAME);
final String username = nv.getValue();
nv = this._hostDetailsDao.findDetail(hostId, ApiConstants.PASSWORD);
final String password = nv.getValue();
final HostVO host = this._hostDao.findById(hostId);
final String hostIpAddress = host.getPrivateIpAddress();
final UpdateHostPasswordCommand cmd = new UpdateHostPasswordCommand(username, password, hostIpAddress);
final Answer answer = this._agentMgr.easySend(hostId, cmd);
s_logger.info("Result returned from update host password ==> " + answer.getDetails());
return answer.getResult();
}
Aggregations