Skip to content

Commit ef2996d

Browse files
Enrico Usaidemartinofra
authored andcommitted
Add logic to cleanup pcluster_config into the convert utility
Before of this patch we were cleaning up the config_parser only when executin the pcluster configure utility. By adding the prepare_to_file function we're sure to have the pcluster_config ready to be written in the file. ## Conversion logic When a default is equal to default should not be written in the file. It means: disable_hyperthreading = false, initial_count = min_count and min_count = 0 Instead enable_efa in the queue will be always written because the default is None ## Tests Improved unit tests by covering all the enable_efa and dysable_hyperthreading cases. Signed-off-by: Enrico Usai <[email protected]>
1 parent 304fd6c commit ef2996d

File tree

11 files changed

+34
-35
lines changed

11 files changed

+34
-35
lines changed

cli/pcluster/config/hit_converter.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class HitConverter:
2525
def __init__(self, pcluster_config):
2626
self.pcluster_config = pcluster_config
2727

28-
def convert(self):
28+
def convert(self, prepare_to_file=False):
2929
"""
3030
Convert the pcluster_config instance from pre-HIT to HIT configuration model.
3131
@@ -138,6 +138,9 @@ def convert(self):
138138
self.pcluster_config.auto_refresh = auto_refresh
139139

140140
self.clean_config_parser(hit_cluster_section)
141+
if prepare_to_file:
142+
self._prepare_to_file()
143+
141144
LOGGER.debug("Conversion to HIT completed successfully.")
142145
conversion_done = True
143146

@@ -147,6 +150,28 @@ def _copy_param_value(self, old_param, new_param, new_value=None):
147150
"""Copy the value from the old param to the new one."""
148151
new_param.value = new_value if new_value is not None else old_param.value
149152

153+
@staticmethod
154+
def _reset_config_params(section, parameters_to_remove):
155+
for param_key in parameters_to_remove:
156+
param = section.get_param(param_key)
157+
param.value = param.get_default_value()
158+
159+
def _prepare_to_file(self):
160+
"""Reset some parameters from config file since their values can be inferred at runtime."""
161+
# disable_hyperthreading will get its value from cluster section
162+
queue_section = self.pcluster_config.get_section("queue", "compute")
163+
self._reset_config_params(queue_section, ["disable_hyperthreading"])
164+
165+
# Remove initial_count if not needed
166+
compute_section = self.pcluster_config.get_section("compute_resource", "default")
167+
if compute_section.get_param_value("initial_count") == compute_section.get_param_value("min_count"):
168+
self._reset_config_params(compute_section, ["initial_count"])
169+
170+
# cluster's disable_hyperthreading's HIT default is None instead of False
171+
cluster_section = self.pcluster_config.get_section("cluster")
172+
if not cluster_section.get_param_value("disable_hyperthreading"):
173+
self._reset_config_params(cluster_section, ["disable_hyperthreading"])
174+
150175
def _store_original_sections(self):
151176
"""
152177
Store original default sections from configuration.

cli/pcluster/configure/easyconfig.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def configure(args):
186186
param.value = param.get_value_from_string(param_value)
187187

188188
# Convert file if needed
189-
_convert_config(pcluster_config)
189+
HitConverter(pcluster_config).convert(prepare_to_file=True)
190190

191191
# Update config file by overriding changed settings
192192
pcluster_config.to_file()
@@ -318,28 +318,6 @@ def _prompt_for_subnet(default_subnet, all_subnets, qualified_subnets, message):
318318
return prompt_iterable(message, qualified_subnets, default_value=default_subnet)
319319

320320

321-
def _convert_config(pcluster_config):
322-
"""Convert the generated SIT configuration to HIT model if scheduler is Slurm."""
323-
if pcluster_config.cluster_model == ClusterModel.SIT:
324-
HitConverter(pcluster_config).convert()
325-
326-
if pcluster_config.cluster_model == ClusterModel.HIT:
327-
# Conversion occurred: reset some parameters from config file since their values can be inferred at runtime
328-
329-
# enable_efa and disable_hyperthreading will get their value from cluster section
330-
queue_section = pcluster_config.get_section("queue", "compute")
331-
_reset_config_params(queue_section, ("enable_efa", "disable_hyperthreading"))
332-
333-
# initial_count will take its value from min_count
334-
compute_resource_section = pcluster_config.get_section("compute_resource", "default")
335-
_reset_config_params(compute_resource_section, ["initial_count"])
336-
337-
# cluster's disable_hyperthreading's HIT default is None instead of False
338-
cluster_section = pcluster_config.get_section("cluster")
339-
if not cluster_section.get_param_value("disable_hyperthreading"):
340-
_reset_config_params(cluster_section, ["disable_hyperthreading"])
341-
342-
343321
class ClusterConfigureHelper:
344322
"""Handle prompts for cluster section."""
345323

