|
21 | 21 | from assertpy import assert_that
|
22 | 22 | from benchmarks.common.util import get_instance_vcpus
|
23 | 23 | from botocore.config import Config
|
| 24 | +from cfn_stacks_factory import CfnStack |
24 | 25 | from clusters_factory import Cluster, ClustersFactory
|
25 | 26 | from pcluster_client import ApiException
|
26 | 27 | from pcluster_client.api import (
|
@@ -519,11 +520,56 @@ def test_official_images(region, api_client):
|
519 | 520 | assert_that(response.images).is_not_empty()
|
520 | 521 |
|
521 | 522 |
|
| 523 | +@pytest.fixture(scope="class") |
| 524 | +def build_image_roles_stack(region, request, cfn_stacks_factory): |
| 525 | + """Set up and tear down a CloudFormation stack to deploy IAM resources used by build-image.""" |
| 526 | + stack_template_path = "../iam_policies/image-roles.cfn.yaml" |
| 527 | + with open(stack_template_path) as stack_template: |
| 528 | + if request.config.getoption("build_image_roles_stack"): |
| 529 | + logging.info( |
| 530 | + "Using an existing build-image roles stack {0} in region {1}".format( |
| 531 | + request.config.getoption("build_image_roles_stack"), region |
| 532 | + ) |
| 533 | + ) |
| 534 | + stack = CfnStack( |
| 535 | + name=request.config.getoption("build_image_roles_stack"), |
| 536 | + region=region, |
| 537 | + template=stack_template.read(), |
| 538 | + ) |
| 539 | + else: |
| 540 | + stack_name = generate_stack_name( |
| 541 | + "integ-tests-build-image-roles", request.config.getoption("stackname_suffix") |
| 542 | + ) |
| 543 | + stack_parameters = [] |
| 544 | + capabilities = ["CAPABILITY_IAM"] |
| 545 | + tags = [{"Key": "parallelcluster:integ-tests-stack", "Value": "build-image"}] |
| 546 | + stack = CfnStack( |
| 547 | + name=stack_name, |
| 548 | + region=region, |
| 549 | + template=stack_template.read(), |
| 550 | + parameters=stack_parameters, |
| 551 | + capabilities=capabilities, |
| 552 | + tags=tags, |
| 553 | + ) |
| 554 | + |
| 555 | + cfn_stacks_factory.create_stack(stack) |
| 556 | + |
| 557 | + yield stack |
| 558 | + |
| 559 | + if not request.config.getoption("no_delete") and not request.config.getoption("build_image_roles_stack"): |
| 560 | + cfn_stacks_factory.delete_stack(stack.name, region) |
| 561 | + |
| 562 | + |
522 | 563 | @pytest.mark.usefixtures("instance")
|
523 |
| -def test_custom_image(region, api_client, build_image, os, request, pcluster_config_reader): |
| 564 | +def test_custom_image(region, api_client, build_image, os, request, pcluster_config_reader, build_image_roles_stack): |
524 | 565 | base_ami = retrieve_latest_ami(region, os)
|
| 566 | + cleanup_lambda_role = build_image_roles_stack.cfn_outputs["BuildImageLambdaCleanupRole"] |
525 | 567 |
|
526 |
| - config_file = pcluster_config_reader(config_file="image.config.yaml", parent_image=base_ami) |
| 568 | + config_file = pcluster_config_reader( |
| 569 | + config_file="image.config.yaml", |
| 570 | + parent_image=base_ami, |
| 571 | + cleanup_lambda_role=cleanup_lambda_role, |
| 572 | + ) |
527 | 573 | with open(config_file, encoding="utf-8") as config_file:
|
528 | 574 | config = config_file.read()
|
529 | 575 |
|
|
0 commit comments