Skip to content

Commit 865c356

Browse files
committed
Update PR#8641: add unit tests
1 parent 12c2542 commit 865c356

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
490490
return _resourceMgr.fillRoutingHostVO(host, ssCmd, getHypervisorType(), host.getDetails(), null);
491491
}
492492

493-
private boolean isHostOsCompatibleWithOtherHost(String hostOsInCluster, String hostOs) {
493+
protected boolean isHostOsCompatibleWithOtherHost(String hostOsInCluster, String hostOs) {
494494
if (hostOsInCluster.equalsIgnoreCase(hostOs)) {
495495
return true;
496496
}
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)