|
45 | 45 | import com.trilead.ssh2.Connection; |
46 | 46 | import org.apache.cloudstack.api.command.admin.host.CancelHostAsDegradedCmd; |
47 | 47 | import org.apache.cloudstack.api.command.admin.host.DeclareHostAsDegradedCmd; |
| 48 | +import org.apache.cloudstack.framework.config.ConfigKey; |
48 | 49 | import org.apache.cloudstack.framework.config.dao.ConfigurationDao; |
49 | 50 | import org.junit.After; |
50 | 51 | import org.junit.Assert; |
|
61 | 62 | import org.mockito.Spy; |
62 | 63 | import org.mockito.junit.MockitoJUnitRunner; |
63 | 64 |
|
| 65 | +import java.lang.reflect.Field; |
64 | 66 | import java.util.ArrayList; |
65 | 67 | import java.util.Arrays; |
66 | 68 | import java.util.Collections; |
@@ -152,6 +154,12 @@ public class ResourceManagerImplTest { |
152 | 154 | private MockedConstruction<GetVncPortCommand> getVncPortCommandMockedConstruction; |
153 | 155 | private AutoCloseable closeable; |
154 | 156 |
|
| 157 | + private void overrideDefaultConfigValue(final ConfigKey configKey, final String name, final Object o) throws IllegalAccessException, NoSuchFieldException { |
| 158 | + Field f = ConfigKey.class.getDeclaredField(name); |
| 159 | + f.setAccessible(true); |
| 160 | + f.set(configKey, o); |
| 161 | + } |
| 162 | + |
155 | 163 | @Before |
156 | 164 | public void setup() throws Exception { |
157 | 165 | closeable = MockitoAnnotations.openMocks(this); |
@@ -194,7 +202,7 @@ public void setup() throws Exception { |
194 | 202 | eq("service cloudstack-agent restart"))). |
195 | 203 | willReturn(new SSHCmdHelper.SSHCmdResult(0,"","")); |
196 | 204 |
|
197 | | - when(configurationDao.getValue(ResourceManager.KvmSshToAgentEnabled.key())).thenReturn("true"); |
| 205 | + overrideDefaultConfigValue(ResourceManager.KvmSshToAgentEnabled, "_defaultValue", "true"); |
198 | 206 |
|
199 | 207 | rootDisks = Arrays.asList(rootDisk1, rootDisk2); |
200 | 208 | dataDisks = Collections.singletonList(dataDisk); |
@@ -372,9 +380,9 @@ public void testHandleAgentSSHEnabledConnectedAgent() { |
372 | 380 | } |
373 | 381 |
|
374 | 382 | @Test(expected = CloudRuntimeException.class) |
375 | | - public void testHandleAgentSSHDisabledNotConnectedAgent() { |
| 383 | + public void testHandleAgentSSHDisabledNotConnectedAgent() throws NoSuchFieldException, IllegalAccessException { |
376 | 384 | when(host.getStatus()).thenReturn(Status.Disconnected); |
377 | | - when(configurationDao.getValue(ResourceManager.KvmSshToAgentEnabled.key())).thenReturn("false"); |
| 385 | + overrideDefaultConfigValue(ResourceManager.KvmSshToAgentEnabled, "_defaultValue", "false"); |
378 | 386 | resourceManager.handleAgentIfNotConnected(host, false); |
379 | 387 | } |
380 | 388 |
|
|
0 commit comments