Skip to content

Commit

Permalink
Increase test covereage and use strategy values matching those provid…
Browse files Browse the repository at this point in the history
…ed from the CLI.
  • Loading branch information
EddyMM committed Oct 4, 2023
1 parent dae9c40 commit b995f81
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
18 changes: 6 additions & 12 deletions src/slurm_plugin/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,17 @@


class ScalingStrategy(Enum):
ALL_OR_NOTHING = "all_or_nothing"
BEST_EFFORT = "best_effort"
ALL_OR_NOTHING = "all-or-nothing"
BEST_EFFORT = "best-effort"

DEFAULT = BEST_EFFORT

@classmethod
def _missing_(cls, value):
return cls.DEFAULT

@classmethod
def from_str(cls, strategy):
def _missing_(cls, strategy):
_strategy = str(strategy).lower()
if _strategy == "all_or_nothing":
return cls.ALL_OR_NOTHING
elif _strategy == "best_effort":
return cls.BEST_EFFORT
else:
for member in cls:
if member.value == _strategy:
return member
return cls.DEFAULT

def __str__(self):
Expand Down
2 changes: 1 addition & 1 deletion src/slurm_plugin/resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class SlurmResumeConfig:
"create_fleet_overrides": "/opt/slurm/etc/pcluster/create_fleet_overrides.json",
"fleet_config_file": "/etc/parallelcluster/slurm_plugin/fleet-config.json",
"job_level_scaling": True,
"scaling_strategy": "all_or_nothing",
"scaling_strategy": "all-or-nothing",
}

def __init__(self, config_file_path):
Expand Down
28 changes: 27 additions & 1 deletion tests/slurm_plugin/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import pytest
from assertpy import assert_that
from common.utils import read_json, time_is_up
from slurm_plugin.common import TIMESTAMP_FORMAT, get_clustermgtd_heartbeat
from slurm_plugin.common import TIMESTAMP_FORMAT, get_clustermgtd_heartbeat, ScalingStrategy


@pytest.mark.parametrize(
Expand Down Expand Up @@ -106,3 +106,29 @@ def test_read_json(test_datadir, caplog, json_file, default_value, raises_except
assert_that(caplog.text).matches(message_in_log)
else:
assert_that(caplog.text).does_not_match("exception")


@pytest.mark.parametrize(
"strategy_as_value, expected_strategy_enum",
[
(
"best-effort",
ScalingStrategy.BEST_EFFORT
),
(
"all-or-nothing",
ScalingStrategy.ALL_OR_NOTHING
),
(
"",
ScalingStrategy.DEFAULT
),
(
"invalid-strategy",
ScalingStrategy.DEFAULT
),
]
)
def test_scaling_strategies_enum_from_value(strategy_as_value, expected_strategy_enum):
strategy_enum = ScalingStrategy(strategy_as_value)
assert_that(strategy_enum).is_equal_to(expected_strategy_enum)

0 comments on commit b995f81

Please sign in to comment.