This is an automated email from the ASF dual-hosted git repository.
mgreber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new 067079658 [test] Skip test if hostname has no DNS record
067079658 is described below
commit 0670796586b932f0e471919cbb24faf734dfb250
Author: Ashwani Raina <[email protected]>
AuthorDate: Thu Oct 30 15:34:42 2025 +0530
[test] Skip test if hostname has no DNS record
With IPv6 support, some tests, that make use of DNS resolution,
can end up with error if the ip_config_mode is set to a family for
which 'hostname' has no corresponding DNS record.
For example, if a hostname resolves to just an IPv4 address on a system,
running the test with ip_config_mode as 'IPv6' fails because
getaddrinfo doesn't find any DNS record for the provided hostname with
desired family set to 'IPv6'.
This patch avoids such scenarios by, proactively, checking whether DNS
record exists or not and skips the test if it doesn't.
Change-Id: Id377c73a752e18324dbd83aad7e613b3ba99ee6b
Reviewed-on: http://gerrit.cloudera.org:8080/23611
Reviewed-by: Alexey Serbin <[email protected]>
Reviewed-by: Marton Greber <[email protected]>
Tested-by: Marton Greber <[email protected]>
---
src/kudu/master/mini_master-test.cc | 12 +++++++++---
src/kudu/rpc/rpc-test-base.h | 16 ++++++++++++++++
src/kudu/util/net/net_util.cc | 2 +-
3 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/src/kudu/master/mini_master-test.cc
b/src/kudu/master/mini_master-test.cc
index 064b45b91..66c6acba7 100644
--- a/src/kudu/master/mini_master-test.cc
+++ b/src/kudu/master/mini_master-test.cc
@@ -26,6 +26,7 @@
#include "kudu/fs/fs_manager.h"
#include "kudu/master/master.h"
#include "kudu/master/mini_master.h"
+#include "kudu/rpc/rpc-test-base.h"
#include "kudu/util/net/net_util.h"
#include "kudu/util/path_util.h"
#include "kudu/util/status.h"
@@ -37,14 +38,18 @@ DECLARE_string(ip_config_mode);
namespace kudu {
namespace master {
+using std::string;
using std::unique_ptr;
class MiniMasterTest : public KuduTest,
- public ::testing::WithParamInterface<std::string> {
+ public ::testing::WithParamInterface<string> {
+ public:
+ MiniMasterTest() {
+ FLAGS_ip_config_mode = GetParam();
+ }
protected:
- static std::string get_host() {
+ static string get_host() {
IPMode mode;
- FLAGS_ip_config_mode = GetParam();
CHECK_OK(ParseIPModeFlag(FLAGS_ip_config_mode, &mode));
switch (mode) {
case IPMode::IPV6:
@@ -62,6 +67,7 @@ INSTANTIATE_TEST_SUITE_P(Parameters, MiniMasterTest,
testing::Values("ipv4", "ipv6", "dual"));
TEST_P(MiniMasterTest, TestMultiDirMaster) {
+ SKIP_IF_HOSTNAME_RESOLUTION_FAILURE_EXPECTED();
// Specifying the number of data directories will create subdirectories
under the test root.
unique_ptr<MiniMaster> mini_master;
FsManager* fs_manager;
diff --git a/src/kudu/rpc/rpc-test-base.h b/src/kudu/rpc/rpc-test-base.h
index d651cddaf..716b3bdc3 100644
--- a/src/kudu/rpc/rpc-test-base.h
+++ b/src/kudu/rpc/rpc-test-base.h
@@ -16,6 +16,8 @@
// under the License.
#pragma once
+#include <netdb.h>
+
#include <algorithm>
#include <atomic>
#include <memory>
@@ -86,6 +88,20 @@ using kudu::rpc_test::WhoAmIResponsePB;
using kudu::rpc_test_diff_package::ReqDiffPackagePB;
using kudu::rpc_test_diff_package::RespDiffPackagePB;
+// If host has no DNS record for a specific ip_config_mode, skip the test.
+// This helps avoid scenarios where getaddrinfo might return error for a
+// 'hostname' that resolves to only ipv4 address with desired family set
+// to ipv6 or the other way around.
+#define SKIP_IF_HOSTNAME_RESOLUTION_FAILURE_EXPECTED() \
+ do { \
+ string host; \
+ Status s = GetFQDN(&host); \
+ if (s.IsNetworkError() && s.posix_code() == EAI_NONAME) { \
+ GTEST_SKIP() << "GetFQDN() failed for this host. Skipping test."; \
+ } \
+ } while (false)
+
+
namespace kudu {
namespace rpc {
diff --git a/src/kudu/util/net/net_util.cc b/src/kudu/util/net/net_util.cc
index b862b8480..d45290cd6 100644
--- a/src/kudu/util/net/net_util.cc
+++ b/src/kudu/util/net/net_util.cc
@@ -145,7 +145,7 @@ Status GetAddrInfo(const string& hostname,
if (rc == EAI_SYSTEM) {
return Status::NetworkError(err_msg, ErrnoToString(err), err);
}
- return Status::NetworkError(err_msg, gai_strerror(rc));
+ return Status::NetworkError(err_msg, gai_strerror(rc), rc);
}
// Converts the given Sockaddr into a HostPort, substituting the FQDN