Skip to content

Commit

Permalink
[Integ-tests] Use right permission to operate on log files
Browse files Browse the repository at this point in the history
In many of the operating systems ParallelCluster supported, `root` user could bypass any files permissions. However, with RHEL9 and Rocky9, `root` user could not bypass files permissions by default. Therefore, this commit improves integration tests to operate on files with the owner users of the files

Signed-off-by: Hanwen <[email protected]>
  • Loading branch information
hanwen-cluster committed Jan 16, 2024
1 parent a0efb5c commit b5b3c41
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 7 additions & 1 deletion tests/integration-tests/remote_command_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,13 @@ def get_remote_files(self, *args, **kwargs):
def clear_log_file(self, path: str):
"""Clear a log file in a specific path."""

self.run_remote_command(f"sudo truncate -s 0 {path}")
log_file_owner_result = self.run_remote_command(f"stat -c '%U' {path}", raise_on_error=False)
if log_file_owner_result.failed:
# If failed, it means the `log_path` does not contain files/directories. Use root as the default owner.
log_file_owner = "root"
else:
log_file_owner = log_file_owner_result.stdout.strip()
self.run_remote_command(f"sudo -u {log_file_owner} truncate -s 0 {path}")

def clear_clustermgtd_log(self):
"""Clear clustermgtd log file."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,15 @@ def _write_dummy_message_to_log(self, log_path, node_type):
dummy_log_entry = "CloudWatch logs integ test - ensuring critical log file is not empty"
self._run_command_on_head_node(f"echo '{dummy_log_entry}' > {dummy_log_message_path}")
# Append the dummy entry to the log
cmd = f"sudo tee -a {log_path} < {dummy_log_message_path}"
log_file_owner_result = self.remote_command_executor.run_remote_command(
f"stat -c '%U' {log_path}", raise_on_error=False
)
if log_file_owner_result.failed:
# If failed, it means the `log_path` does not contain files/directories. Use root as the default owner.
log_file_owner = "root"
else:
log_file_owner = log_file_owner_result.stdout.strip()
cmd = f"sudo -u {log_file_owner} tee -a {log_path} < {dummy_log_message_path}"
if node_type == HEAD_NODE_ROLE_NAME:
self._run_command_on_head_node(cmd)
elif node_type == COMPUTE_NODE_ROLE_NAME:
Expand Down

0 comments on commit b5b3c41

Please sign in to comment.