Skip to content

Commit e3521b9

Browse files
committed
[PCAPI][Test] Add integration test to validate PCAPI deployment with all custom parameters.
Signed-off-by: Giacomo Marciani <mgiacomo@amazon.com>
1 parent cb97660 commit e3521b9

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

tests/integration-tests/configs/develop.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,9 @@ test-suites:
761761
test_api_infrastructure.py::test_api_infrastructure_with_default_parameters:
762762
dimensions:
763763
- regions: ["ap-south-1", "cn-north-1", "us-gov-west-1"]
764+
test_api_infrastructure.py::test_api_infrastructure_with_full_parameters:
765+
dimensions:
766+
- regions: [ "eu-west-1" ]
764767
test_api.py::test_cluster_slurm:
765768
dimensions:
766769
- regions: ["sa-east-1"]

tests/integration-tests/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,14 @@ def api_definition_s3_uri(request, resource_bucket):
10091009
)
10101010

10111011

1012+
@pytest.fixture(scope="class")
1013+
def api_permissions_boundary_policy_arn(request, region):
1014+
"""Return the ARN of an IAM permissions boundary to be used with the ParallelCluster API."""
1015+
arn_partition = get_arn_partition(region)
1016+
# TODO Restrict the permissions boundary to the minimum set of required permissions
1017+
return f"arn:{arn_partition}:iam::aws:policy/AdministratorAccess"
1018+
1019+
10121020
@pytest.fixture(scope="session")
10131021
def api_infrastructure_s3_uri(request):
10141022
return request.config.getoption("api_infrastructure_s3_uri")

tests/integration-tests/tests/pcluster_api/test_api_infrastructure.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,56 @@ def api_with_default_settings(
6363
factory.delete_all_stacks()
6464

6565

66+
@pytest.fixture()
67+
def api_with_full_settings(
68+
api_infrastructure_s3_uri,
69+
api_definition_s3_uri,
70+
policies_uri,
71+
request,
72+
region,
73+
resource_bucket,
74+
api_permissions_boundary_policy_arn,
75+
):
76+
"""Deploy the ParallelCluster API infrastructure with all the stack parameters being set"""
77+
factory = CfnStacksFactory(request.config.getoption("credential"))
78+
79+
params = []
80+
if api_definition_s3_uri:
81+
params.append({"ParameterKey": "ApiDefinitionS3Uri", "ParameterValue": api_definition_s3_uri})
82+
if policies_uri:
83+
params.append({"ParameterKey": "PoliciesTemplateUri", "ParameterValue": policies_uri})
84+
if resource_bucket:
85+
params.append({"ParameterKey": "CustomBucket", "ParameterValue": resource_bucket})
86+
87+
params.append({"ParameterKey": "CreateApiUserRole", "ParameterValue": "true"})
88+
params.append({"ParameterKey": "EnableFSxS3Access", "ParameterValue": "true"})
89+
params.append({"ParameterKey": "EnableIamAdminAccess", "ParameterValue": "true"})
90+
params.append({"ParameterKey": "FsxS3Buckets", "ParameterValue": "*"})
91+
params.append({"ParameterKey": "IAMRoleAndPolicyPrefix", "ParameterValue": "abcdefghij"})
92+
params.append({"ParameterKey": "PermissionsBoundaryPolicy", "ParameterValue": api_permissions_boundary_policy_arn})
93+
params.append({"ParameterKey": "Region", "ParameterValue": region})
94+
95+
template = (
96+
api_infrastructure_s3_uri
97+
or f"https://{resource_bucket}.s3.{region}.amazonaws.com{'.cn' if region.startswith('cn') else ''}"
98+
f"/parallelcluster/{get_installed_parallelcluster_version()}/api/parallelcluster-api.yaml"
99+
)
100+
logging.info(f"Creating API Server stack in {region} with template {template}")
101+
stack = CfnStack(
102+
name=generate_stack_name("integ-tests-api", request.config.getoption("stackname_suffix")),
103+
region=region,
104+
parameters=params,
105+
capabilities=["CAPABILITY_NAMED_IAM", "CAPABILITY_AUTO_EXPAND"],
106+
template=template,
107+
)
108+
try:
109+
factory.create_stack(stack)
110+
yield stack
111+
finally:
112+
if not request.config.getoption("no_delete"):
113+
factory.delete_all_stacks()
114+
115+
66116
def test_api_infrastructure_with_default_parameters(region, api_with_default_settings):
67117
"""Test that creating the API Infrastructure stack with the defaults correctly sets up the Lambda and APIGateway API
68118
@@ -82,6 +132,27 @@ def test_api_infrastructure_with_default_parameters(region, api_with_default_set
82132
_test_api_deletion(api_with_default_settings)
83133

84134

135+
def test_api_infrastructure_with_full_parameters(region, api_with_full_settings):
136+
"""
137+
Test that creating the API Infrastructure stack with the all the parameters being set with custom values
138+
correctly sets up the Lambda and APIGateway API
139+
140+
:param region: the region where the stack is run
141+
:api_with_full_settings: factory that deploys a ParallelCluster API
142+
"""
143+
parallelcluster_lambda_name = api_with_full_settings.cfn_resources["ParallelClusterFunction"]
144+
parallelcluster_lambda_arn = api_with_full_settings.cfn_outputs["ParallelClusterLambdaArn"]
145+
146+
parallelcluster_api_id = api_with_full_settings.cfn_resources["ApiGatewayApiWithoutCustomDomain"]
147+
parallelcluster_api_url = api_with_full_settings.cfn_outputs["ParallelClusterApiInvokeUrl"]
148+
parallelcluster_user_role = api_with_full_settings.cfn_outputs["ParallelClusterApiUserRole"]
149+
150+
_assert_parallelcluster_lambda(lambda_name=parallelcluster_lambda_name, lambda_arn=parallelcluster_lambda_arn)
151+
_assert_parallelcluster_api(api_id=parallelcluster_api_id, api_url=parallelcluster_api_url)
152+
_test_auth(region, parallelcluster_user_role, parallelcluster_api_url)
153+
_test_api_deletion(api_with_full_settings)
154+
155+
85156
def _assert_parallelcluster_lambda(lambda_name, lambda_arn):
86157
"""Check that the ParallelCluster Lambda is correctly configured
87158

0 commit comments

Comments
 (0)