From c06d85938271b0fdd4aec913b76ed34e8e28fda7 Mon Sep 17 00:00:00 2001 From: Nikhil Chandrappa Date: Mon, 2 Dec 2024 07:48:41 +0000 Subject: [PATCH] [#23331] yugabyted: Fixing yugabyted tests broken with pg_isready diff D34597. Summary: On Jenkins pipelines `pg_isready` binary is not available in the paths configured in yugabyted. Adding required changes to find the `pg_isready` on Jenkins VMs. Jira: DB-12256 Test Plan: ./yb_build.sh --java-test 'org.yb.yugabyted.TestYugabytedSingleNode' Reviewers: sgarg-yb Reviewed By: sgarg-yb Subscribers: yugabyted-dev Differential Revision: https://phorge.dev.yugabyte.com/D40379 --- bin/yugabyted | 37 ++++++++------- .../yb/yugabyted/TestYugabytedSingleNode.java | 45 +++++++++++++++++-- 2 files changed, 61 insertions(+), 21 deletions(-) diff --git a/bin/yugabyted b/bin/yugabyted index efe6db977247..11e61e2d3840 100755 --- a/bin/yugabyted +++ b/bin/yugabyted @@ -479,28 +479,27 @@ def check_files_in_path(path, files): return not has_error -def get_ysqlsh_test_env_path(): +def find_binary_path_in_test_env(binary_name): - # Find directories inside YUGABYTE_DIR containing ysqlsh - directories_with_ysqlsh = find_directories_with_ysqlsh(YUGABYTE_DIR) - if directories_with_ysqlsh: - for directory in directories_with_ysqlsh: + # Find directories inside YUGABYTE_DIR containing the specific binary. + directories_with_binary = find_test_directories_with_binary(YUGABYTE_DIR, binary_name) + if directories_with_binary: + for directory in directories_with_binary: if 'postgres/bin' in directory: - ysqlsh_path = os.path.join(directory, 'ysqlsh') - Output.log("Using directory for running ysqlsh: {}".format( + binary_path = os.path.join(directory, binary_name) + Output.log("Using directory for running {}: {}".format(binary_name, directory)) - return ysqlsh_path + return binary_path else: Output.log_error_and_exit( - "No directories containing ysqlsh were found.") + "No directories containing {} were found.".format(binary_name)) - -def find_directories_with_ysqlsh(root_dir): - directories_with_ysqlsh = [] +def find_test_directories_with_binary(root_dir, binary_name): + directories_with_binary = [] for dirpath, _, filenames in os.walk(root_dir): - if 'ysqlsh' in filenames: - directories_with_ysqlsh.append(dirpath) - return directories_with_ysqlsh + if binary_name in filenames: + directories_with_binary.append(dirpath) + return directories_with_binary # Finds the path of a particular YB binary def find_binary_location(binary_name): @@ -508,7 +507,10 @@ def find_binary_location(binary_name): # Specific path for ysqlsh in test environment is_test_env = os.getenv('USER') == 'jenkins' if binary_name == "ysqlsh" and is_test_env: - return get_ysqlsh_test_env_path() + return find_binary_path_in_test_env(binary_name) + + if binary_name == "pg_isready" and is_test_env: + return find_binary_path_in_test_env(binary_name) # Default if tar is downloaded dir_candidates = [ @@ -5835,8 +5837,9 @@ class ControlScript(object): def check_pg_isready(self, timeout = 5, retries = 10): advertise_ip = self.advertise_ip() + ysql_port = self.configs.saved_data.get("ysql_port") path = find_binary_location("pg_isready") - cmd = [path, "-h", str(advertise_ip)] + cmd = [path, "-h", str(advertise_ip), "-p", str(ysql_port)] (out, err, retcode) = run_process_with_retries(cmd=cmd, log_cmd=True, retries=retries, timeout=timeout) diff --git a/java/yb-yugabyted/src/test/java/org/yb/yugabyted/TestYugabytedSingleNode.java b/java/yb-yugabyted/src/test/java/org/yb/yugabyted/TestYugabytedSingleNode.java index 2b6b18d7a37a..10e43c706214 100644 --- a/java/yb-yugabyted/src/test/java/org/yb/yugabyted/TestYugabytedSingleNode.java +++ b/java/yb-yugabyted/src/test/java/org/yb/yugabyted/TestYugabytedSingleNode.java @@ -1,13 +1,18 @@ package org.yb.yugabyted; -import static org.yb.AssertionWrappers.assertEquals; -import static org.yb.AssertionWrappers.assertTrue; +import java.io.BufferedReader; +import java.io.InputStreamReader; import java.util.ArrayList; +import java.util.List; import java.util.Map; + +import org.json.JSONObject; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.yb.AssertionWrappers.assertEquals; +import static org.yb.AssertionWrappers.assertTrue; import org.yb.YBTestRunner; import org.yb.minicluster.MiniYBDaemon; import org.yb.minicluster.MiniYugabytedClusterParameters; @@ -15,7 +20,6 @@ import org.yb.minicluster.YugabytedTestUtils; import com.google.common.net.HostAndPort; -import org.json.JSONObject; @RunWith(value = YBTestRunner.class) public class TestYugabytedSingleNode extends BaseYbdClientTest { @@ -36,6 +40,7 @@ public TestYugabytedSingleNode() { clusterConfigurations.add(nodeConfigurations); } + } @Test(timeout = 300000) @@ -54,10 +59,13 @@ public void testSingleNode() throws Exception { JSONObject jsonObject = new JSONObject(jsonResponse); String actualClusterUuid = jsonObject.getString("cluster_uuid"); LOG.info("Actual Cluster UUID: " + actualClusterUuid); - String baseDir = clusterConfigurations.get(0).baseDir; + String baseDir = clusterConfigurations.get(0).getBaseDir(); // Assert Cluster UUIDs match assertEquals(expectedClusterUuid, actualClusterUuid); + // Check the ysql status + assertTrue(getYsqlStatus()); + // Assert YSQL and YCQL connection boolean isYsqlConnected = YugabytedTestUtils.testYsqlConnection(baseDir, host); boolean isYcqlConnected = YugabytedTestUtils.testYcqlConnection(baseDir, host); @@ -65,4 +73,33 @@ public void testSingleNode() throws Exception { assertTrue(isYsqlConnected); assertTrue(isYcqlConnected); } + + + private Boolean getYsqlStatus() throws Exception { + String baseDir = clusterConfigurations.get(0).getBaseDir(); + Boolean ysqlStatus = false; + + List statusCmd = YugabytedTestUtils.getYugabytedStatus(baseDir); + LOG.info("Yugabyted status cmd: " + statusCmd); + ProcessBuilder procBuilder = + new ProcessBuilder(statusCmd).redirectErrorStream(true); + Process proc = procBuilder.start(); + + try (BufferedReader reader = + new BufferedReader(new InputStreamReader(proc.getInputStream()))) { + String line; + while ((line = reader.readLine()) != null) { + LOG.info("Yugabyted lines: " + line); + if (line.contains("YSQL Status") && !line.contains("Not Ready")) { + ysqlStatus = true; + return ysqlStatus; + } + } + } + int exitCode = proc.waitFor(); + if (exitCode != 0) { + LOG.error("Status command failed with exit code: " + exitCode); + } + return ysqlStatus; + } }