Skip to content

Commit 74623aa

Browse files
committed
Merge remote-tracking branch 'apache/4.17'
2 parents 90413cb + a4d3780 commit 74623aa

File tree

4 files changed

+128
-3
lines changed

4 files changed

+128
-3
lines changed

plugins/affinity-group-processors/host-affinity/src/main/java/org/apache/cloudstack/affinity/HostAffinityProcessor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ protected Set<Long> getHostIdSet(List<Long> vmIds) {
8181
Set<Long> hostIds = new HashSet<>();
8282
for (Long groupVMId : vmIds) {
8383
VMInstanceVO groupVM = _vmInstanceDao.findById(groupVMId);
84-
hostIds.add(groupVM.getHostId());
84+
if (groupVM != null && groupVM.getHostId() != null) {
85+
hostIds.add(groupVM.getHostId());
86+
}
8587
}
8688
return hostIds;
8789
}

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
3232
import org.apache.cloudstack.storage.to.TemplateObjectTO;
3333
import org.apache.cloudstack.storage.to.VolumeObjectTO;
34+
import org.apache.commons.lang3.StringUtils;
3435
import org.apache.log4j.Logger;
3536

3637
import com.cloud.agent.api.Answer;
@@ -1270,7 +1271,7 @@ private Map<String, String> getNewDiskMap(VirtualMachineMO vmMo) throws Exceptio
12701271
return mapNewDisk;
12711272
}
12721273

