api: fix new password is applied on host when update host password with update_passwd_on_host=false (#7092)

This commit is contained in:
Wei Zhou 2023-01-20 16:11:55 +01:00 committed by GitHub
parent 9366c4ea01
commit 536a387326
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -23,6 +23,7 @@ import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.ClusterResponse;
import org.apache.cloudstack.api.response.HostResponse;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.log4j.Logger;
import com.cloud.user.Account;
@ -67,7 +68,7 @@ public class UpdateHostPasswordCmd extends BaseCmd {
}
public Boolean getUpdatePasswdOnHost() {
return updatePasswdOnHost == null ? false : true;
return BooleanUtils.isTrue(updatePasswdOnHost);
}
public String getPassword() {

View File

@ -27,6 +27,7 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.test.util.ReflectionTestUtils;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.resource.ResourceService;
@ -94,4 +95,15 @@ public class UpdateHostPasswordCmdTest extends TestCase {
assertFalse("The attribute updatePasswdOnHost should be false, but it isn't.", updateHostPasswordCmd.getUpdatePasswdOnHost());
verify(managementServer, times(1)).updateHostPassword(updateHostPasswordCmd);
}
@Test
public void testGetUpdatePasswdOnHostValues() {
assertFalse(updateHostPasswordCmd.getUpdatePasswdOnHost());
ReflectionTestUtils.setField(updateHostPasswordCmd, "updatePasswdOnHost", false);
assertFalse(updateHostPasswordCmd.getUpdatePasswdOnHost());
ReflectionTestUtils.setField(updateHostPasswordCmd, "updatePasswdOnHost", true);
assertTrue(updateHostPasswordCmd.getUpdatePasswdOnHost());
}
}