Skip to content

Commit ae87438

Browse files
Improve integration test to test capacity reservation update without instance type specified
1 parent a3cc362 commit ae87438

File tree

3 files changed

+203
-3
lines changed

3 files changed

+203
-3
lines changed

tests/integration-tests/tests/capacity_reservations/test_on_demand_capacity_reservation.py

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied.
1111
# See the License for the specific language governing permissions and limitations under the License.
1212
import logging
13+
import os
14+
import subprocess
1315

1416
import boto3
1517
import pytest
1618
from assertpy import assert_that
17-
from utils import describe_cluster_instances, retrieve_cfn_resources
19+
from utils import describe_cluster_instances, retrieve_cfn_resources, wait_for_computefleet_changed
1820

1921

2022
@pytest.mark.usefixtures("os", "region")
@@ -40,7 +42,50 @@ def test_on_demand_capacity_reservation(
4042
pg_capacity_reservation_id=odcr_resources["integTestsPgOdcr"],
4143
pg_capacity_reservation_arn=resource_group_arn,
4244
)
43-
cluster = clusters_factory(cluster_config)
45+
46+
# Apply patch to the repo
47+
logging.info("Applying patch to the repository")
48+
repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../.."))
49+
s3_bucket_file = os.path.join(repo_root, "cli/src/pcluster/models/s3_bucket.py")
50+
51+
# Backup the original file
52+
with open(s3_bucket_file, "r") as f:
53+
original_content = f.read()
54+
55+
try:
56+
# Apply the patch - inject the bug that replaces capacity reservation IDs
57+
with open(s3_bucket_file, "r") as f:
58+
content = f.read()
59+
60+
# Add the bug injection line after the upload_config method definition
61+
modified_content = content.replace(
62+
" def upload_config(self, config, config_name, format=S3FileFormat.YAML):\n"
63+
' """Upload config file to S3 bucket."""',
64+
" def upload_config(self, config, config_name, format=S3FileFormat.YAML):\n"
65+
' """Upload config file to S3 bucket."""\n'
66+
' if config_name == "cluster-config.yaml":\n'
67+
" config = re.sub(r'cr-[0-9a-f]{17}', 'cr-11111111111111111', config)",
68+
)
69+
70+
# Write the modified content back
71+
with open(s3_bucket_file, "w") as f:
72+
f.write(modified_content)
73+
74+
# Install the CLI
75+
logging.info("Installing CLI from local repository")
76+
subprocess.run(["pip", "install", "./cli"], cwd=repo_root, check=True)
77+
78+
# Create the cluster
79+
cluster = clusters_factory(cluster_config)
80+
finally:
81+
# Revert the patch by restoring the original file
82+
logging.info("Reverting patch from the repository")
83+
with open(s3_bucket_file, "w") as f:
84+
f.write(original_content)
85+
86+
# Reinstall the CLI
87+
logging.info("Reinstalling CLI from local repository")
88+
subprocess.run(["pip", "install", "./cli"], cwd=repo_root, check=True)
4489

4590
_assert_instance_in_capacity_reservation(cluster, region, "open-odcr-id-cr", odcr_resources["integTestsOpenOdcr"])
4691
_assert_instance_in_capacity_reservation(cluster, region, "open-odcr-arn-cr", odcr_resources["integTestsOpenOdcr"])
@@ -64,6 +109,19 @@ def test_on_demand_capacity_reservation(
64109
)
65110
_assert_instance_in_capacity_reservation(cluster, region, "pg-odcr-id-cr", odcr_resources["integTestsPgOdcr"])
66111
_assert_instance_in_capacity_reservation(cluster, region, "pg-odcr-arn-cr", odcr_resources["integTestsPgOdcr"])
112+
cluster.stop()
113+
wait_for_computefleet_changed(cluster, "STOPPED")
114+
updated_config_file = pcluster_config_reader(
115+
config_file="pcluster.config.update.yaml",
116+
placement_group=placement_group_stack.cfn_resources["PlacementGroup"],
117+
open_capacity_reservation_id=odcr_resources["integTestsOpenOdcr"],
118+
open_capacity_reservation_arn=resource_group_arn,
119+
target_capacity_reservation_id=odcr_resources["integTestsTargetOdcr"],
120+
target_capacity_reservation_arn=resource_group_arn,
121+
pg_capacity_reservation_id=odcr_resources["integTestsPgOdcr"],
122+
pg_capacity_reservation_arn=resource_group_arn,
123+
)
124+
cluster.update(str(updated_config_file))
67125

68126

