Merge branch '4.18' into 4.19

This commit is contained in:
Suresh Kumar Anaparti 2024-07-15 00:59:06 +05:30
commit 7f8f113709
No known key found for this signature in database
GPG Key ID: D7CEAE3A9E71D0AA
2 changed files with 26 additions and 17 deletions

View File

@ -29,6 +29,7 @@ import com.cloud.utils.db.QueryBuilder;
import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction; import com.cloud.utils.db.Transaction;
import com.cloud.utils.db.TransactionCallback; import com.cloud.utils.db.TransactionCallback;
import com.cloud.utils.db.TransactionCallbackNoReturn;
import com.cloud.utils.db.TransactionLegacy; import com.cloud.utils.db.TransactionLegacy;
import com.cloud.utils.db.TransactionStatus; import com.cloud.utils.db.TransactionStatus;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
@ -540,21 +541,25 @@ public class UsageDaoImpl extends GenericDaoBase<UsageVO, Long> implements Usage
@Override @Override
public void removeOldUsageRecords(int days) { public void removeOldUsageRecords(int days) {
String sql = DELETE_ALL_BY_INTERVAL; Transaction.execute(TransactionLegacy.USAGE_DB, new TransactionCallbackNoReturn() {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); @Override
PreparedStatement pstmt = null; public void doInTransactionWithoutResult(TransactionStatus status) {
try { TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start(); PreparedStatement pstmt = null;
pstmt = txn.prepareAutoCloseStatement(sql); try {
pstmt.setLong(1, days); txn.start();
pstmt.executeUpdate(); pstmt = txn.prepareAutoCloseStatement(DELETE_ALL_BY_INTERVAL);
txn.commit(); pstmt.setLong(1, days);
} catch (Exception ex) { pstmt.executeUpdate();
txn.rollback(); txn.commit();
s_logger.error("error removing old cloud_usage records for interval: " + days); } catch (Exception ex) {
} finally { txn.rollback();
txn.close(); s_logger.error("error removing old cloud_usage records for interval: " + days);
} } finally {
txn.close();
}
}
});
} }
public UsageVO persistUsage(final UsageVO usage) { public UsageVO persistUsage(final UsageVO usage) {

View File

@ -26,6 +26,7 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Spy; import org.mockito.Spy;
@ -49,8 +50,7 @@ public class LibvirtOvsFetchInterfaceCommandWrapperTest {
while(interfaces.hasMoreElements()) { while(interfaces.hasMoreElements()) {
NetworkInterface networkInterface = interfaces.nextElement(); NetworkInterface networkInterface = interfaces.nextElement();
if (networkInterface.getInetAddresses().hasMoreElements() && if (networkInterface.getInetAddresses().hasMoreElements() &&
(networkInterface.getName().startsWith("eth") || networkInterface.getName().matches("^(eth|wl|en).*")) {
networkInterface.getName().startsWith("wl"))) {
interfaceName = networkInterface.getName(); interfaceName = networkInterface.getName();
Enumeration<InetAddress> addresses = networkInterface.getInetAddresses(); Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
while(addresses.hasMoreElements()) { while(addresses.hasMoreElements()) {
@ -60,9 +60,13 @@ public class LibvirtOvsFetchInterfaceCommandWrapperTest {
break; break;
}; };
} }
if (StringUtils.isNotBlank(interfaceName) && StringUtils.isNotBlank(ipAddress)) {
break;
}
} }
} }
} catch (SocketException ignored) {} } catch (SocketException ignored) {}
Assume.assumeTrue(StringUtils.isNotBlank(interfaceName));
Ternary<String, String, String> result = null; Ternary<String, String, String> result = null;
try { try {
result = wrapper.getInterfaceDetails(interfaceName); result = wrapper.getInterfaceDetails(interfaceName);