Merge remote-tracking branch 'apache/4.17'

This commit is contained in:
Wei Zhou 2022-12-07 13:37:30 +01:00
commit 74623aa3d3
4 changed files with 128 additions and 3 deletions

View File

@ -81,7 +81,9 @@ public class HostAffinityProcessor extends AffinityProcessorBase implements Affi
Set<Long> hostIds = new HashSet<>();
for (Long groupVMId : vmIds) {
VMInstanceVO groupVM = _vmInstanceDao.findById(groupVMId);
hostIds.add(groupVM.getHostId());
if (groupVM != null && groupVM.getHostId() != null) {
hostIds.add(groupVM.getHostId());
}
}
return hostIds;
}

View File

@ -31,6 +31,7 @@ import java.util.UUID;
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
import org.apache.cloudstack.storage.to.TemplateObjectTO;
import org.apache.cloudstack.storage.to.VolumeObjectTO;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import com.cloud.agent.api.Answer;
@ -1270,7 +1271,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
return mapNewDisk;
}
private void setVolumeToPathAndSize(List<VolumeObjectTO> volumeTOs, VirtualMachineMO vmMo, VmwareHostService hostService, VmwareContext context, VmwareHypervisorHost hyperHost)
protected void setVolumeToPathAndSize(List<VolumeObjectTO> volumeTOs, VirtualMachineMO vmMo, VmwareHostService hostService, VmwareContext context, VmwareHypervisorHost hyperHost)
throws Exception {
String vmName = vmMo.getVmName();
for (VolumeObjectTO volumeTO : volumeTOs) {
@ -1282,7 +1283,9 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
syncVolume(hostService, vmMo, context, hyperHost, volumeTO);
path = volumeTO.getPath();
baseName = VmwareHelper.trimSnapshotDeltaPostfix(volumeTO.getPath());
datastoreUuid = volumeTO.getDataStoreUuid();
if (StringUtils.isNotEmpty(volumeTO.getDataStoreUuid())) {
datastoreUuid = volumeTO.getDataStoreUuid();
}
} else {
Map<String, String> mapNewDisk = getNewDiskMap(vmMo);
// if this is managed storage

View File

@ -0,0 +1,119 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.hypervisor.vmware.manager;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
import org.apache.cloudstack.storage.to.VolumeObjectTO;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mockito;
import com.cloud.hypervisor.vmware.mo.VirtualMachineMO;
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost;
import com.cloud.hypervisor.vmware.util.VmwareClient;
import com.cloud.hypervisor.vmware.util.VmwareContext;
import com.cloud.storage.Storage;
import com.vmware.vim25.HostDatastoreBrowserSearchResults;
import com.vmware.vim25.ManagedObjectReference;
import com.vmware.vim25.VimPortType;
import com.vmware.vim25.VirtualDisk;
public class VmwareStorageManagerImplTest {
@InjectMocks
private VmwareStorageManagerImpl storageManager;
@Before
public void init() {
VmwareStorageMount mountService = Mockito.mock(VmwareStorageMount.class);
storageManager = new VmwareStorageManagerImpl(mountService);
}
private void testCommon(Storage.StoragePoolType poolType, Storage.StoragePoolType parentPoolType, boolean dsChange) {
VirtualMachineMO vmMo = Mockito.mock(VirtualMachineMO.class);
VmwareContext context = Mockito.mock(VmwareContext.class);
VmwareHypervisorHost hyperHost = Mockito.mock(VmwareHypervisorHost.class);
final String volumePath = "somepath";
final String uuid1 = UUID.randomUUID().toString();
final String uuid2 = UUID.randomUUID().toString();
VolumeObjectTO volumeTO = new VolumeObjectTO();
volumeTO.setPath(volumePath);
PrimaryDataStoreTO primaryDataStoreTO = Mockito.mock(PrimaryDataStoreTO.class);
Mockito.when(primaryDataStoreTO.getPoolType()).thenReturn(poolType);
Mockito.when(primaryDataStoreTO.getParentPoolType()).thenReturn(parentPoolType);
Mockito.when(primaryDataStoreTO.getUuid()).thenReturn(uuid1);
volumeTO.setDataStore(primaryDataStoreTO);
boolean isVolumeOnDatastoreCluster = Storage.StoragePoolType.DatastoreCluster.equals(poolType) || Storage.StoragePoolType.DatastoreCluster.equals(parentPoolType);
if (isVolumeOnDatastoreCluster && dsChange) {
volumeTO.setDataStoreUuid(uuid2);
}
VmwareClient vmwareClient = Mockito.mock(VmwareClient.class);
VimPortType service = Mockito.mock(VimPortType.class);
ManagedObjectReference mor = Mockito.mock(ManagedObjectReference.class);
ArrayList<HostDatastoreBrowserSearchResults> arr = new ArrayList<>();
Mockito.when(context.getVimClient()).thenReturn(vmwareClient);
Mockito.when(context.getService()).thenReturn(service);
List<VolumeObjectTO> volumes = List.of(volumeTO);
try {
Mockito.when(vmMo.getVmName()).thenReturn("dummy-vm");
String key = "browser";
Mockito.when(vmwareClient.getDynamicProperty(null, key)).thenReturn(null);
Mockito.when(vmwareClient.getDynamicProperty(mor, key)).thenReturn(mor);
Mockito.when(vmwareClient.waitForTask(Mockito.any())).thenReturn(true);
Mockito.doNothing().when(context).waitForTaskProgressDone(Mockito.any(ManagedObjectReference.class));
key = "info.result";
Mockito.when(vmwareClient.getDynamicProperty(null, key)).thenReturn(arr);
Mockito.doThrow(RuntimeException.class).when(service).searchDatastoreSubFoldersTask(Mockito.eq(null), Mockito.anyString(), Mockito.any());
Mockito.when(vmMo.getAllDiskDevice()).thenReturn(new VirtualDisk[0]);
if (isVolumeOnDatastoreCluster) {
if (dsChange) {
Mockito.when(hyperHost.findDatastore(uuid2)).thenReturn(mor);
} else {
Mockito.when(hyperHost.findDatastore(uuid1)).thenReturn(mor);
}
} else {
Mockito.when(hyperHost.findDatastoreByName(volumePath)).thenReturn(mor);
}
storageManager.setVolumeToPathAndSize(volumes, vmMo, Mockito.mock(VmwareHostService.class), context, hyperHost);
} catch (Exception e) {
e.printStackTrace();
}
Assert.assertEquals(0L, (long) volumes.get(0).getSize());
}
@Test
public void testSetVolumeToPathAndSizeNotDatastoreCluster() {
testCommon(Storage.StoragePoolType.VMFS, null, false);
}
@Test
public void testSetVolumeToPathAndSizeDatastoreClusterSameChildStore() {
testCommon(Storage.StoragePoolType.PreSetup, Storage.StoragePoolType.DatastoreCluster, false);
}
@Test
public void testSetVolumeToPathAndSizeDatastoreClusterDifferentChildStore() {
testCommon(Storage.StoragePoolType.PreSetup, Storage.StoragePoolType.DatastoreCluster, true);
}
}

View File

@ -1942,6 +1942,7 @@ export default {
// step 2: select template/iso
if (this.tabKey === 'templateid') {
deployVmData.templateid = values.templateid
values.hypervisor = null
} else {
deployVmData.templateid = values.isoid
}