|
12 | 12 | import datetime |
13 | 13 | import json |
14 | 14 | import logging |
| 15 | +import os |
15 | 16 | import re |
16 | 17 | import tarfile |
17 | 18 | import tempfile |
@@ -51,6 +52,52 @@ class ImageNotFound(Exception): |
51 | 52 | pass |
52 | 53 |
|
53 | 54 |
|
| 55 | +@pytest.fixture(scope="class") |
| 56 | +def no_internet_proxy_stack(region, request, cfn_stacks_factory): |
| 57 | + """Deploy a VPC with a proxy that only allows OS repo access and VPC endpoints for AWS services.""" |
| 58 | + proxy_template_path = os.path.join(os.path.dirname(__file__), "test_createami", "test_build_image_no_internet", "proxy_stack.yaml") |
| 59 | + with open(proxy_template_path) as f: |
| 60 | + template = f.read() |
| 61 | + |
| 62 | + stack = CfnStack( |
| 63 | + name=generate_stack_name("integ-tests-build-image-no-internet", request.config.getoption("stackname_suffix")), |
| 64 | + region=region, |
| 65 | + template=template, |
| 66 | + parameters=[{"ParameterKey": "Keypair", "ParameterValue": request.config.getoption("key_name")}], |
| 67 | + capabilities=["CAPABILITY_IAM"], |
| 68 | + ) |
| 69 | + cfn_stacks_factory.create_stack(stack) |
| 70 | + yield stack |
| 71 | + if not request.config.getoption("no_delete"): |
| 72 | + cfn_stacks_factory.delete_stack(stack.name, region) |
| 73 | + |
| 74 | + |
| 75 | +@pytest.mark.usefixtures("instance") |
| 76 | +def test_build_image_no_internet( |
| 77 | + region, |
| 78 | + os, |
| 79 | + instance, |
| 80 | + pcluster_config_reader, |
| 81 | + architecture, |
| 82 | + no_internet_proxy_stack, |
| 83 | + images_factory, |
| 84 | + request, |
| 85 | +): |
| 86 | + """Test build image in a private subnet with no internet access, only VPC endpoints and a proxy for OS repos.""" |
| 87 | + base_ami = retrieve_latest_ami(region, os, architecture=architecture) |
| 88 | + |
| 89 | + image_id = generate_stack_name("integ-tests-build-image-no-internet", request.config.getoption("stackname_suffix")) |
| 90 | + image_config = pcluster_config_reader( |
| 91 | + config_file="image.config.yaml", |
| 92 | + parent_image=base_ami, |
| 93 | + subnet_id=no_internet_proxy_stack.cfn_outputs["PrivateSubnetId"], |
| 94 | + security_group_id=no_internet_proxy_stack.cfn_outputs["DefaultSecurityGroupId"], |
| 95 | + ) |
| 96 | + |
| 97 | + image = images_factory(image_id, image_config, region) |
| 98 | + _test_build_image_success(image) |
| 99 | + |
| 100 | + |
54 | 101 | @pytest.mark.usefixtures("instance") |
55 | 102 | def test_invalid_config( |
56 | 103 | region, |
|
0 commit comments