Skip to content

Commit

Permalink
[PLAT-15771] clock-sync.sh is smarter about its python version
Browse files Browse the repository at this point in the history
Summary:
it is possible for a vm to have python3, but not python in the path. Pick a valid python executable.

In addition, if one is not found do not do the full skew calculation

Test Plan: tested clock-sync.sh with various python executables

Reviewers: muthu, nsingh

Reviewed By: muthu

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D39211
  • Loading branch information
shubin-yb committed Oct 21, 2024
1 parent 3c451aa commit fc53c93
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,21 @@ command_exists() {
command -v "$1" >/dev/null 2>&1
}

readonly PYTHON_EXECUTABLES=('python' 'python3' 'python3.11' 'python3.10' 'python3.9' 'python3.8' 'python3.7' 'python3.6' 'python3.12' 'python2')
PYTHON_EXECUTABLE=""
set_python_executable() {
for py_executable in "${PYTHON_EXECUTABLES[@]}"; do
if which "$py_executable" > /dev/null 2>&1; then
PYTHON_EXECUTABLE="$py_executable"
export PYTHON_EXECUTABLE
return
fi
done
}

check_clock_sync_chrony() {
# if chrond is restarted, tracking will return all 0's
set_python_executable
chrony_tracking="$(chronyc tracking)"
if [[ $? -ne 0 ]]; then
echo "`chronyc tracking` failed to execute"
Expand All @@ -31,7 +44,12 @@ check_clock_sync_chrony() {
local skew=$(echo "${chrony_tracking}" | awk '/System time/ {print $4}')
local dispersion=$(echo "${chrony_tracking}" | awk '/Root dispersion/ {print $4}')
local delay=$(echo "${chrony_tracking}" | awk '/Root delay/ {print $4}')
local clock_error=$(python -c 'print('${skew}' + '${dispersion}' + (.5 * '${delay}'))')
local clock_error=""
if [[ -z "${PYTHON_EXECUTABLE}" ]]; then
clock_error=${skew}
else
clock_error=$(${PYTHON_EXECUTABLE} -c 'print('${skew}' + '${dispersion}' + (.5 * '${delay}'))')
fi

if awk 'BEGIN{exit !('"$clock_error"' < '"$acceptable_clock_skew_sec"')}'; then
echo "Clock skew is within acceptable limits: $skew ms"
Expand Down

0 comments on commit fc53c93

Please sign in to comment.