Skip to content

Commit

Permalink
Only log slurm node list if it's been modified
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Lane <tilne@amazon.com>
  • Loading branch information
Tim Lane authored and tilne committed Apr 3, 2020
1 parent 2c23e2c commit 79db0e4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/sqswatcher/plugins/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# This file has a special meaning for pytest. See https://docs.pytest.org/en/2.7.3/plugins.html for
# additional details.

import filecmp
import logging
import os
import os.path
Expand Down Expand Up @@ -76,14 +77,18 @@ def _read_node_list(config_file):


def _write_node_list_to_file(generic_node_list, config_file_path):
log.info("Writing updated {0} with the following nodes: {1}".format(config_file_path, generic_node_list))
with tempfile.NamedTemporaryFile(mode="w", delete=False) as file:
abs_path = file.name
# Adding a comment to the file so that Slurm does not display warnings in case of empty file
file.write("# This file is automatically generated by ParallelCluster\n\n")
for node in generic_node_list:
file.write("{0}".format(node))

# Only log the updated node list if it's different from the previous version,
# because it can get quite long.
if not filecmp.cmp(config_file_path, abs_path, shallow=False):
log.info("Writing updated {0} with the following nodes: {1}".format(config_file_path, generic_node_list))

# Update permissions on new file
os.chmod(abs_path, 0o744)
# Move new file
Expand Down

0 comments on commit 79db0e4

Please sign in to comment.