Skip to content

Commit

Permalink
[Test] Add options 'api-stack' and 'build-image-roles-stack'
Browse files Browse the repository at this point in the history
to let the test runner use an existing ParallelCluster API stack
and a build-image permissions stack, respectively.

Signed-off-by: Giacomo Marciani <[email protected]>
  • Loading branch information
gmarciani committed Jul 22, 2024
1 parent 2a2be29 commit fd5f10b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 32 deletions.
6 changes: 5 additions & 1 deletion tests/integration-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ usage: test_runner.py [-h] --key-name KEY_NAME --key-path KEY_PATH [-n PARALLELI
[--node-git-ref NODE_GIT_REF] [--ami-owner AMI_OWNER] [--benchmarks] [--benchmarks-target-capacity BENCHMARKS_TARGET_CAPACITY] [--benchmarks-max-time BENCHMARKS_MAX_TIME]
[--api-definition-s3-uri API_DEFINITION_S3_URI] [--api-infrastructure-s3-uri API_INFRASTRUCTURE_S3_URI] [--api-uri API_URI] [--policies-uri POLICIES_URI] [--vpc-stack VPC_STACK] [--cluster CLUSTER] [--lambda-layer-source LAMBDA_LAYER_SOURCE]
[--no-delete] [--retain-ad-stack] [--delete-logs-on-success] [--stackname-suffix STACKNAME_SUFFIX] [--dry-run] [--directory-stack-name DIRECTORY_STACK_NAME] [--ldaps-nlb-stack-name LDAPS_NLB_STACK_NAME] [--external-shared-storage-stack-name SHARED_STORAGE_STACK_NAME]
[--bucket-name BUCKET_NAME] [--proxy-stack PROXY_STACK_NAME]
[--bucket-name BUCKET_NAME] [--proxy-stack PROXY_STACK_NAME] [--build-image-roles-stack BUILD_IMAGE_ROLES_STACK_NAME] [--api-stack API_STACK_NAME]
Run integration tests suite.
Expand Down Expand Up @@ -178,6 +178,10 @@ Debugging/Development options:
Name of an existing bucket. (default: None)
--proxy-stack
Name of an existing proxy stack. (default: None)
--build-image-roles-stack
Name of CFN stack providing the build image permissions. (default: None)
--api-stack
Name of CFN stack providing the ParallelCluster API infrastructure. (default: None)
```

Here is an example of tests submission:
Expand Down
76 changes: 45 additions & 31 deletions tests/integration-tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ def pytest_addoption(parser):
"--proxy-stack",
help="Name of CFN stack providing a Proxy environment.",
)
parser.addoption(
"--build-image-roles-stack",
help="Name of CFN stack providing the build image permissions.",
)
parser.addoption(
"--api-stack",
help="Name of CFN stack providing the ParallelCluster API infrastructure.",
)


def pytest_generate_tests(metafunc):
Expand Down Expand Up @@ -420,38 +428,44 @@ def api_server_factory(
api_servers = {}

def _api_server_factory(server_region):
api_stack_name = generate_stack_name("integ-tests-api", request.config.getoption("stackname_suffix"))

params = [
{"ParameterKey": "EnableIamAdminAccess", "ParameterValue": "true"},
{"ParameterKey": "CreateApiUserRole", "ParameterValue": "false"},
]
if api_definition_s3_uri:
params.append({"ParameterKey": "ApiDefinitionS3Uri", "ParameterValue": api_definition_s3_uri})
if policies_uri:
params.append({"ParameterKey": "PoliciesTemplateUri", "ParameterValue": policies_uri})
if resource_bucket:
params.append({"ParameterKey": "CustomBucket", "ParameterValue": resource_bucket})

template = (
api_infrastructure_s3_uri
or f"https://{resource_bucket}.s3.{server_region}.amazonaws.com"
f"{'.cn' if server_region.startswith('cn') else ''}"
f"/parallelcluster/{get_installed_parallelcluster_version()}/api/parallelcluster-api.yaml"
)
if server_region not in api_servers:
logging.info(f"Creating API Server stack: {api_stack_name} in {server_region} with template {template}")
stack = CfnStack(
name=api_stack_name,
region=server_region,
parameters=params,
capabilities=["CAPABILITY_NAMED_IAM", "CAPABILITY_AUTO_EXPAND"],
template=template,
)
cfn_stacks_factory.create_stack(stack)
api_servers[server_region] = stack
option = "api_stack"
if request.config.getoption(option):
api_stack_name = request.config.getoption(option)
logging.info(f"Using existing ParallelCluster API stack in {server_region}: {api_stack_name}")
api_servers[server_region] = CfnStack(name=api_stack_name, region=server_region, template=None)
else:
logging.info(f"Found cached API Server stack: {api_stack_name} in {server_region}")
api_stack_name = generate_stack_name("integ-tests-api", request.config.getoption("stackname_suffix"))

params = [
{"ParameterKey": "EnableIamAdminAccess", "ParameterValue": "true"},
{"ParameterKey": "CreateApiUserRole", "ParameterValue": "false"},
]
if api_definition_s3_uri:
params.append({"ParameterKey": "ApiDefinitionS3Uri", "ParameterValue": api_definition_s3_uri})
if policies_uri:
params.append({"ParameterKey": "PoliciesTemplateUri", "ParameterValue": policies_uri})
if resource_bucket:
params.append({"ParameterKey": "CustomBucket", "ParameterValue": resource_bucket})

template = (
api_infrastructure_s3_uri
or f"https://{resource_bucket}.s3.{server_region}.amazonaws.com"
f"{'.cn' if server_region.startswith('cn') else ''}"
f"/parallelcluster/{get_installed_parallelcluster_version()}/api/parallelcluster-api.yaml"
)
if server_region not in api_servers:
logging.info(f"Creating API Server stack: {api_stack_name} in {server_region} with template {template}")
stack = CfnStack(
name=api_stack_name,
region=server_region,
parameters=params,
capabilities=["CAPABILITY_NAMED_IAM", "CAPABILITY_AUTO_EXPAND"],
template=template,
)
cfn_stacks_factory.create_stack(stack)
api_servers[server_region] = stack
else:
logging.info(f"Found cached API Server stack: {api_stack_name} in {server_region}")

return api_servers[server_region]

Expand Down
18 changes: 18 additions & 0 deletions tests/integration-tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"api_uri": None,
"cluster": None,
"policies_uri": None,
"api_stack": None,
"api_definition_s3_uri": None,
"api_infrastructure_s3_uri": None,
"no_delete": False,
Expand Down Expand Up @@ -99,6 +100,7 @@
"retain_ad_stack": False,
"global_build_number": 0,
"proxy_stack": None,
"build_image_roles_stack": None,
}


Expand Down Expand Up @@ -461,6 +463,16 @@ def _init_argparser():
help="Name of CFN stack providing a Proxy environment.",
default=TEST_DEFAULTS.get("proxy_stack"),
)
debug_group.add_argument(
"--build-image-roles-stack",
help="Name of CFN stack providing build image permissions.",
default=TEST_DEFAULTS.get("build_image_roles_stack"),
)
debug_group.add_argument(
"--api-stack",
help="Name of CFN stack providing the ParallelCluster API infrastructure.",
default=TEST_DEFAULTS.get("api_stack"),
)

return parser

Expand Down Expand Up @@ -685,6 +697,12 @@ def _set_custom_stack_args(args, pytest_args): # noqa: C901
if args.proxy_stack:
pytest_args.extend(["--proxy-stack", args.proxy_stack])

if args.build_image_roles_stack:
pytest_args.extend(["--build-image-roles-stack", args.build_image_roles_stack])

if args.api_stack:
pytest_args.extend(["--api-stack", args.api_stack])


def _set_validate_instance_type_args(args, pytest_args):
if args.force_elastic_ip:
Expand Down

0 comments on commit fd5f10b

Please sign in to comment.