Skip to content

Commit 9c0c8f8

Browse files
weizhouapachedhslove
authored andcommitted
kvm: support Rocky/RHEL/OL/Alma in the same cluster (apache#8641)
* kvm: support Rocky/RHEL/OL/Alma in the same cluster * Update PR#8641: add unit tests
1 parent 9618a96 commit 9c0c8f8

2 files changed

Lines changed: 71 additions & 1 deletion

File tree

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
@@ -62,6 +62,7 @@
6262
import java.util.Arrays;
6363
import java.util.Collections;
6464
import java.util.HashMap;
65+
import java.util.HashSet;
6566
import java.util.List;
6667
import java.util.Map;
6768
import java.util.UUID;
@@ -70,6 +71,10 @@
7071

7172
public abstract class LibvirtServerDiscoverer extends DiscovererBase implements Discoverer, Listener, ResourceStateAdapter {
7273
private final int _waitTime = 5; /* wait for 5 minutes */
74+
75+
private final static HashSet<String> COMPATIBLE_HOST_OSES = new HashSet<>(Arrays.asList("Rocky", "Rocky Linux",
76+
"Red", "Red Hat Enterprise Linux", "Oracle", "Oracle Linux Server", "AlmaLinux"));
77+
7378
private String _kvmPrivateNic;
7479
private String _kvmPublicNic;
7580
private String _kvmGuestNic;
@@ -468,7 +473,7 @@ public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
468473
_hostDao.loadDetails(oneHost);
469474
String hostOsInCluster = oneHost.getDetail("Host.OS");
470475
String hostOs = ssCmd.getHostDetails().get("Host.OS");
471-
if (!hostOsInCluster.equalsIgnoreCase(hostOs)) {
476+
if (!isHostOsCompatibleWithOtherHost(hostOsInCluster, hostOs)) {
472477
String msg = String.format("host: %s with hostOS, \"%s\"into a cluster, in which there are \"%s\" hosts added", firstCmd.getPrivateIpAddress(), hostOs, hostOsInCluster);
473478
if (hostOs != null && hostOs.startsWith(hostOsInCluster)) {
474479
logger.warn(String.format("Adding %s. This may or may not be ok!", msg));
@@ -483,6 +488,17 @@ public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
483488
return _resourceMgr.fillRoutingHostVO(host, ssCmd, getHypervisorType(), host.getDetails(), null);
484489
}
485490

491+
protected boolean isHostOsCompatibleWithOtherHost(String hostOsInCluster, String hostOs) {
492+
if (hostOsInCluster.equalsIgnoreCase(hostOs)) {
493+
return true;
494+
}
495+
if (COMPATIBLE_HOST_OSES.contains(hostOsInCluster) && COMPATIBLE_HOST_OSES.contains(hostOs)) {
496+
s_logger.info(String.format("The host OS (%s) is compatible with the existing host OS (%s) in the cluster.", hostOs, hostOsInCluster));
497+
return true;
498+
}
499+
return false;
500+
}
501+
486502
@Override
487503
public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details, List<String> hostTags) {
488504
// 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)