Copilot commented on code in PR #13775:
URL: https://github.com/apache/cloudstack/pull/13775#discussion_r3917389768
##########
server/src/main/java/com/cloud/ha/HighAvailabilityManagerImpl.java:
##########
@@ -527,9 +528,17 @@ public void scheduleRestart(VMInstanceVO vm, boolean
investigate, ReasonType rea
}
if (!(ForceHA.value() || vm.isHaEnabled())) {
- String hostDesc = "id:" + vm.getHostId() + ", availability
zone id:" + vm.getDataCenterId() + ", pod id:" + vm.getPodIdToDeployIn();
+ HostVO stoppedHost = hostId != null ?
_hostDao.findById(hostId) : null;
+ String hostDesc;
+ if (stoppedHost != null) {
+ DataCenterVO stoppedHostDcVO =
_dcDao.findById(stoppedHost.getDataCenterId());
+ HostPodVO stoppedHostPodVO =
_podDao.findById(stoppedHost.getPodId());
+ hostDesc =
AlertFormatUtils.describeHostLocation(stoppedHost, stoppedHostDcVO,
stoppedHostPodVO);
+ } else {
+ hostDesc = "host id: " + hostId;
+ }
Review Comment:
This alert string uses the resolved host location when the host exists, but
if the host record is missing it falls back to `host id: <id>` (or even `host
id: null`), dropping zone/pod context that is still available from the VM.
Consider a richer fallback that includes zone/pod ids and handles null host ids
explicitly.
##########
server/src/test/java/org/apache/cloudstack/outofbandmanagement/OutOfBandManagementServiceImplTest.java:
##########
@@ -0,0 +1,470 @@
+// 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 org.apache.cloudstack.outofbandmanagement;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.concurrent.Executors;
+
+import org.apache.cloudstack.api.response.OutOfBandManagementResponse;
+import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao;
+import org.apache.cloudstack.poll.BackgroundPollManager;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import com.cloud.alert.AlertManager;
+import com.cloud.dc.ClusterDetailsDao;
+import com.cloud.dc.ClusterDetailsVO;
+import com.cloud.dc.DataCenter;
+import com.cloud.dc.DataCenterDetailVO;
+import com.cloud.dc.dao.ClusterDao;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.dc.dao.DataCenterDetailsDao;
+import com.cloud.host.HostVO;
+import com.cloud.host.dao.HostDao;
+import com.cloud.org.Cluster;
+import com.cloud.resource.ResourceState;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.collect.ImmutableMap;
+
+@RunWith(MockitoJUnitRunner.class)
+public class OutOfBandManagementServiceImplTest {
+
+ private static final String OOBM_ENABLED_DETAIL =
"outOfBandManagementEnabled";
+
+ @Mock
+ private ClusterDao clusterDao;
+ @Mock
+ private ClusterDetailsDao clusterDetailsDao;
+ @Mock
+ private DataCenterDao dataCenterDao;
+ @Mock
+ private DataCenterDetailsDao dataCenterDetailsDao;
+ @Mock
+ private OutOfBandManagementDao outOfBandManagementDao;
+ @Mock
+ private HostDao hostDao;
+ @Mock
+ private AlertManager alertMgr;
+ @Mock
+ private BackgroundPollManager backgroundPollManager;
+
+ @Mock
+ private HostVO host;
+ @Mock
+ private DataCenter zone;
+ @Mock
+ private Cluster cluster;
+
+ private OutOfBandManagementServiceImpl service;
+
+ @BeforeClass
+ public static void setUpStaticFields() throws Exception {
+ Field cacheField =
OutOfBandManagementServiceImpl.class.getDeclaredField("hostAlertCache");
+ cacheField.setAccessible(true);
+ cacheField.set(null, CacheBuilder.newBuilder().build());
+
+ Field executorField =
OutOfBandManagementServiceImpl.class.getDeclaredField("backgroundSyncBlockingExecutor");
+ executorField.setAccessible(true);
+ executorField.set(null, Executors.newSingleThreadExecutor());
+ }
Review Comment:
The test installs a static ExecutorService via reflection but never shuts it
down. If any test path submits work to this executor, the non-daemon thread can
leak across the test suite and potentially keep the JVM alive after tests
complete.
##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -7780,15 +7788,23 @@ public void checkHostsDedication(VMInstanceVO vm, long
srcHostId, long destHostI
//if hosts are dedicated to different account/domains, raise an alert
if (srcExplDedicated && destExplDedicated) {
- if (!((accountOfDedicatedHost(srcHost) == null) ||
(accountOfDedicatedHost(srcHost).equals(accountOfDedicatedHost(destHost))))) {
- String msg = String.format("VM is being migrated from host %s
explicitly dedicated to account %d to host %s explicitly dedicated to account
%d",
- srcHost, accountOfDedicatedHost(srcHost), destHost,
accountOfDedicatedHost(destHost));
+ Long srcAccountId = accountOfDedicatedHost(srcHost);
+ Long destAccountId = accountOfDedicatedHost(destHost);
+ if (!((srcAccountId == null) ||
(srcAccountId.equals(destAccountId)))) {
+ Account srcAccount = _accountDao.findById(srcAccountId);
+ Account destAccount = destAccountId != null ?
_accountDao.findById(destAccountId) : null;
+ String msg = String.format("VM is being migrated from host %s
explicitly dedicated to account %s to host %s %s",
+ srcHost, srcAccount, destHost, destAccount != null ?
"explicitly dedicated to account " + destAccount : "not dedicated to a specific
account");
Review Comment:
If the destination host is dedicated to an account but that account cannot
be resolved (e.g. deleted), the current message incorrectly falls back to “not
dedicated to a specific account” and loses the account id entirely (prints
`null`). Consider keeping the dedication semantics and falling back to the
numeric ids when lookups return null.
This issue also appears in the following locations of the same file:
- line 7804
- line 7818
- line 7832
- line 7840
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]