Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.UUID;
Expand All @@ -72,6 +73,10 @@
public abstract class LibvirtServerDiscoverer extends DiscovererBase implements Discoverer, Listener, ResourceStateAdapter {
private static final Logger s_logger = Logger.getLogger(LibvirtServerDiscoverer.class);
private final int _waitTime = 5; /* wait for 5 minutes */

private final static HashSet<String> COMPATIBLE_HOST_OSES = new HashSet<>(Arrays.asList("Rocky", "Rocky Linux",
"Red", "Red Hat Enterprise Linux", "Oracle", "Oracle Linux Server", "AlmaLinux"));

private String _kvmPrivateNic;
private String _kvmPublicNic;
private String _kvmGuestNic;
Expand Down Expand Up @@ -470,7 +475,7 @@ public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
_hostDao.loadDetails(oneHost);
String hostOsInCluster = oneHost.getDetail("Host.OS");
String hostOs = ssCmd.getHostDetails().get("Host.OS");
if (!hostOsInCluster.equalsIgnoreCase(hostOs)) {
if (!isHostOsCompatibleWithOtherHost(hostOsInCluster, hostOs)) {
String msg = String.format("host: %s with hostOS, \"%s\"into a cluster, in which there are \"%s\" hosts added", firstCmd.getPrivateIpAddress(), hostOs, hostOsInCluster);
if (hostOs != null && hostOs.startsWith(hostOsInCluster)) {
s_logger.warn(String.format("Adding %s. This may or may not be ok!", msg));
Expand All @@ -485,6 +490,17 @@ public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
return _resourceMgr.fillRoutingHostVO(host, ssCmd, getHypervisorType(), host.getDetails(), null);
}

protected boolean isHostOsCompatibleWithOtherHost(String hostOsInCluster, String hostOs) {
if (hostOsInCluster.equalsIgnoreCase(hostOs)) {
return true;
}
if (COMPATIBLE_HOST_OSES.contains(hostOsInCluster) && COMPATIBLE_HOST_OSES.contains(hostOs)) {
s_logger.info(String.format("The host OS (%s) is compatible with the existing host OS (%s) in the cluster.", hostOs, hostOsInCluster));
return true;
}
return false;
}

@Override
public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details, List<String> hostTags) {
// TODO Auto-generated method stub
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// 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.kvm.discoverer;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class LibvirtServerDiscovererTest {

@Spy
private LibvirtServerDiscoverer libvirtServerDiscoverer;

@Test
public void validateCompatibleOses() {
validateCompatibleOs("Rocky Linux", "Rocky Linux", true);
validateCompatibleOs("Rocky", "Rocky Linux", true);
validateCompatibleOs("Red", "Red Hat Enterprise Linux", true);
validateCompatibleOs("Oracle", "Oracle Linux Server", true);
validateCompatibleOs("Rocky Linux", "Red Hat Enterprise Linux", true);
validateCompatibleOs("AlmaLinux", "Red Hat Enterprise Linux", true);

validateCompatibleOs("Windows", "Rocky Linux", false);
validateCompatibleOs("SUSE", "Rocky Linux", false);
}

private void validateCompatibleOs(String hostOsInCluster, String hostOs, boolean expected) {
if (expected) {
Assert.assertTrue(libvirtServerDiscoverer.isHostOsCompatibleWithOtherHost(hostOsInCluster, hostOs));
} else {
Assert.assertFalse(libvirtServerDiscoverer.isHostOsCompatibleWithOtherHost(hostOsInCluster, hostOs));
}
}
}