Skip to content

Commit c760f5f

Browse files
committed
Fix KvmSshToAgentEnabled setting description and make it dynamic
1 parent 35e6d7c commit c760f5f

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

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
@@ -51,8 +51,8 @@ public interface ResourceManager extends ResourceService, Configurable {
5151

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

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

engine/schema/src/main/resources/META-INF/db/schema-42020to42030.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ ALTER TABLE `cloud`.`template_store_ref` MODIFY COLUMN `download_url` varchar(20
2323

2424
UPDATE `cloud`.`alert` SET type = 33 WHERE name = 'ALERT.VR.PUBLIC.IFACE.MTU';
2525
UPDATE `cloud`.`alert` SET type = 34 WHERE name = 'ALERT.VR.PRIVATE.IFACE.MTU';
26+
27+
-- Update configuration 'kvm.ssh.to.agent' description and is_dynamic fields
28+
UPDATE `cloud`.`configuration` SET description = 'True if the management server will restart the agent service via SSH into the KVM hosts after or during maintenance operations', is_dynamic = 1 WHERE name = 'kvm.ssh.to.agent';

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,8 +2920,7 @@ protected void handleAgentIfNotConnected(HostVO host, boolean vmsMigrating) {
29202920
if (!isAgentOnHost || vmsMigrating || host.getStatus() == Status.Up) {
29212921
return;
29222922
}
2923-
final boolean sshToAgent = Boolean.parseBoolean(_configDao.getValue(KvmSshToAgentEnabled.key()));
2924-
if (sshToAgent) {
2923+
if (KvmSshToAgentEnabled.value()) {
29252924
Ternary<String, String, String> credentials = getHostCredentials(host);
29262925
connectAndRestartAgentOnHost(host, credentials.first(), credentials.second(), credentials.third());
29272926
} else {

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.trilead.ssh2.Connection;
4646
import org.apache.cloudstack.api.command.admin.host.CancelHostAsDegradedCmd;
4747
import org.apache.cloudstack.api.command.admin.host.DeclareHostAsDegradedCmd;
48+
import org.apache.cloudstack.framework.config.ConfigKey;
4849
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
4950
import org.junit.After;
5051
import org.junit.Assert;
@@ -61,6 +62,7 @@
6162
import org.mockito.Spy;
6263
import org.mockito.junit.MockitoJUnitRunner;
6364

65+
import java.lang.reflect.Field;
6466
import java.util.ArrayList;
6567
import java.util.Arrays;
6668
import java.util.Collections;
@@ -152,6 +154,12 @@ public class ResourceManagerImplTest {
152154
private MockedConstruction<GetVncPortCommand> getVncPortCommandMockedConstruction;
153155
private AutoCloseable closeable;
154156

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+
155163
@Before
156164
public void setup() throws Exception {
157165
closeable = MockitoAnnotations.openMocks(this);
@@ -194,7 +202,7 @@ public void setup() throws Exception {
194202
eq("service cloudstack-agent restart"))).
195203
willReturn(new SSHCmdHelper.SSHCmdResult(0,"",""));
196204

197-
when(configurationDao.getValue(ResourceManager.KvmSshToAgentEnabled.key())).thenReturn("true");
205+
overrideDefaultConfigValue(ResourceManager.KvmSshToAgentEnabled, "_defaultValue", "true");
198206

199207
rootDisks = Arrays.asList(rootDisk1, rootDisk2);
200208
dataDisks = Collections.singletonList(dataDisk);
@@ -372,9 +380,9 @@ public void testHandleAgentSSHEnabledConnectedAgent() {
372380
}
373381

374382
@Test(expected = CloudRuntimeException.class)
375-
public void testHandleAgentSSHDisabledNotConnectedAgent() {
383+
public void testHandleAgentSSHDisabledNotConnectedAgent() throws NoSuchFieldException, IllegalAccessException {
376384
when(host.getStatus()).thenReturn(Status.Disconnected);
377-
when(configurationDao.getValue(ResourceManager.KvmSshToAgentEnabled.key())).thenReturn("false");
385+
overrideDefaultConfigValue(ResourceManager.KvmSshToAgentEnabled, "_defaultValue", "false");
378386
resourceManager.handleAgentIfNotConnected(host, false);
379387
}
380388

0 commit comments

Comments
 (0)