Skip to content

Commit 42e7117

Browse files
Merge remote-tracking branch 'origin/4.18' into 4.19
2 parents 4d6df58 + fcfa371 commit 42e7117

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import java.util.Arrays;
6464
import java.util.Collections;
6565
import java.util.HashMap;
66+
import java.util.HashSet;
6667
import java.util.List;
6768
import java.util.Map;
6869
import java.util.UUID;
@@ -72,6 +73,10 @@
7273
public abstract class LibvirtServerDiscoverer extends DiscovererBase implements Discoverer, Listener, ResourceStateAdapter {
7374
private static final Logger s_logger = Logger.getLogger(LibvirtServerDiscoverer.class);
7475
private final int _waitTime = 5; /* wait for 5 minutes */
76+
77+
private final static HashSet<String> COMPATIBLE_HOST_OSES = new HashSet<>(Arrays.asList("Rocky", "Rocky Linux",
78+
"Red", "Red Hat Enterprise Linux", "Oracle", "Oracle Linux Server", "AlmaLinux"));
79+
7580
private String _kvmPrivateNic;
7681
private String _kvmPublicNic;
7782
private String _kvmGuestNic;
@@ -470,7 +475,7 @@ public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
470475
_hostDao.loadDetails(oneHost);
471476
String hostOsInCluster = oneHost.getDetail("Host.OS");
472477
String hostOs = ssCmd.getHostDetails().get("Host.OS");
473-
if (!hostOsInCluster.equalsIgnoreCase(hostOs)) {
478+
if (!isHostOsCompatibleWithOtherHost(hostOsInCluster, hostOs)) {
474479
String msg = String.format("host: %s with hostOS, \"%s\"into a cluster, in which there are \"%s\" hosts added", firstCmd.getPrivateIpAddress(), hostOs, hostOsInCluster);
475480
if (hostOs != null && hostOs.startsWith(hostOsInCluster)) {
476481
s_logger.warn(String.format("Adding %s. This may or may not be ok!", msg));
@@ -485,6 +490,17 @@ public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
485490
return _resourceMgr.fillRoutingHostVO(host, ssCmd, getHypervisorType(), host.getDetails(), null);
486491
}
487492

493+
protected boolean isHostOsCompatibleWithOtherHost(String hostOsInCluster, String hostOs) {
494+
if (hostOsInCluster.equalsIgnoreCase(hostOs)) {
495+
return true;
496+
}
497+
if (COMPATIBLE_HOST_OSES.contains(hostOsInCluster) && COMPATIBLE_HOST_OSES.contains(hostOs)) {
498+
s_logger.info(String.format("The host OS (%s) is compatible with the existing host OS (%s) in the cluster.", hostOs, hostOsInCluster));
499+
return true;
500+
}
501+
return false;
502+
}
503+
488504
@Override
489505
public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details, List<String> hostTags) {
490506
// TODO Auto-generated method stub
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.hypervisor.kvm.discoverer;
21+
22+
import org.junit.Assert;
23+
import org.junit.Test;
24+
import org.junit.runner.RunWith;
25+
import org.mockito.Spy;
26+
import org.mockito.junit.MockitoJUnitRunner;
27+
28+
@RunWith(MockitoJUnitRunner.class)
29+
public class LibvirtServerDiscovererTest {
30+
31+
@Spy
32+
private LibvirtServerDiscoverer libvirtServerDiscoverer;
33+
34+
@Test
35+
public void validateCompatibleOses() {
36+
validateCompatibleOs("Rocky Linux", "Rocky Linux", true);
37+
validateCompatibleOs("Rocky", "Rocky Linux", true);
38+
validateCompatibleOs("Red", "Red Hat Enterprise Linux", true);
39+
validateCompatibleOs("Oracle", "Oracle Linux Server", true);
40+
validateCompatibleOs("Rocky Linux", "Red Hat Enterprise Linux", true);
41+
validateCompatibleOs("AlmaLinux", "Red Hat Enterprise Linux", true);
42+
43+
validateCompatibleOs("Windows", "Rocky Linux", false);
44+
validateCompatibleOs("SUSE", "Rocky Linux", false);
45+
}
46+
47+
private void validateCompatibleOs(String hostOsInCluster, String hostOs, boolean expected) {
48+
if (expected) {
49+
Assert.assertTrue(libvirtServerDiscoverer.isHostOsCompatibleWithOtherHost(hostOsInCluster, hostOs));
50+
} else {
51+
Assert.assertFalse(libvirtServerDiscoverer.isHostOsCompatibleWithOtherHost(hostOsInCluster, hostOs));
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)