Skip to content

Commit 536a387

Browse files
api: fix new password is applied on host when update host password with update_passwd_on_host=false (#7092)
1 parent 9366c4e commit 536a387

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostPasswordCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.cloudstack.api.response.ClusterResponse;
2424
import org.apache.cloudstack.api.response.HostResponse;
2525
import org.apache.cloudstack.api.response.SuccessResponse;
26+
import org.apache.commons.lang3.BooleanUtils;
2627
import org.apache.log4j.Logger;
2728

2829
import com.cloud.user.Account;
@@ -67,7 +68,7 @@ public Long getClusterId() {
6768
}
6869

6970
public Boolean getUpdatePasswdOnHost() {
70-
return updatePasswdOnHost == null ? false : true;
71+
return BooleanUtils.isTrue(updatePasswdOnHost);
7172
}
7273

7374
public String getPassword() {

api/src/test/java/org/apache/cloudstack/api/command/test/UpdateHostPasswordCmdTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.junit.Before;
2828
import org.junit.Test;
2929
import org.mockito.Mockito;
30+
import org.springframework.test.util.ReflectionTestUtils;
3031

3132
import com.cloud.exception.InvalidParameterValueException;
3233
import com.cloud.resource.ResourceService;
@@ -94,4 +95,15 @@ public void testCreateSuccess() {
9495
assertFalse("The attribute updatePasswdOnHost should be false, but it isn't.", updateHostPasswordCmd.getUpdatePasswdOnHost());
9596
verify(managementServer, times(1)).updateHostPassword(updateHostPasswordCmd);
9697
}
97-
}
98+
99+
@Test
100+
public void testGetUpdatePasswdOnHostValues() {
101+
assertFalse(updateHostPasswordCmd.getUpdatePasswdOnHost());
102+
103+
ReflectionTestUtils.setField(updateHostPasswordCmd, "updatePasswdOnHost", false);
104+
assertFalse(updateHostPasswordCmd.getUpdatePasswdOnHost());
105+
106+
ReflectionTestUtils.setField(updateHostPasswordCmd, "updatePasswdOnHost", true);
107+
assertTrue(updateHostPasswordCmd.getUpdatePasswdOnHost());
108+
}
109+
}

0 commit comments

Comments
 (0)