Skip to content
Open
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 @@ -251,6 +251,11 @@ public void cancel() {


public void trackHost(String hostUuid) {
if (!destMaker.isManagedByUs(hostUuid)) {
logger.debug(String.format("skip tracking host[uuid:%s], not managed by us", hostUuid));
return;
}

Tracker t = trackers.get(hostUuid);
if (t != null) {
t.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import org.zstack.utils.gson.JSONObjectUtil
import org.zstack.header.network.l2.BatchCheckNetworkPhysicalInterfaceMsg
import org.zstack.header.network.l2.BatchCheckNetworkPhysicalInterfaceReply
import org.zstack.core.cloudbus.CloudBus
import org.zstack.core.cloudbus.ResourceDestinationMaker
import org.zstack.compute.host.HostTrackImpl

import static org.mockito.Mockito.mock
import static org.mockito.Mockito.when

class HostConnectedTimeCase extends SubCase {

Expand All @@ -34,6 +39,7 @@ class HostConnectedTimeCase extends SubCase {
@Override
void test() {
env.create {
testSkipTrackIfNotManagedByUs()
testHostConnectedTime()
}
}
Expand All @@ -43,6 +49,31 @@ class HostConnectedTimeCase extends SubCase {
env.delete()
}

/**
* Test for ZSTAC-76341: check isManagedByUs before trackHost to prevent dual MN tracking
*/
void testSkipTrackIfNotManagedByUs() {
HostInventory host = env.inventoryByName("kvm") as HostInventory
HostTrackImpl tracker = bean(HostTrackImpl.class)

ResourceDestinationMaker originalDestMaker = tracker.@destMaker

ResourceDestinationMaker mockDestMaker = mock(ResourceDestinationMaker.class)
when(mockDestMaker.isManagedByUs(host.uuid)).thenReturn(false)
tracker.@destMaker = mockDestMaker

tracker.untrackHost(host.uuid)
assert !tracker.trackers.containsKey(host.uuid)

tracker.trackHost(host.uuid)
assert !tracker.trackers.containsKey(host.uuid) : "Host should NOT be tracked when isManagedByUs returns false"

tracker.@destMaker = originalDestMaker

tracker.trackHost(host.uuid)
assert tracker.trackers.containsKey(host.uuid) : "Host should be tracked when isManagedByUs returns true"
}

void testHostConnectedTime() {

HostInventory host = env.inventoryByName("kvm")
Expand Down