Skip to content

Commit 2d1989f

Browse files
committed
Merge branch '4.14'
2 parents e447764 + 8b99411 commit 2d1989f

3 files changed

Lines changed: 26 additions & 5 deletions

File tree

server/src/main/java/com/cloud/server/ManagementServerImpl.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3987,6 +3987,11 @@ private boolean updateHostsInCluster(final UpdateHostPasswordCmd command) {
39873987
// get all the hosts in this cluster
39883988
final List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(command.getClusterId());
39893989

3990+
String userNameWithoutSpaces = StringUtils.deleteWhitespace(command.getUsername());
3991+
if (StringUtils.isBlank(userNameWithoutSpaces)) {
3992+
throw new InvalidParameterValueException("Username should be non empty string");
3993+
}
3994+
39903995
Transaction.execute(new TransactionCallbackNoReturn() {
39913996
@Override
39923997
public void doInTransactionWithoutResult(final TransactionStatus status) {
@@ -3996,7 +4001,12 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
39964001
}
39974002
// update password for this host
39984003
final DetailVO nv = _detailsDao.findDetail(h.getId(), ApiConstants.USERNAME);
3999-
if (nv.getValue().equals(command.getUsername())) {
4004+
if (nv == null) {
4005+
final DetailVO nvu = new DetailVO(h.getId(), ApiConstants.USERNAME, userNameWithoutSpaces);
4006+
_detailsDao.persist(nvu);
4007+
final DetailVO nvp = new DetailVO(h.getId(), ApiConstants.PASSWORD, DBEncryptionUtil.encrypt(command.getPassword()));
4008+
_detailsDao.persist(nvp);
4009+
} else if (nv.getValue().equals(userNameWithoutSpaces)) {
40004010
final DetailVO nvp = _detailsDao.findDetail(h.getId(), ApiConstants.PASSWORD);
40014011
nvp.setValue(DBEncryptionUtil.encrypt(command.getPassword()));
40024012
_detailsDao.persist(nvp);
@@ -4044,6 +4054,12 @@ public boolean updateHostPassword(final UpdateHostPasswordCmd cmd) {
40444054
if (!supportedHypervisors.contains(host.getHypervisorType())) {
40454055
throw new InvalidParameterValueException("This operation is not supported for this hypervisor type");
40464056
}
4057+
4058+
String userNameWithoutSpaces = StringUtils.deleteWhitespace(cmd.getUsername());
4059+
if (StringUtils.isBlank(userNameWithoutSpaces)) {
4060+
throw new InvalidParameterValueException("Username should be non empty string");
4061+
}
4062+
40474063
Transaction.execute(new TransactionCallbackNoReturn() {
40484064
@Override
40494065
public void doInTransactionWithoutResult(final TransactionStatus status) {
@@ -4052,7 +4068,12 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
40524068
}
40534069
// update password for this host
40544070
final DetailVO nv = _detailsDao.findDetail(host.getId(), ApiConstants.USERNAME);
4055-
if (nv.getValue().equals(cmd.getUsername())) {
4071+
if (nv == null) {
4072+
final DetailVO nvu = new DetailVO(host.getId(), ApiConstants.USERNAME, userNameWithoutSpaces);
4073+
_detailsDao.persist(nvu);
4074+
final DetailVO nvp = new DetailVO(host.getId(), ApiConstants.PASSWORD, DBEncryptionUtil.encrypt(cmd.getPassword()));
4075+
_detailsDao.persist(nvp);
4076+
} else if (nv.getValue().equals(userNameWithoutSpaces)) {
40564077
final DetailVO nvp = _detailsDao.findDetail(host.getId(), ApiConstants.PASSWORD);
40574078
nvp.setValue(DBEncryptionUtil.encrypt(cmd.getPassword()));
40584079
_detailsDao.persist(nvp);

server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ public Snapshot backupSnapshotFromVmSnapshot(Long snapshotId, Long vmId, Long vo
465465
}
466466
SnapshotInfo snapshotInfo = this.snapshotFactory.getSnapshot(snapshotId, store);
467467
snapshotInfo = (SnapshotInfo)store.create(snapshotInfo);
468-
SnapshotDataStoreVO snapshotOnPrimaryStore = this._snapshotStoreDao.findBySnapshot(snapshot.getId(), store.getRole());
468+
SnapshotDataStoreVO snapshotOnPrimaryStore = this._snapshotStoreDao.findByStoreSnapshot(store.getRole(), store.getId(), snapshot.getId());
469469
snapshotOnPrimaryStore.setState(ObjectInDataStoreStateMachine.State.Ready);
470470
snapshotOnPrimaryStore.setInstallPath(vmSnapshot.getName());
471471
_snapshotStoreDao.update(snapshotOnPrimaryStore.getId(), snapshotOnPrimaryStore);

server/src/test/java/com/cloud/storage/snapshot/SnapshotManagerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public void testBackupSnapshotFromVmSnapshotF2() {
316316
when(snapshotStoreDao.findParent(any(DataStoreRole.class), nullable(Long.class), nullable(Long.class))).thenReturn(null);
317317
when(snapshotFactory.getSnapshot(nullable(Long.class), nullable(DataStore.class))).thenReturn(snapshotInfoMock);
318318
when(storeMock.create(snapshotInfoMock)).thenReturn(snapshotInfoMock);
319-
when(snapshotStoreDao.findBySnapshot(nullable(Long.class), nullable(DataStoreRole.class))).thenReturn(snapshotStoreMock);
319+
when(snapshotStoreDao.findByStoreSnapshot(nullable(DataStoreRole.class), nullable(Long.class), nullable(Long.class))).thenReturn(snapshotStoreMock);
320320
when(snapshotStoreDao.update(nullable(Long.class), nullable(SnapshotDataStoreVO.class))).thenReturn(true);
321321
when(_snapshotDao.update(nullable(Long.class), nullable(SnapshotVO.class))).thenReturn(true);
322322
when(vmMock.getAccountId()).thenReturn(2L);
@@ -333,7 +333,7 @@ public void testBackupSnapshotFromVmSnapshotF3() {
333333
when(vmMock.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM);
334334
when(_vmSnapshotDao.findById(nullable(Long.class))).thenReturn(vmSnapshotMock);
335335
when(snapshotStoreDao.findParent(any(DataStoreRole.class), nullable(Long.class), nullable(Long.class))).thenReturn(snapshotStoreMock);
336-
when(snapshotStoreDao.findBySnapshot(nullable(Long.class), nullable(DataStoreRole.class))).thenReturn(snapshotStoreMock);
336+
when(snapshotStoreDao.findByStoreSnapshot(nullable(DataStoreRole.class), nullable(Long.class), nullable(Long.class))).thenReturn(snapshotStoreMock);
337337
when(snapshotStoreMock.getInstallPath()).thenReturn("VM_SNAPSHOT_NAME");
338338
when(vmSnapshotMock.getName()).thenReturn("VM_SNAPSHOT_NAME");
339339
Snapshot snapshot = _snapshotMgr.backupSnapshotFromVmSnapshot(TEST_SNAPSHOT_ID, TEST_VM_ID, TEST_VOLUME_ID, TEST_VM_SNAPSHOT_ID);

0 commit comments

Comments
 (0)