Skip to content

Commit

Permalink
[#23331] yugabyted: Fixing yugabyted tests broken with pg_isready dif…
Browse files Browse the repository at this point in the history
…f 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
  • Loading branch information
nchandrappa committed Dec 2, 2024
1 parent 50db5f0 commit c06d859
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 21 deletions.
37 changes: 20 additions & 17 deletions bin/yugabyted
Original file line number Diff line number Diff line change
Expand Up @@ -479,36 +479,38 @@ 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):

# 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 = [
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
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;
import org.yb.minicluster.MiniYugabytedNodeConfigurations;
import org.yb.minicluster.YugabytedTestUtils;

import com.google.common.net.HostAndPort;
import org.json.JSONObject;

@RunWith(value = YBTestRunner.class)
public class TestYugabytedSingleNode extends BaseYbdClientTest {
Expand All @@ -36,6 +40,7 @@ public TestYugabytedSingleNode() {

clusterConfigurations.add(nodeConfigurations);
}

}

@Test(timeout = 300000)
Expand All @@ -54,15 +59,47 @@ 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);

assertTrue(isYsqlConnected);
assertTrue(isYcqlConnected);
}


private Boolean getYsqlStatus() throws Exception {
String baseDir = clusterConfigurations.get(0).getBaseDir();
Boolean ysqlStatus = false;

List<String> 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;
}
}

0 comments on commit c06d859

Please sign in to comment.