69127
def _assert_instance_in_capacity_reservation(cluster, region, compute_resource_name, expected_reservation):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
Image:
2+
Os: {{ os }}
3+
HeadNode:
4+
InstanceType: r5.xlarge
5+
Networking:
6+
SubnetId: {{ public_subnet_id }}
7+
Ssh:
8+
KeyName: {{ key_name }}
9+
Scheduling:
10+
Scheduler: slurm
11+
SlurmQueues:
12+
- Name: open-odcr-q
13+
ComputeResources:
14+
- Name: open-odcr-id-cr
15+
InstanceType: m5.2xlarge
16+
MinCount: 0
17+
MaxCount: 1
18+
CapacityReservationTarget:
19+
CapacityReservationId: {{ open_capacity_reservation_id }}
20+
- Name: open-odcr-arn-cr
21+
InstanceType: m5.2xlarge
22+
MinCount: 0
23+
MaxCount: 1
24+
CapacityReservationTarget:
25+
CapacityReservationResourceGroupArn: {{ open_capacity_reservation_arn }}
26+
- Name: open-odcr-arn-fl-cr
27+
Instances:
28+
- InstanceType: m5.2xlarge
29+
MinCount: 0
30+
MaxCount: 1
31+
CapacityReservationTarget:
32+
CapacityReservationResourceGroupArn: {{ open_capacity_reservation_arn }}
33+
- Name: open-odcr-id-pg-cr
34+
InstanceType: m5.2xlarge
35+
MinCount: 0
36+
MaxCount: 1
37+
Networking:
38+
PlacementGroup:
39+
Enabled: true
40+
CapacityReservationTarget:
41+
CapacityReservationId: {{ open_capacity_reservation_id }}
42+
- Name: open-odcr-arn-pg-cr
43+
InstanceType: m5.2xlarge
44+
MinCount: 0
45+
MaxCount: 1
46+
Networking:
47+
PlacementGroup:
48+
Enabled: true
49+
CapacityReservationTarget:
50+
CapacityReservationResourceGroupArn: {{ open_capacity_reservation_arn }}
51+
- Name: open-odcr-arn-pg-fl-cr
52+
Instances:
53+
- InstanceType: m5.2xlarge
54+
MinCount: 0
55+
MaxCount: 1
56+
Networking:
57+
PlacementGroup:
58+
Enabled: true
59+
CapacityReservationTarget:
60+
CapacityReservationResourceGroupArn: {{ open_capacity_reservation_arn }}
61+
Networking:
62+
SubnetIds:
63+
- {{ public_subnet_id }}
64+
- Name: target-odcr-q
65+
ComputeResources:
66+
- Name: target-odcr-id-cr
67+
InstanceType: r5.xlarge
68+
MinCount: 0
69+
MaxCount: 1
70+
CapacityReservationTarget:
71+
CapacityReservationId: {{ target_capacity_reservation_id }}
72+
- Name: target-odcr-arn-cr
73+
InstanceType: r5.xlarge
74+
MinCount: 0
75+
MaxCount: 1
76+
CapacityReservationTarget:
77+
CapacityReservationResourceGroupArn: {{ target_capacity_reservation_arn }}
78+
- Name: target-odcr-arn-fl-cr
79+
Instances:
80+
- InstanceType: r5.xlarge
81+
MinCount: 0
82+
MaxCount: 1
83+
CapacityReservationTarget:
84+
CapacityReservationResourceGroupArn: {{ target_capacity_reservation_arn }}
85+
- Name: target-odcr-id-pg-cr
86+
InstanceType: r5.xlarge
87+
MinCount: 0
88+
MaxCount: 1
89+
Networking:
90+
PlacementGroup:
91+
Enabled: true
92+
CapacityReservationTarget:
93+
CapacityReservationId: {{ target_capacity_reservation_id }}
94+
- Name: target-odcr-arn-pg-cr
95+
InstanceType: r5.xlarge
96+
MinCount: 0
97+
MaxCount: 1
98+
CapacityReservationTarget:
99+
CapacityReservationResourceGroupArn: {{ target_capacity_reservation_arn }}
100+
- Name: target-odcr-arn-pg-fl-cr
101+
Instances:
102+
- InstanceType: r5.xlarge
103+
MinCount: 0
104+
MaxCount: 1
105+
CapacityReservationTarget:
106+
CapacityReservationResourceGroupArn: {{ target_capacity_reservation_arn }}
107+
Networking:
108+
SubnetIds:
109+
- {{ public_subnet_id }}
110+
- Name: pg-odcr-q
111+
ComputeResources:
112+
- Name: pg-odcr-id-cr
113+
InstanceType: m5.xlarge
114+
MinCount: 0
115+
MaxCount: 1
116+
Networking:
117+
PlacementGroup:
118+
Name: {{ placement_group }}
119+
CapacityReservationTarget:
120+
CapacityReservationId: {{ pg_capacity_reservation_id }}
121+
- Name: pg-odcr-arn-cr
122+
InstanceType: m5.xlarge
123+
MinCount: 0
124+
MaxCount: 1
125+
Networking:
126+
PlacementGroup:
127+
Name: {{ placement_group }}
128+
CapacityReservationTarget:
129+
CapacityReservationResourceGroupArn: {{ pg_capacity_reservation_arn }}
130+
- Name: pg-odcr-arn-fleet-cr
131+
Instances:
132+
- InstanceType: m5.xlarge
133+
MinCount: 0
134+
MaxCount: 1
135+
Networking:
136+
PlacementGroup:
137+
Name: {{ placement_group }}
138+
CapacityReservationTarget:
139+
CapacityReservationResourceGroupArn: {{ pg_capacity_reservation_arn }}
140+
Networking:
141+
SubnetIds:
142+
- {{ public_subnet_id }}
143+

tests/integration-tests/tests/capacity_reservations/test_on_demand_capacity_reservation/test_on_demand_capacity_reservation/pcluster.config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Scheduling:
1212
- Name: open-odcr-q
1313
ComputeResources:
1414
- Name: open-odcr-id-cr
15-
InstanceType: m5.2xlarge
1615
MinCount: 1
1716
MaxCount: 1
1817
CapacityReservationTarget:

0 commit comments

Comments
 (0)