|
22 | 22 | import com.cloud.agent.api.StartupCommand; |
23 | 23 | import com.cloud.agent.api.StartupRoutingCommand; |
24 | 24 | import com.cloud.exception.ConnectionException; |
| 25 | +import com.cloud.host.Host; |
25 | 26 | import com.cloud.host.HostVO; |
26 | 27 | import com.cloud.host.Status; |
27 | 28 | import com.cloud.host.dao.HostDao; |
@@ -104,4 +105,36 @@ public void testGetTimeoutWithGranularTimeout() { |
104 | 105 |
|
105 | 106 | Assert.assertEquals(50, result); |
106 | 107 | } |
| 108 | + |
| 109 | + @Test |
| 110 | + public void testGetHostSshPortWithHostNull() { |
| 111 | + int hostSshPort = mgr.getHostSshPort(null); |
| 112 | + Assert.assertEquals(22, hostSshPort); |
| 113 | + } |
| 114 | + |
| 115 | + @Test |
| 116 | + public void testGetHostSshPortWithNonKVMHost() { |
| 117 | + HostVO host = Mockito.mock(HostVO.class); |
| 118 | + Mockito.when(host.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.XenServer); |
| 119 | + int hostSshPort = mgr.getHostSshPort(host); |
| 120 | + Assert.assertEquals(22, hostSshPort); |
| 121 | + } |
| 122 | + |
| 123 | + @Test |
| 124 | + public void testGetHostSshPortWithKVMHostDefaultPort() { |
| 125 | + HostVO host = Mockito.mock(HostVO.class); |
| 126 | + Mockito.when(host.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM); |
| 127 | + Mockito.when(host.getClusterId()).thenReturn(1L); |
| 128 | + int hostSshPort = mgr.getHostSshPort(host); |
| 129 | + Assert.assertEquals(22, hostSshPort); |
| 130 | + } |
| 131 | + |
| 132 | + @Test |
| 133 | + public void testGetHostSshPortWithKVMHostCustomPort() { |
| 134 | + HostVO host = Mockito.mock(HostVO.class); |
| 135 | + Mockito.when(host.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM); |
| 136 | + Mockito.when(host.getDetail(Host.HOST_SSH_PORT)).thenReturn(String.valueOf(3922)); |
| 137 | + int hostSshPort = mgr.getHostSshPort(host); |
| 138 | + Assert.assertEquals(3922, hostSshPort); |
| 139 | + } |
107 | 140 | } |
0 commit comments