1273-
private void setVolumeToPathAndSize(List<VolumeObjectTO> volumeTOs, VirtualMachineMO vmMo, VmwareHostService hostService, VmwareContext context, VmwareHypervisorHost hyperHost)
1274+
protected void setVolumeToPathAndSize(List<VolumeObjectTO> volumeTOs, VirtualMachineMO vmMo, VmwareHostService hostService, VmwareContext context, VmwareHypervisorHost hyperHost)
12741275
throws Exception {
12751276
String vmName = vmMo.getVmName();
12761277
for (VolumeObjectTO volumeTO : volumeTOs) {
@@ -1282,7 +1283,9 @@ private void setVolumeToPathAndSize(List<VolumeObjectTO> volumeTOs, VirtualMachi
12821283
syncVolume(hostService, vmMo, context, hyperHost, volumeTO);
12831284
path = volumeTO.getPath();
12841285
baseName = VmwareHelper.trimSnapshotDeltaPostfix(volumeTO.getPath());
1285-
datastoreUuid = volumeTO.getDataStoreUuid();
1286+
if (StringUtils.isNotEmpty(volumeTO.getDataStoreUuid())) {
1287+
datastoreUuid = volumeTO.getDataStoreUuid();
1288+
}
12861289
} else {
12871290
Map<String, String> mapNewDisk = getNewDiskMap(vmMo);
12881291
// if this is managed storage
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.hypervisor.vmware.manager;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
import java.util.UUID;
22+
23+
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
24+
import org.apache.cloudstack.storage.to.VolumeObjectTO;
25+
import org.junit.Assert;
26+
import org.junit.Before;
27+
import org.junit.Test;
28+
import org.mockito.InjectMocks;
29+
import org.mockito.Mockito;
30+
31+
import com.cloud.hypervisor.vmware.mo.VirtualMachineMO;
32+
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost;
33+
import com.cloud.hypervisor.vmware.util.VmwareClient;
34+
import com.cloud.hypervisor.vmware.util.VmwareContext;
35+
import com.cloud.storage.Storage;
36+
import com.vmware.vim25.HostDatastoreBrowserSearchResults;
37+
import com.vmware.vim25.ManagedObjectReference;
38+
import com.vmware.vim25.VimPortType;
39+
import com.vmware.vim25.VirtualDisk;
40+
41+
public class VmwareStorageManagerImplTest {
42+
43+
@InjectMocks
44+
private VmwareStorageManagerImpl storageManager;
45+
46+
@Before
47+
public void init() {
48+
VmwareStorageMount mountService = Mockito.mock(VmwareStorageMount.class);
49+
50+
storageManager = new VmwareStorageManagerImpl(mountService);
51+
}
52+
53+
private void testCommon(Storage.StoragePoolType poolType, Storage.StoragePoolType parentPoolType, boolean dsChange) {
54+
VirtualMachineMO vmMo = Mockito.mock(VirtualMachineMO.class);
55+
VmwareContext context = Mockito.mock(VmwareContext.class);
56+
VmwareHypervisorHost hyperHost = Mockito.mock(VmwareHypervisorHost.class);
57+
final String volumePath = "somepath";
58+
final String uuid1 = UUID.randomUUID().toString();
59+
final String uuid2 = UUID.randomUUID().toString();
60+
VolumeObjectTO volumeTO = new VolumeObjectTO();
61+
volumeTO.setPath(volumePath);
62+
PrimaryDataStoreTO primaryDataStoreTO = Mockito.mock(PrimaryDataStoreTO.class);
63+
Mockito.when(primaryDataStoreTO.getPoolType()).thenReturn(poolType);
64+
Mockito.when(primaryDataStoreTO.getParentPoolType()).thenReturn(parentPoolType);
65+
Mockito.when(primaryDataStoreTO.getUuid()).thenReturn(uuid1);
66+
volumeTO.setDataStore(primaryDataStoreTO);
67+
boolean isVolumeOnDatastoreCluster = Storage.StoragePoolType.DatastoreCluster.equals(poolType) || Storage.StoragePoolType.DatastoreCluster.equals(parentPoolType);
68+
if (isVolumeOnDatastoreCluster && dsChange) {
69+
volumeTO.setDataStoreUuid(uuid2);
70+
}
71+
VmwareClient vmwareClient = Mockito.mock(VmwareClient.class);
72+
VimPortType service = Mockito.mock(VimPortType.class);
73+
ManagedObjectReference mor = Mockito.mock(ManagedObjectReference.class);
74+
ArrayList<HostDatastoreBrowserSearchResults> arr = new ArrayList<>();
75+
Mockito.when(context.getVimClient()).thenReturn(vmwareClient);
76+
Mockito.when(context.getService()).thenReturn(service);
77+
List<VolumeObjectTO> volumes = List.of(volumeTO);
78+
try {
79+
Mockito.when(vmMo.getVmName()).thenReturn("dummy-vm");
80+
String key = "browser";
81+
Mockito.when(vmwareClient.getDynamicProperty(null, key)).thenReturn(null);
82+
Mockito.when(vmwareClient.getDynamicProperty(mor, key)).thenReturn(mor);
83+
Mockito.when(vmwareClient.waitForTask(Mockito.any())).thenReturn(true);
84+
Mockito.doNothing().when(context).waitForTaskProgressDone(Mockito.any(ManagedObjectReference.class));
85+
key = "info.result";
86+
Mockito.when(vmwareClient.getDynamicProperty(null, key)).thenReturn(arr);
87+
Mockito.doThrow(RuntimeException.class).when(service).searchDatastoreSubFoldersTask(Mockito.eq(null), Mockito.anyString(), Mockito.any());
88+
Mockito.when(vmMo.getAllDiskDevice()).thenReturn(new VirtualDisk[0]);
89+
if (isVolumeOnDatastoreCluster) {
90+
if (dsChange) {
91+
Mockito.when(hyperHost.findDatastore(uuid2)).thenReturn(mor);
92+
} else {
93+
Mockito.when(hyperHost.findDatastore(uuid1)).thenReturn(mor);
94+
}
95+
} else {
96+
Mockito.when(hyperHost.findDatastoreByName(volumePath)).thenReturn(mor);
97+
}
98+
storageManager.setVolumeToPathAndSize(volumes, vmMo, Mockito.mock(VmwareHostService.class), context, hyperHost);
99+
} catch (Exception e) {
100+
e.printStackTrace();
101+
}
102+
Assert.assertEquals(0L, (long) volumes.get(0).getSize());
103+
}
104+
105+
@Test
106+
public void testSetVolumeToPathAndSizeNotDatastoreCluster() {
107+
testCommon(Storage.StoragePoolType.VMFS, null, false);
108+
}
109+
110+
@Test
111+
public void testSetVolumeToPathAndSizeDatastoreClusterSameChildStore() {
112+
testCommon(Storage.StoragePoolType.PreSetup, Storage.StoragePoolType.DatastoreCluster, false);
113+
}
114+
115+
@Test
116+
public void testSetVolumeToPathAndSizeDatastoreClusterDifferentChildStore() {
117+
testCommon(Storage.StoragePoolType.PreSetup, Storage.StoragePoolType.DatastoreCluster, true);
118+
}
119+
}

ui/src/views/compute/DeployVM.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,7 @@ export default {
19421942
// step 2: select template/iso
19431943
if (this.tabKey === 'templateid') {
19441944
deployVmData.templateid = values.templateid
1945+
values.hypervisor = null
19451946
} else {
19461947
deployVmData.templateid = values.isoid
19471948
}

0 commit comments

Comments
 (0)