Skip to content

Commit 614b3f2

Browse files
committed
Fix KvmSshToAgentEnabled setting description and make it dynamic
1 parent 5aced73 commit 614b3f2

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

engine/components-api/src/main/java/com/cloud/resource/ResourceManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public interface ResourceManager extends ResourceService, Configurable {
5757

5858
ConfigKey<Boolean> KvmSshToAgentEnabled = new ConfigKey<>("Advanced", Boolean.class,
5959
"kvm.ssh.to.agent","true",
60-
"Number of retries when preparing a host into Maintenance Mode is faulty before failing",
61-
false);
60+
"True if the management server will restart the agent service via SSH into the KVM hosts after or during maintenance operations",
61+
true);
6262

6363
ConfigKey<String> HOST_MAINTENANCE_LOCAL_STRATEGY = new ConfigKey<>(String.class,
6464
"host.maintenance.local.storage.strategy", "Advanced","Error",

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3833,8 +3833,7 @@ protected void handleAgentIfNotConnected(HostVO host, boolean vmsMigrating) {
38333833
if (!isAgentOnHost || vmsMigrating || host.getStatus() == Status.Up) {
38343834
return;
38353835
}
3836-
final boolean sshToAgent = Boolean.parseBoolean(_configDao.getValue(KvmSshToAgentEnabled.key()));
3837-
if (sshToAgent) {
3836+
if (KvmSshToAgentEnabled.value()) {
38383837
Ternary<String, String, String> credentials = getHostCredentials(host);
38393838
connectAndRestartAgentOnHost(host, credentials.first(), credentials.second(), credentials.third());
38403839
} else {

server/src/test/java/com/cloud/resource/ResourceManagerImplTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.cloud.agent.api.GetVncPortAnswer;
2222
import com.cloud.agent.api.GetVncPortCommand;
2323
import com.cloud.capacity.dao.CapacityDao;
24+
import com.cloud.configuration.ConfigurationManagerImpl;
2425
import com.cloud.dc.ClusterVO;
2526
import com.cloud.dc.DataCenterVO;
2627
import com.cloud.dc.HostPodVO;
@@ -57,6 +58,7 @@
5758
import org.apache.cloudstack.api.command.admin.host.DeclareHostAsDegradedCmd;
5859
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
5960
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
61+
import org.apache.cloudstack.framework.config.ConfigKey;
6062
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
6163
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
6264
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
@@ -75,6 +77,7 @@
7577
import org.mockito.Spy;
7678
import org.mockito.junit.MockitoJUnitRunner;
7779

80+
import java.lang.reflect.Field;
7881
import java.util.ArrayList;
7982
import java.util.Arrays;
8083
import java.util.Collections;
@@ -179,6 +182,12 @@ public class ResourceManagerImplTest {
179182
private MockedConstruction<GetVncPortCommand> getVncPortCommandMockedConstruction;
180183
private AutoCloseable closeable;
181184

185+
private void overrideDefaultConfigValue(final ConfigKey configKey, final String name, final Object o) throws IllegalAccessException, NoSuchFieldException {
186+
Field f = ConfigKey.class.getDeclaredField(name);
187+
f.setAccessible(true);
188+
f.set(configKey, o);
189+
}
190+
182191
@Before
183192
public void setup() throws Exception {
184193
closeable = MockitoAnnotations.openMocks(this);
@@ -221,7 +230,7 @@ public void setup() throws Exception {
221230
eq("service cloudstack-agent restart"))).
222231
willReturn(new SSHCmdHelper.SSHCmdResult(0,"",""));
223232

224-
when(configurationDao.getValue(ResourceManager.KvmSshToAgentEnabled.key())).thenReturn("true");
233+
overrideDefaultConfigValue(ResourceManager.KvmSshToAgentEnabled, "_defaultValue", "true");
225234

226235
rootDisks = Arrays.asList(rootDisk1, rootDisk2);
227236
dataDisks = Collections.singletonList(dataDisk);
@@ -383,8 +392,9 @@ public void testConnectAndRestartAgentOnHost() {
383392
}
384393

385394
@Test
386-
public void testHandleAgentSSHEnabledNotConnectedAgent() {
395+
public void testHandleAgentSSHEnabledNotConnectedAgent() throws NoSuchFieldException, IllegalAccessException {
387396
when(host.getStatus()).thenReturn(Status.Disconnected);
397+
overrideDefaultConfigValue(ResourceManager.KvmSshToAgentEnabled, "_defaultValue", "true");
388398
resourceManager.handleAgentIfNotConnected(host, false);
389399
verify(resourceManager).getHostCredentials(eq(host));
390400
verify(resourceManager).connectAndRestartAgentOnHost(eq(host), eq(hostUsername), eq(hostPassword), eq(hostPrivateKey));
@@ -399,9 +409,9 @@ public void testHandleAgentSSHEnabledConnectedAgent() {
399409
}
400410

401411
@Test(expected = CloudRuntimeException.class)
402-
public void testHandleAgentSSHDisabledNotConnectedAgent() {
412+
public void testHandleAgentSSHDisabledNotConnectedAgent() throws NoSuchFieldException, IllegalAccessException {
403413
when(host.getStatus()).thenReturn(Status.Disconnected);
404-
when(configurationDao.getValue(ResourceManager.KvmSshToAgentEnabled.key())).thenReturn("false");
414+
overrideDefaultConfigValue(ResourceManager.KvmSshToAgentEnabled, "_defaultValue", "false");
405415
resourceManager.handleAgentIfNotConnected(host, false);
406416
}
407417

0 commit comments

Comments
 (0)