|
49 | 49 |
|
50 | 50 | from cdpctl.validation.aws_utils import get_client |
51 | 51 | from cdpctl.validation.infra.validate_aws_subnets import ( |
| 52 | + aws_private_subnets_auto_assign_ip_validation, |
52 | 53 | aws_private_subnets_availablity_zone_validation, |
53 | 54 | aws_private_subnets_range_validation, |
54 | 55 | aws_private_subnets_route_validation, |
|
107 | 108 | { |
108 | 109 | "AvailabilityZone": "us-west-2b", |
109 | 110 | "CidrBlock": "20.0.237.0/14", |
| 111 | + "MapPublicIpOnLaunch": False, |
110 | 112 | "SubnetId": "subnet-prvtest1-cdp", |
111 | 113 | "VpcId": "vpc-testcdp12345", |
112 | 114 | "Tags": [ |
|
117 | 119 | { |
118 | 120 | "AvailabilityZone": "us-west-2c", |
119 | 121 | "CidrBlock": "20.1.238.0/19", |
| 122 | + "MapPublicIpOnLaunch": False, |
120 | 123 | "SubnetId": "subnet-prvtest2-cdp", |
121 | 124 | "VpcId": "vpc-testcdp12345", |
122 | 125 | "Tags": [ |
|
127 | 130 | { |
128 | 131 | "AvailabilityZone": "us-west-2a", |
129 | 132 | "CidrBlock": "20.2.236.0/18", |
| 133 | + "MapPublicIpOnLaunch": False, |
130 | 134 | "SubnetId": "subnet-prvtest3-cdp", |
131 | 135 | "VpcId": "vpc-testcdp12345", |
132 | 136 | "Tags": [ |
@@ -899,7 +903,7 @@ def test_aws_private_subnets_tags_validation_success(ec2_client: EC2Client) -> N |
899 | 903 | func() |
900 | 904 |
|
901 | 905 |
|
902 | | -def test_aws_private_subnets_tags_validation_failure(ec2_client: EC2Client) -> None: |
| 906 | +def test_aws_private_subnets_tags_validation_warning(ec2_client: EC2Client) -> None: |
903 | 907 | """Unit test private subnets tags failure.""" |
904 | 908 | config = get_config( |
905 | 909 | private_subnet_ids_val=private_subnet_ids, private_suffix_val="fail" |
@@ -941,6 +945,63 @@ def test_aws_private_subnets_tags_validation_failure(ec2_client: EC2Client) -> N |
941 | 945 | func() |
942 | 946 |
|
943 | 947 |
|
| 948 | +def test_aws_private_subnets_auto_assign_ip_validation_success( |
| 949 | + ec2_client: EC2Client, |
| 950 | +) -> None: |
| 951 | + """Unit test private subnets auto assign ip settings success.""" |
| 952 | + config = get_config( |
| 953 | + private_subnet_ids_val=private_subnet_ids, private_suffix_val="cdp" |
| 954 | + ) |
| 955 | + stubber = Stubber(ec2_client) |
| 956 | + stubber.add_response( |
| 957 | + "describe_subnets", |
| 958 | + sample_private_subnets_response, |
| 959 | + expected_params={"SubnetIds": private_subnet_ids}, |
| 960 | + ) |
| 961 | + with stubber: |
| 962 | + func = expect_validation_success(aws_private_subnets_validation) |
| 963 | + func(config, ec2_client) |
| 964 | + with stubber: |
| 965 | + func = expect_validation_success(aws_private_subnets_auto_assign_ip_validation) |
| 966 | + func() |
| 967 | + |
| 968 | + |
| 969 | +def test_aws_private_subnets_auto_assign_ip_validation_warning( |
| 970 | + ec2_client: EC2Client, |
| 971 | +) -> None: |
| 972 | + """Unit test private subnets auto assign ip settings failure.""" |
| 973 | + config = get_config( |
| 974 | + private_subnet_ids_val=private_subnet_ids, private_suffix_val="fail" |
| 975 | + ) |
| 976 | + stubber = Stubber(ec2_client) |
| 977 | + stubber.add_response( |
| 978 | + "describe_subnets", |
| 979 | + { |
| 980 | + "Subnets": [ |
| 981 | + { |
| 982 | + "MapPublicIpOnLaunch": False, |
| 983 | + "SubnetId": "subnet-prvtest1-cdp", |
| 984 | + }, |
| 985 | + { |
| 986 | + "MapPublicIpOnLaunch": False, |
| 987 | + "SubnetId": "subnet-prvtest2-cdp", |
| 988 | + }, |
| 989 | + { |
| 990 | + "MapPublicIpOnLaunch": True, |
| 991 | + "SubnetId": "subnet-prvtest3-cdp", |
| 992 | + }, |
| 993 | + ], |
| 994 | + }, |
| 995 | + expected_params={"SubnetIds": private_subnet_ids}, |
| 996 | + ) |
| 997 | + with stubber: |
| 998 | + func = expect_validation_success(aws_private_subnets_validation) |
| 999 | + func(config, ec2_client) |
| 1000 | + with stubber: |
| 1001 | + func = expect_validation_warning(aws_private_subnets_auto_assign_ip_validation) |
| 1002 | + func() |
| 1003 | + |
| 1004 | + |
944 | 1005 | def test_aws_vpc_validation_success(ec2_client: EC2Client) -> None: |
945 | 1006 | """Unit test vpc success.""" |
946 | 1007 | config = { |
|
0 commit comments