Skip to content

Commit c84198d

Browse files
committed
Merge remote-tracking branch 'origin/4.16'
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2 parents 49b2dfc + 4ba2ad5 commit c84198d

File tree

102 files changed

+737
-286
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+737
-286
lines changed

debian/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Description: CloudStack server library
2222

2323
Package: cloudstack-agent
2424
Architecture: all
25-
Depends: ${python:Depends}, ${python3:Depends}, openjdk-11-jre-headless | java11-runtime-headless | java11-runtime | openjdk-11-jre-headless | zulu-11, cloudstack-common (= ${source:Version}), lsb-base (>= 9), openssh-client, qemu-kvm (>= 2.5), libvirt-bin (>= 1.3) | libvirt-daemon-system (>= 3.0), iproute2, ebtables, vlan, ipset, python3-libvirt, ethtool, iptables, lsb-release, aria2, ufw, apparmor
25+
Depends: ${python:Depends}, ${python3:Depends}, openjdk-11-jre-headless | java11-runtime-headless | java11-runtime | openjdk-11-jre-headless | zulu-11, cloudstack-common (= ${source:Version}), lsb-base (>= 9), openssh-client, qemu-kvm (>= 2.5) | qemu-system-x86 (>= 5.2), libvirt-bin (>= 1.3) | libvirt-daemon-system (>= 3.0), iproute2, ebtables, vlan, ipset, python3-libvirt, ethtool, iptables, lsb-release, aria2, ufw, apparmor
2626
Recommends: init-system-helpers
2727
Conflicts: cloud-agent, cloud-agent-libs, cloud-agent-deps, cloud-agent-scripts
2828
Description: CloudStack agent

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3714,10 +3714,6 @@ public DiskDef.DiskBus getDiskModelFromVMDetail(final VirtualMachineTO vmTO) {
37143714
return null;
37153715
}
37163716

3717-
if (_guestCpuArch != null && _guestCpuArch.equals("aarch64")) {
3718-
return DiskDef.DiskBus.SCSI;
3719-
}
3720-
37213717
String rootDiskController = details.get(VmDetailConstants.ROOT_DISK_CONTROLLER);
37223718
if (StringUtils.isNotBlank(rootDiskController)) {
37233719
s_logger.debug("Passed custom disk controller for ROOT disk " + rootDiskController);
@@ -3751,10 +3747,6 @@ public DiskDef.DiskBus getDataDiskModelFromVMDetail(final VirtualMachineTO vmTO)
37513747
}
37523748

