Skip to content

Commit 087ec02

Browse files
Enrico Usaienrico-usai
authored andcommitted
Fix pcluster configure internal refresh flow
Before this patch the code was loading the configuration file by initializing `PclusterConfig` with `auto_refresh=True`. This setting means that the internal parameters must be recalculated every time there is a change in one of the internal sections. The issue was that the calculation of internal parameters was using the values from the initial config file and after that, the `pcluster configure` workflow wasn't changing internal sections (parameters only) so the auto-refresh wasn't triggered anymore. For this reason there was a piece of code to explicitly reload the config file again after changing the region. We don't need it anymore because I'm instead explicitly calling the `refresh` method. Then, in the `no_awsbatch_*_with_config_file" test we were wrongly expecting the `AWSBatchFullAccess` policy with `sge` scheduler(!). The test was clearly wrong and was hiding a wrong behaviour. Now we're executing the `refresh` command right after collecting all the inputs from the users, so the `additional_iam_policies` will contain the values related to the right scheduler (`sge`) and not the original one (`awsbatch`). We're also setting the `auto_refresh=True` before calling the `HitConverter.convert` because this method can change some internal sections so the internal parameters must be updated accordingly. This commit also fixes cases on which `refresh` method was called with default/initial values (e.g. t2.micro as instance type in regions on which this instance doesn't exist). Right now we're instead validating the values coming from the user. Signed-off-by: Enrico Usai <[email protected]>
1 parent f8e46ab commit 087ec02

File tree

8 files changed

+152
-6
lines changed

8 files changed

+152
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ CHANGELOG
7676
- Fix issue when the `cluster` section label changed.
7777
- Fix issue when `shared_dir` and `ebs_settings` are both configured in the `cluster` section.
7878
- Fix `cluster` and `cfncluster` compatibility in `extra_json` parameter.
79+
- Fix `pcluster configure` to avoid using default/initial values for internal parameter initialization.
7980
- Fix pre/post install script arguments management when using double quotes.
8081
- Fix a bug that was causing `clustermgtd` and `computemgtd` sleep interval to be incorrectly computed when
8182
system timezone is not set to UTC.

cli/pcluster/configure/easyconfig.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def configure(args):
118118
if args.config_file and os.path.exists(args.config_file) and not os.path.isfile(args.config_file):
119119
error("Invalid configuration file path: {0}".format(args.config_file))
120120

121-
pcluster_config = PclusterConfig(config_file=args.config_file, fail_on_error=False)
121+
pcluster_config = PclusterConfig(config_file=args.config_file, fail_on_error=False, auto_refresh=False)
122122

123123
# FIXME: Overriding HIT config files is currently not supported.
124124
if pcluster_config.cluster_model == ClusterModel.HIT:
@@ -141,10 +141,7 @@ def configure(args):
141141
default_region = pcluster_config.get_section("aws").get_param_value("aws_region_name")
142142
aws_region_name = prompt_iterable("AWS Region ID", available_regions, default_value=default_region)
143143
# Set provided region into os environment for suggestions and validations from here on
144-
if os.environ["AWS_DEFAULT_REGION"] != aws_region_name:
145-
os.environ["AWS_DEFAULT_REGION"] = aws_region_name
146-
# Read config file again, because region change can cause change of the initial values in PclusterConfig
147-
pcluster_config = PclusterConfig(config_file=args.config_file, fail_on_error=False)
144+
os.environ["AWS_DEFAULT_REGION"] = aws_region_name
148145
else:
149146
aws_region_name = args.region
150147

@@ -192,6 +189,10 @@ def configure(args):
192189
param = vpc_section.get_param(param_key)
193190
param.value = param.get_value_from_string(param_value)
194191

192+
# Update internal params according to provided parameters and enable auto-refresh before eventual hit conversion
193+
pcluster_config.refresh()
194+
pcluster_config.auto_refresh = True
195+
195196
# Convert file if needed
196197
HitConverter(pcluster_config).convert(prepare_to_file=True)
197198

cli/tests/pcluster/configure/test_pcluster_configure.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,31 @@ def test_region_env_overwrite_region_config(mocker, capsys, test_datadir):
504504
_run_input_test_with_config(mocker, config, old_config_file, error, output, capsys, with_input=False)
505505

506506

507+
def test_unexisting_instance_type(mocker, capsys, test_datadir):
508+
"""
509+
Test configuration file with wrong values that must be overridden by user inputs.
510+
511+
This test verifies that the validation steps are not performed with initial or default values
512+
(e.g. t2.micro as instance type in a region that doesn't support it).
513+
"""
514+
config, error, output = get_file_path(test_datadir)
515+
old_config_file = str(test_datadir / "original_config_file.ini")
516+
517+
MockHandler(mocker)
518+
519+
_run_input_test_with_config(
520+
mocker,
521+
config,
522+
old_config_file,
523+
error,
524+
output,
525+
capsys,
526+
with_input=True,
527+
master_instance="m6g.xlarge",
528+
compute_instance="m6g.xlarge",
529+
)
530+
531+
507532
def test_no_available_no_input_no_automation_no_errors_with_config_file(mocker, capsys, test_datadir):
508533
"""
509534
Testing easy config with user hitting return on all prompts.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ master_instance_type = t2.nano
1313
max_queue_size = 14
1414
initial_queue_size = 13
1515
maintain_initial_size = true
16-
additional_iam_policies = arn:aws:iam::aws:policy/AWSBatchFullAccess
1716

1817
[vpc default]
1918
vpc_id = vpc-12345678

cli/tests/pcluster/configure/test_pcluster_configure/test_unexisting_instance_type/error.txt

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[aws]
2+
aws_region_name = eu-west-1
3+
4+
[cluster default]
5+
key_name = key1
6+
base_os = ubuntu1604
7+
vpc_settings = default
8+
scheduler = slurm
9+
master_instance_type = WRONG-INSTANCE-TYPE
10+
compute_instance_type = WRONG-INSTANCE-TYPE
11+
max_queue_size = 14
12+
initial_queue_size = 13
13+
maintain_initial_size = true
14+
15+
[vpc default]
16+
vpc_id = vpc-12345678
17+
master_subnet_id = subnet-12345678
18+
compute_subnet_id = subnet-23456789
19+
20+
[global]
21+
cluster_template = default
22+
update_check = true
23+
sanity_check = true
24+
25+
[aliases]
26+
ssh = ssh {CFN_USER}@{MASTER_IP} {ARGS}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
WARNING: Configuration file {{ CONFIG_FILE }} will be overwritten.
2+
Press CTRL-C to interrupt the procedure.
3+
4+
5+
Allowed values for AWS Region ID:
6+
1. eu-north-1
7+
2. ap-south-1
8+
3. eu-west-3
9+
4. eu-west-2
10+
5. eu-west-1
11+
6. ap-northeast-2
12+
7. ap-northeast-1
13+
8. sa-east-1
14+
9. ca-central-1
15+
10. ap-southeast-1
16+
11. ap-southeast-2
17+
12. eu-central-1
18+
13. us-east-1
19+
14. us-east-2
20+
15. us-west-1
21+
16. us-west-2
22+
Allowed values for EC2 Key Pair Name:
23+
1. key1
24+
2. key2
25+
3. key3
26+
4. key4
27+
5. key5
28+
6. key6
29+
Allowed values for Scheduler:
30+
1. sge
31+
2. torque
32+
3. slurm
33+
4. awsbatch
34+
Allowed values for Operating System:
35+
1. alinux
36+
2. alinux2
37+
3. centos7
38+
4. centos8
39+
5. ubuntu1604
40+
6. ubuntu1804
41+
Allowed values for VPC ID:
42+
# id name number_of_subnets
43+
--- ------------ --------------------------------- -------------------
44+
1 vpc-12345678 ParallelClusterVPC-20190625135738 2
45+
2 vpc-23456789 ParallelClusterVPC-20190624105051 0
46+
3 vpc-34567891 default 3
47+
4 vpc-45678912 ParallelClusterVPC-20190626095403 1
48+
Allowed values for Master Subnet ID:
49+
# id name size availability_zone
50+
--- --------------- ------ ------ -------------------
51+
1 subnet-34567891 4096 eu-west-1b
52+
2 subnet-45678912 4096 eu-west-1a
53+
3 subnet-56789123 4096 eu-west-1c
54+
Allowed values for Compute Subnet ID:
55+
# id name size availability_zone
56+
--- --------------- ------ ------ -------------------
57+
1 subnet-34567891 4096 eu-west-1b
58+
2 subnet-45678912 4096 eu-west-1a
59+
3 subnet-56789123 4096 eu-west-1c
60+
Configuration file written to {{ CONFIG_FILE }}
61+
You can edit your configuration file or simply run 'pcluster create -c {{ CONFIG_FILE }} cluster-name' to create your cluster
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[aws]
2+
aws_region_name = us-east-1
3+
4+
[cluster default]
5+
key_name = key2
6+
base_os = ubuntu1604
7+
vpc_settings = default
8+
scheduler = slurm
9+
master_instance_type = m6g.xlarge
10+
queue_settings = compute
11+
12+
[vpc default]
13+
vpc_id = vpc-34567891
14+
master_subnet_id = subnet-34567891
15+
compute_subnet_id = subnet-45678912
16+
17+
[global]
18+
cluster_template = default
19+
update_check = true
20+
sanity_check = true
21+
22+
[aliases]
23+
ssh = ssh {CFN_USER}@{MASTER_IP} {ARGS}
24+
25+
[queue compute]
26+
enable_efa = false
27+
enable_efa_gdr = false
28+
compute_resource_settings = default
29+
30+
[compute_resource default]
31+
instance_type = m6g.xlarge
32+
min_count = 7
33+
max_count = 18

0 commit comments

Comments
 (0)