Skip to content

Commit

Permalink
[PLAT-15465][PLAT-15466] Minor fixes in YNP
Browse files Browse the repository at this point in the history
Summary:
This diff -
1. Fixes a typo while validating preflight check results.
2. Fixes the check for mount_point.
3. Moves & install the node-agent-installer.sh inside yugabyte home_directory to cater restrictive environments.

Test Plan: Manual Testing

Reviewers: anijhawan, skhilar

Reviewed By: anijhawan

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D38411
  • Loading branch information
Vars-07 committed Sep 26, 2024
1 parent 11acca7 commit 96703da
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def print_results_helper(self, file):
file.write("""
print_results() {
any_fail=0
if [[ $json_results == *'"result":"FAIL"'* ]]; then
if [[ $json_results == *'"result": "FAIL"'* ]]; then
any_fail=1
fi
json_results+='\n]}'
Expand Down
11 changes: 11 additions & 0 deletions managed/node-agent/resources/ynp/configs/setup_logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import logging.config
import os
import pwd


def setup_logger(config):
Expand Down Expand Up @@ -53,3 +54,13 @@ def setup_logger(config):
os.chmod(os.path.join(log_dir, log_file), 0o644)
logger = logging.getLogger()
logger.info("Logging Setup Done")

if 'SUDO_USER' in os.environ:
original_user = os.environ['SUDO_USER']
else:
original_user = os.getlogin()
user_info = pwd.getpwnam(original_user)
uid = user_info.pw_uid
gid = user_info.pw_gid
os.chown(log_dir, uid, gid)
os.chown(os.path.join(log_dir, log_file), uid, gid)
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ for mount_point in "${mount_points_array[@]}"; do
add_result "home directory check" "FAIL" "$message"
fi
if [ -d "$mount_point" ]; then
if [ -w "$mount_point" ] && [ $(( $(stat -c %a "$mount_point") % 10 & 2 )) -ne 0 ]; then
if su - {{ yb_user }} -c "test -w \"$mount_point\""; then
result="PASS"
message="Directory $mount_point exists and is world-writable."
message="Directory $mount_point exists and is writable by {{ yb_user }}."
echo "[PASS] $message"
else
result="FAIL"
message="Directory $mount_point exists but is not world-writable."
message="Directory $mount_point exists but is not {{ yb_user }} writable."
echo "[FAIL] $message"
any_fail=1
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ if [ "$http_status" -ge 200 ] && [ "$http_status" -lt 300 ]; then
echo "HTTP GET request successful. Processing response..."

# Extract IPs using sed and grep
ips=$(echo "$response_body" | sed -n 's/.*"ip":"\([a-zA-Z0-9\.-]*\)".*/\1/p')
ips=$(echo "$response_body" | grep -o '"ip":"[a-zA-Z0-9.:_-]*"' | cut -d '"' -f4)
for ip in $ips; do
if [[ "$ip" == "{{ node_ip }}" ]]; then
matched=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ airgap_flag="--airgap"
airgap_flag=""
{% endif %}

installer_dir="{{ ynp_dir }}/../../bin"
installer_dir="{{ yb_home_dir }}/.install"
su - {{ yb_user }} -c "\"$installer_dir/node-agent-installer.sh\" -c install \
-u {{ url }} -t {{ api_key }} --provider_id $provider_id \
--instance_type {{ instance_type_name }} --zone_name {{ provider_region_zone_name }} \
Expand Down Expand Up @@ -299,6 +299,8 @@ function cleanup() {
if test -f "{{ tmp_directory }}/add_node_to_provider.json"; then
rm "{{ tmp_directory }}/add_node_to_provider.json"
fi

rm -rf "{{ yb_home_dir }}/.install"
}

trap cleanup EXIT
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,12 @@ else
echo "el8 not detected, skipping changing selinux context"
fi

installer_dir="{{ ynp_dir }}/../../bin"
# Copy node-agent binary to yugabyte home directory. This is needed so that yugabyte user
# can read the binary in restricted environment.
mkdir -p {{ yb_home_dir }}/.install
cp "$installer_dir/node-agent-installer.sh" {{ yb_home_dir }}/.install
chown -R {{ yb_user }}:{{ yb_user }} {{ yb_home_dir }}/.install

# Ensure the permissions for yb_home_dir are 750
chmod 750 "{{ yb_home_dir }}"

0 comments on commit 96703da

Please sign in to comment.