use of com.cloud.agent.api.UpdateHostPasswordCommand in project cloudstack by apache.
the class NotAValidCommand method testUpdateHostPasswordCommandException.
@Test
public void testUpdateHostPasswordCommandException() {
final XenServerUtilitiesHelper xenServerUtilitiesHelper = Mockito.mock(XenServerUtilitiesHelper.class);
final UpdateHostPasswordCommand updatePwd = new UpdateHostPasswordCommand("test", "123", "127.0.0.1");
when(citrixResourceBase.getPwdFromQueue()).thenReturn("password");
final String hostIp = updatePwd.getHostIp();
final String username = updatePwd.getUsername();
final String hostPasswd = 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(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())).thenThrow(new Exception("testing failure"));
} catch (final Exception e) {
fail(e.getMessage());
}
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(updatePwd, citrixResourceBase);
verify(citrixResourceBase, times(2)).getPwdFromQueue();
verify(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());
}
assertFalse(answer.getResult());
}
use of com.cloud.agent.api.UpdateHostPasswordCommand in project cloudstack by apache.
the class NotAValidCommand method testUpdateHostPasswordCommandFail.
@SuppressWarnings("unchecked")
@Test
public void testUpdateHostPasswordCommandFail() {
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(citrixResourceBase.getPwdFromQueue()).thenReturn("password");
final String hostIp = updatePwd.getHostIp();
final String username = updatePwd.getUsername();
final String hostPasswd = 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(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(false);
when(result.second()).thenReturn("");
} catch (final Exception e) {
fail(e.getMessage());
}
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(updatePwd, citrixResourceBase);
verify(citrixResourceBase, times(2)).getPwdFromQueue();
verify(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();
assertFalse(answer.getResult());
}
use of com.cloud.agent.api.UpdateHostPasswordCommand in project cloudstack by apache.
the class LibvirtComputingResourceTest method testUpdateHostPasswordCommandFail.
@Test
public void testUpdateHostPasswordCommandFail() {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Script script = Mockito.mock(Script.class);
final String hostIp = "127.0.0.1";
final String username = "root";
final String newPassword = "password";
final UpdateHostPasswordCommand command = new UpdateHostPasswordCommand(username, newPassword, hostIp);
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtComputingResource.getUpdateHostPasswdPath()).thenReturn("/tmp");
when(libvirtUtilitiesHelper.buildScript(libvirtComputingResource.getUpdateHostPasswdPath())).thenReturn(script);
when(script.execute()).thenReturn("#FAIL");
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertFalse(answer.getResult());
}
use of com.cloud.agent.api.UpdateHostPasswordCommand in project cloudstack by apache.
the class LibvirtComputingResourceTest method testUpdateHostPasswordCommand.
@Test
public void testUpdateHostPasswordCommand() {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Script script = Mockito.mock(Script.class);
final String hostIp = "127.0.0.1";
final String username = "root";
final String newPassword = "password";
final UpdateHostPasswordCommand command = new UpdateHostPasswordCommand(username, newPassword, hostIp);
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtComputingResource.getUpdateHostPasswdPath()).thenReturn("/tmp");
when(libvirtUtilitiesHelper.buildScript(libvirtComputingResource.getUpdateHostPasswdPath())).thenReturn(script);
when(script.execute()).thenReturn(null);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertTrue(answer.getResult());
}
Aggregations