37533749
private DiskDef.DiskBus getGuestDiskModel(final String platformEmulator, boolean isUefiEnabled) {
3754-
if (_guestCpuArch != null && _guestCpuArch.equals("aarch64")) {
3755-
return DiskDef.DiskBus.SCSI;
3756-
}
3757-
37583750
if (platformEmulator == null) {
37593751
return DiskDef.DiskBus.IDE;
37603752
} else if (platformEmulator.startsWith("Other PV Virtio-SCSI")) {
@@ -3765,6 +3757,8 @@ private DiskDef.DiskBus getGuestDiskModel(final String platformEmulator, boolean
37653757
return DiskDef.DiskBus.VIRTIO;
37663758
} else if (isUefiEnabled && StringUtils.startsWithAny(platformEmulator, "Windows", "Other")) {
37673759
return DiskDef.DiskBus.SATA;
3760+
} else if (_guestCpuArch != null && _guestCpuArch.equals("aarch64")) {
3761+
return DiskDef.DiskBus.SCSI;
37683762
} else {
37693763
return DiskDef.DiskBus.IDE;
37703764
}

plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ public void testCreateDevicesDef() {
420420
public void testCreateDevicesWithSCSIDisk() {
421421
VirtualMachineTO to = createDefaultVM(false);
422422
to.setDetails(new HashMap<>());
423-
libvirtComputingResourceSpy._guestCpuArch = "aarch64";
423+
to.setPlatformEmulator("Other PV Virtio-SCSI");
424424

425425
GuestDef guest = new GuestDef();
426426
guest.setGuestType(GuestType.KVM);

plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ public void copyAsync(DataObject srcData, DataObject destData, Host destHost, As
629629

630630
private Answer copyTemplateToVolume(DataObject srcData, DataObject destData, Host destHost) {
631631
// Copy PowerFlex/ScaleIO template to volume
632-
LOGGER.debug("Initiating copy from PowerFlex template volume on host " + destHost != null ? destHost.getId() : "");
632+
LOGGER.debug(String.format("Initiating copy from PowerFlex template volume on host %s", destHost != null ? destHost.getId() : "<not specified>"));
633633
int primaryStorageDownloadWait = StorageManager.PRIMARY_STORAGE_DOWNLOAD_WAIT.value();
634634
CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
635635

@@ -648,7 +648,7 @@ private Answer copyTemplateToVolume(DataObject srcData, DataObject destData, Hos
648648

649649
private Answer copyVolume(DataObject srcData, DataObject destData, Host destHost) {
650650
// Copy PowerFlex/ScaleIO volume
651-
LOGGER.debug("Initiating copy from PowerFlex volume on host " + destHost != null ? destHost.getId() : "");
651+
LOGGER.debug(String.format("Initiating copy from PowerFlex template volume on host %s", destHost != null ? destHost.getId() : "<not specified>"));
652652
String value = configDao.getValue(Config.CopyVolumeWait.key());
653653
int copyVolumeWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CopyVolumeWait.getDefaultValue()));
654654

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3152,6 +3152,7 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
31523152
SearchCriteria<ServiceOfferingJoinVO> cpuSearchCriteria = _srvOfferingJoinDao.createSearchCriteria();
31533153
cpuSearchCriteria.addOr("minCpu", Op.NULL);
31543154
cpuSearchCriteria.addOr("constraints", Op.SC, cpuConstraintSearchCriteria);
3155+
cpuSearchCriteria.addOr("minCpu", Op.GTEQ, cpuNumber);
31553156

31563157
sc.addAnd("cpuConstraints", SearchCriteria.Op.SC, cpuSearchCriteria);
31573158
}
@@ -3164,14 +3165,15 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
31643165
SearchCriteria<ServiceOfferingJoinVO> memSearchCriteria = _srvOfferingJoinDao.createSearchCriteria();
31653166
memSearchCriteria.addOr("minMemory", Op.NULL);
31663167
memSearchCriteria.addOr("memconstraints", Op.SC, memoryConstraintSearchCriteria);
3168+
memSearchCriteria.addOr("minMemory", Op.GTEQ, memory);
31673169

31683170
sc.addAnd("memoryConstraints", SearchCriteria.Op.SC, memSearchCriteria);
31693171
}
31703172

31713173
if (cpuSpeed != null) {
31723174
SearchCriteria<ServiceOfferingJoinVO> cpuSpeedSearchCriteria = _srvOfferingJoinDao.createSearchCriteria();
31733175
cpuSpeedSearchCriteria.addOr("speed", Op.NULL);
3174-
cpuSpeedSearchCriteria.addOr("speed", Op.EQ, cpuSpeed);
3176+
cpuSpeedSearchCriteria.addOr("speed", Op.GTEQ, cpuSpeed);
31753177
sc.addAnd("cpuspeedconstraints", SearchCriteria.Op.SC, cpuSpeedSearchCriteria);
31763178
}
31773179

server/src/main/java/com/cloud/hypervisor/kvm/discoverer/LibvirtServerDiscoverer.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,17 @@ private void setupAgentSecurity(final Connection sshConnection, final String age
259259
sshConnection = new Connection(agentIp, 22);
260260

261261
sshConnection.connect(null, 60000, 60000);
262-
if (!sshConnection.authenticateWithPassword(username, password)) {
263-
s_logger.debug("Failed to authenticate");
264-
throw new DiscoveredWithErrorException("Authentication error");
262+
263+
final String privateKey = _configDao.getValue("ssh.privatekey");
264+
if (!SSHCmdHelper.acquireAuthorizedConnectionWithPublicKey(sshConnection, username, privateKey)) {
265+
s_logger.error("Failed to authenticate with ssh key");
266+
if (org.apache.commons.lang3.StringUtils.isEmpty(password)) {
267+
throw new DiscoveredWithErrorException("Authentication error with ssh private key");
268+
}
269+
if (!sshConnection.authenticateWithPassword(username, password)) {
270+
s_logger.error("Failed to authenticate with password");
271+
throw new DiscoveredWithErrorException("Authentication error with host password");
272+
}
265273
}
266274

267275
if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "ls /dev/kvm")) {

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@
165165
import com.cloud.storage.dao.VMTemplateDao;
166166
import com.cloud.user.Account;
167167
import com.cloud.user.AccountManager;
168-
import com.cloud.utils.Pair;
168+
import com.cloud.utils.Ternary;
169+
import com.cloud.utils.StringUtils;
169170
import com.cloud.utils.UriUtils;
170171
import com.cloud.utils.component.Manager;
171172
import com.cloud.utils.component.ManagerBase;
@@ -695,9 +696,16 @@ private List<HostVO> discoverHostsFull(final Long dcId, final Long podId, Long c
695696
throw new InvalidParameterValueException("Can't specify cluster without specifying the pod");
696697
}
697698
List<String> skipList = Arrays.asList(HypervisorType.VMware.name().toLowerCase(Locale.ROOT), Type.SecondaryStorage.name().toLowerCase(Locale.ROOT));
698-
if (!skipList.contains(hypervisorType.toLowerCase(Locale.ROOT)) &&
699-
(StringUtils.isAnyEmpty(username, password))) {
700-
throw new InvalidParameterValueException("Username and Password need to be provided.");
699+
if (!skipList.contains(hypervisorType.toLowerCase(Locale.ROOT))) {
700+
if (HypervisorType.KVM.toString().equalsIgnoreCase(hypervisorType)) {
701+
if (org.apache.commons.lang3.StringUtils.isBlank(username)) {
702+
throw new InvalidParameterValueException("Username need to be provided.");
703+
}
704+
} else {
705+
if (org.apache.commons.lang3.StringUtils.isBlank(username) || org.apache.commons.lang3.StringUtils.isBlank(password)) {
706+
throw new InvalidParameterValueException("Username and Password need to be provided.");
707+
}
708+
}
701709
}
702710

703711
if (clusterId != null) {
@@ -2731,8 +2739,8 @@ protected void handleAgentIfNotConnected(HostVO host, boolean vmsMigrating) {
27312739
}
27322740
final boolean sshToAgent = Boolean.parseBoolean(_configDao.getValue(KvmSshToAgentEnabled.key()));
27332741
if (sshToAgent) {
2734-
Pair<String, String> credentials = getHostCredentials(host);
2735-
connectAndRestartAgentOnHost(host, credentials.first(), credentials.second());
2742+
Ternary<String, String, String> credentials = getHostCredentials(host);
2743+
connectAndRestartAgentOnHost(host, credentials.first(), credentials.second(), credentials.third());
27362744
} else {
27372745
throw new CloudRuntimeException("SSH access is disabled, cannot cancel maintenance mode as " +
27382746
"host agent is not connected");
@@ -2743,22 +2751,23 @@ protected void handleAgentIfNotConnected(HostVO host, boolean vmsMigrating) {
27432751
* Get host credentials
27442752
* @throws CloudRuntimeException if username or password are not found
27452753
*/
2746-
protected Pair<String, String> getHostCredentials(HostVO host) {
2754+
protected Ternary<String, String, String> getHostCredentials(HostVO host) {
27472755
_hostDao.loadDetails(host);
27482756
final String password = host.getDetail("password");
27492757
final String username = host.getDetail("username");
2750-
if (password == null || username == null) {
2751-
throw new CloudRuntimeException("SSH to agent is enabled, but username/password credentials are not found");
2758+
final String privateKey = _configDao.getValue("ssh.privatekey");
2759+
if ((password == null && privateKey == null) || username == null) {
2760+
throw new CloudRuntimeException("SSH to agent is enabled, but username and password or private key are not found");
27522761
}
2753-
return new Pair<>(username, password);
2762+
return new Ternary<>(username, password, privateKey);
27542763
}
27552764

27562765
/**
27572766
* True if agent is restarted via SSH. Assumes kvm.ssh.to.agent = true and host status is not Up
27582767
*/
2759-
protected void connectAndRestartAgentOnHost(HostVO host, String username, String password) {
2768+
protected void connectAndRestartAgentOnHost(HostVO host, String username, String password, String privateKey) {
27602769
final com.trilead.ssh2.Connection connection = SSHCmdHelper.acquireAuthorizedConnection(
2761-
host.getPrivateIpAddress(), 22, username, password);
2770+
host.getPrivateIpAddress(), 22, username, password, privateKey);
27622771
if (connection == null) {
27632772
throw new CloudRuntimeException(String.format("SSH to agent is enabled, but failed to connect to %s via IP address [%s].", host, host.getPrivateIpAddress()));
27642773
}

server/src/main/java/com/cloud/storage/StorageManagerImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,6 +2136,7 @@ public Host findUpAndEnabledHostWithAccessToStoragePools(List<Long> poolIds) {
21362136
if (hostIds.isEmpty()) {
21372137
return null;
21382138
}
2139+
Collections.shuffle(hostIds);
21392140

21402141
for (Long hostId : hostIds) {
21412142
Host host = _hostDao.findById(hostId);

server/src/test/java/com/cloud/resource/ResourceManagerImplTest.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
import com.cloud.host.dao.HostDao;
6868
import com.cloud.hypervisor.Hypervisor;
6969
import com.cloud.storage.StorageManager;
70-
import com.cloud.utils.Pair;
70+
import com.cloud.utils.Ternary;
7171
import com.cloud.utils.exception.CloudRuntimeException;
7272
import com.cloud.utils.fsm.NoTransitionException;
7373
import com.cloud.utils.ssh.SSHCmdHelper;
@@ -125,6 +125,7 @@ public class ResourceManagerImplTest {
125125
private static long hostId = 1L;
126126
private static final String hostUsername = "user";
127127
private static final String hostPassword = "password";
128+
private static final String hostPrivateKey = "privatekey";
128129
private static final String hostPrivateIp = "192.168.1.10";
129130

130131
private static long vm1Id = 1L;
@@ -148,6 +149,7 @@ public void setup() throws Exception {
148149
when(hostDao.findById(hostId)).thenReturn(host);
149150
when(host.getDetail("username")).thenReturn(hostUsername);
150151
when(host.getDetail("password")).thenReturn(hostPassword);
152+
when(configurationDao.getValue("ssh.privatekey")).thenReturn(hostPrivateKey);
151153
when(host.getStatus()).thenReturn(Status.Up);
152154
when(host.getPrivateIpAddress()).thenReturn(hostPrivateIp);
153155
when(vm1.getId()).thenReturn(vm1Id);
@@ -171,7 +173,7 @@ public void setup() throws Exception {
171173

172174
PowerMockito.mockStatic(SSHCmdHelper.class);
173175
BDDMockito.given(SSHCmdHelper.acquireAuthorizedConnection(eq(hostPrivateIp), eq(22),
174-
eq(hostUsername), eq(hostPassword))).willReturn(sshConnection);
176+
eq(hostUsername), eq(hostPassword), eq(hostPrivateKey))).willReturn(sshConnection);
175177
BDDMockito.given(SSHCmdHelper.sshExecuteCmdOneShot(eq(sshConnection),
176178
eq("service cloudstack-agent restart"))).
177179
willReturn(new SSHCmdHelper.SSHCmdResult(0,"",""));
@@ -292,50 +294,52 @@ public void testConfigureVncAccessForKVMHostFailedMigrations() {
292294
@Test(expected = CloudRuntimeException.class)
293295
public void testGetHostCredentialsMissingParameter() {
294296
when(host.getDetail("password")).thenReturn(null);
297+
when(configurationDao.getValue("ssh.privatekey")).thenReturn(null);
295298
resourceManager.getHostCredentials(host);
296299
}
297300

298301
@Test
299302
public void testGetHostCredentials() {
300-
Pair<String, String> credentials = resourceManager.getHostCredentials(host);
303+
Ternary<String, String, String> credentials = resourceManager.getHostCredentials(host);
301304
Assert.assertNotNull(credentials);
302305
Assert.assertEquals(hostUsername, credentials.first());
303306
Assert.assertEquals(hostPassword, credentials.second());
307+
Assert.assertEquals(hostPrivateKey, credentials.third());
304308
}
305309

306310
@Test(expected = CloudRuntimeException.class)
307311
public void testConnectAndRestartAgentOnHostCannotConnect() {
308312
BDDMockito.given(SSHCmdHelper.acquireAuthorizedConnection(eq(hostPrivateIp), eq(22),
309-
eq(hostUsername), eq(hostPassword))).willReturn(null);
310-
resourceManager.connectAndRestartAgentOnHost(host, hostUsername, hostPassword);
313+
eq(hostUsername), eq(hostPassword), eq(hostPrivateKey))).willReturn(null);
314+
resourceManager.connectAndRestartAgentOnHost(host, hostUsername, hostPassword, hostPrivateKey);
311315
}
312316

313317
@Test(expected = CloudRuntimeException.class)
314318
public void testConnectAndRestartAgentOnHostCannotRestart() throws Exception {
315319
BDDMockito.given(SSHCmdHelper.sshExecuteCmdOneShot(eq(sshConnection),
316320
eq("service cloudstack-agent restart"))).willThrow(new SshException("exception"));
317-
resourceManager.connectAndRestartAgentOnHost(host, hostUsername, hostPassword);
321+
resourceManager.connectAndRestartAgentOnHost(host, hostUsername, hostPassword, hostPrivateKey);
318322
}
319323

320324
@Test
321325
public void testConnectAndRestartAgentOnHost() {
322-
resourceManager.connectAndRestartAgentOnHost(host, hostUsername, hostPassword);
326+
resourceManager.connectAndRestartAgentOnHost(host, hostUsername, hostPassword, hostPrivateKey);
323327
}
324328

325329
@Test
326330
public void testHandleAgentSSHEnabledNotConnectedAgent() {
327331
when(host.getStatus()).thenReturn(Status.Disconnected);
328332
resourceManager.handleAgentIfNotConnected(host, false);
329333
verify(resourceManager).getHostCredentials(eq(host));
330-
verify(resourceManager).connectAndRestartAgentOnHost(eq(host), eq(hostUsername), eq(hostPassword));
334+
verify(resourceManager).connectAndRestartAgentOnHost(eq(host), eq(hostUsername), eq(hostPassword), eq(hostPrivateKey));
331335
}
332336

333337
@Test
334338
public void testHandleAgentSSHEnabledConnectedAgent() {
335339
when(host.getStatus()).thenReturn(Status.Up);
336340
resourceManager.handleAgentIfNotConnected(host, false);
337341
verify(resourceManager, never()).getHostCredentials(eq(host));
338-
verify(resourceManager, never()).connectAndRestartAgentOnHost(eq(host), eq(hostUsername), eq(hostPassword));
342+
verify(resourceManager, never()).connectAndRestartAgentOnHost(eq(host), eq(hostUsername), eq(hostPassword), eq(hostPrivateKey));
339343
}
340344

341345
@Test(expected = CloudRuntimeException.class)
@@ -351,14 +355,14 @@ public void testHandleAgentSSHDisabledConnectedAgent() {
351355
when(configurationDao.getValue(ResourceManager.KvmSshToAgentEnabled.key())).thenReturn("false");
352356
resourceManager.handleAgentIfNotConnected(host, false);
353357
verify(resourceManager, never()).getHostCredentials(eq(host));
354-
verify(resourceManager, never()).connectAndRestartAgentOnHost(eq(host), eq(hostUsername), eq(hostPassword));
358+
verify(resourceManager, never()).connectAndRestartAgentOnHost(eq(host), eq(hostUsername), eq(hostPassword), eq(hostPrivateKey));
355359
}
356360

357361
@Test
358362
public void testHandleAgentVMsMigrating() {
359363
resourceManager.handleAgentIfNotConnected(host, true);
360364
verify(resourceManager, never()).getHostCredentials(eq(host));
361-
verify(resourceManager, never()).connectAndRestartAgentOnHost(eq(host), eq(hostUsername), eq(hostPassword));
365+
verify(resourceManager, never()).connectAndRestartAgentOnHost(eq(host), eq(hostUsername), eq(hostPassword), eq(hostPrivateKey));
362366
}
363367

364368
private void setupNoPendingMigrationRetries() {

0 commit comments

Comments
 (0)