Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This file is used to list changes made in each version of the aws-parallelcluste

**BUG FIXES**
- Handle corner case in the scaling logic when instance is just launched and the describe instances API doesn't report yet all the EC2 info.
- Fix file handle leak in `computemgtd`.

3.1.4
------
Expand Down
12 changes: 5 additions & 7 deletions src/slurm_plugin/computemgtd.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
import time
from configparser import ConfigParser
from datetime import datetime, timezone
from io import StringIO
from logging.config import fileConfig
from subprocess import CalledProcessError
from tempfile import NamedTemporaryFile

from botocore.config import Config
from common.schedulers.slurm_commands import get_nodes_info
from common.time_utils import seconds
from common.utils import run_command, sleep_remaining_loop_time
from common.utils import check_command_output, run_command, sleep_remaining_loop_time
from retrying import retry
from slurm_plugin.common import (
DEFAULT_COMMAND_TIMEOUT,
Expand Down Expand Up @@ -55,8 +55,6 @@ class ComputemgtdConfig:
}

def __init__(self, config_file_path):
tf = NamedTemporaryFile()
self._local_config_file = tf.name
self._get_config(config_file_path)

def __repr__(self):
Expand All @@ -70,12 +68,12 @@ def _get_config(self, config_file_path):
config = ConfigParser()
try:
# Use subprocess based method to copy shared file to local to prevent hanging when NFS is down
run_command(
f"cat {config_file_path} > {self._local_config_file}",
config_str = check_command_output(
f"cat {config_file_path}",
timeout=DEFAULT_COMMAND_TIMEOUT,
shell=True, # nosec
)
config.read_file(open(self._local_config_file, "r"))
config.read_file(StringIO(config_str))
except Exception:
log.error(f"Cannot read computemgtd configuration file: {config_file_path}")
raise
Expand Down
3 changes: 1 addition & 2 deletions tests/slurm_plugin/test_computemgtd.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
)
def test_computemgtd_config(config_file, expected_attributes, test_datadir, mocker):
mocker.patch("slurm_plugin.computemgtd.ComputemgtdConfig._read_nodename_from_file", return_value="some_nodename")
mocker.patch("slurm_plugin.computemgtd.run_command")
mocker.patch("slurm_plugin.computemgtd.open", return_value=open(test_datadir / config_file, "r"))
mocker.patch("slurm_plugin.computemgtd.check_command_output", return_value=(test_datadir / config_file).read_text())
compute_config = ComputemgtdConfig("mocked_config_path")
for key in expected_attributes:
assert_that(compute_config.__dict__.get(key)).is_equal_to(expected_attributes.get(key))
Expand Down