cli/pcluster_config/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def convert(args=None):
8181
)
8282

8383
# Automatic SIT -> HIT conversion, if needed
84-
conversion_done, reason = HitConverter(pcluster_config).convert()
84+
conversion_done, reason = HitConverter(pcluster_config).convert(prepare_to_file=True)
8585
if conversion_done:
8686
if args.output_file:
8787
if os.path.isfile(args.output_file):

cli/tests/pcluster/configure/test_pcluster_configure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ def _assert_configurations_are_equal(path_config_expected, path_config_after_inp
334334
config_expected = ConfigParser()
335335
config_expected.read(path_config_expected)
336336
config_expected_dict = {s: dict(config_expected.items(s)) for s in config_expected.sections()}
337+
337338
config_actual = ConfigParser()
338339
config_actual.read(path_config_after_input)
339340
config_actual_dict = {s: dict(config_actual.items(s)) for s in config_actual.sections()}

cli/tests/pcluster/configure/test_pcluster_configure/test_vpc_automation_no_vpc_in_region/pcluster.config.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ compute_subnet_id = subnet-23456789
2424
use_public_ips = false
2525

2626
[queue compute]
27+
enable_efa = false
2728
compute_resource_settings = default
2829

2930
[compute_resource default]

cli/tests/pcluster/configure/test_pcluster_configure/test_vpc_automation_no_vpc_in_region_public/pcluster.config.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ vpc_id = vpc-12345678
2222
master_subnet_id = subnet-12345678
2323

2424
[queue compute]
25+
enable_efa = false
2526
compute_resource_settings = default
2627

2728
[compute_resource default]

cli/tests/pcluster/configure/test_pcluster_configure/test_with_input_no_automation_no_errors_with_config_file/pcluster.config.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ sanity_check = true
2424
ssh = ssh {CFN_USER}@{MASTER_IP} {ARGS}
2525

2626
[queue compute]
27+
enable_efa = false
2728
compute_resource_settings = default
2829

2930
[compute_resource default]

cli/tests/pcluster_config/test_pcluster_config_convert/test_slurm_sit_full/expected_output.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,16 @@ raid_settings = settings1
7878
fsx_settings = settings1
7979
additional_iam_policies = arn:aws:iam::aws:policy/CloudWatchFullAccess,arn:aws:iam::aws:policy/CloudWatchReadAccess
8080
queue_settings = compute
81-
disable_hyperthreading = false
8281

8382
[queue compute]
8483
compute_type = spot
8584
enable_efa = true
86-
disable_hyperthreading = false
8785
placement_group = DYNAMIC
8886
compute_resource_settings = default
8987

9088
[compute_resource default]
9189
instance_type = t2.large
9290
min_count = 1
9391
max_count = 2
94-
initial_count = 1
9592
spot_price = 5.0
9693

cli/tests/pcluster_config/test_pcluster_config_convert/test_slurm_sit_simple/expected_output.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,12 @@ shared_dir = /test
2222
vpc_settings = public
2323
additional_iam_policies = arn:aws:iam::aws:policy/CloudWatchFullAccess
2424
queue_settings = compute
25-
disable_hyperthreading = false
2625

2726
[queue compute]
2827
enable_efa = false
29-
disable_hyperthreading = false
3028
compute_resource_settings = default
3129

3230
[compute_resource default]
3331
instance_type = g4dn.12xlarge
3432
max_count = 100
35-
initial_count = 0
3633

cli/tests/pcluster_config/test_pcluster_config_convert/test_slurm_unrelated_sections/expected_output.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,15 @@ raid_settings = settings1
7878
fsx_settings = settings1
7979
additional_iam_policies = arn:aws:iam::aws:policy/CloudWatchFullAccess,arn:aws:iam::aws:policy/CloudWatchReadAccess
8080
queue_settings = compute
81-
disable_hyperthreading = false
8281

8382
[queue compute]
8483
compute_type = spot
8584
enable_efa = true
86-
disable_hyperthreading = false
8785
placement_group = DYNAMIC
8886
compute_resource_settings = default
8987

9088
[compute_resource default]
9189
instance_type = t2.large
92-
min_count = 1
9390
max_count = 2
9491
initial_count = 1
9592
spot_price = 5.0

0 commit comments

Comments
 (0)