|
19 | 19 |
|
20 | 20 | VPC_NAME = "sagemaker-python-sdk-test-vpc" |
21 | 21 | LOCK_PATH = os.path.join(tempfile.gettempdir(), "sagemaker_test_vpc_lock") |
| 22 | +LOCK_PATH_EFS = os.path.join(tempfile.gettempdir(), "sagemaker_efs_fsx_vpc_lock") |
22 | 23 |
|
23 | 24 |
|
24 | 25 | def _get_subnet_ids_by_name(ec2_client, name): |
@@ -64,7 +65,7 @@ def _route_table_id(ec2_client, vpc_id): |
64 | 65 |
|
65 | 66 | def check_or_create_vpc_resources_efs_fsx(sagemaker_session, name=VPC_NAME): |
66 | 67 | # use lock to prevent race condition when tests are running concurrently |
67 | | - with lock.lock(LOCK_PATH): |
| 68 | + with lock.lock(LOCK_PATH_EFS): |
68 | 69 | ec2_client = sagemaker_session.boto_session.client("ec2") |
69 | 70 |
|
70 | 71 | if _vpc_exists(ec2_client, name): |
@@ -121,7 +122,7 @@ def _create_vpc_with_name_efs_fsx(ec2_client, name): |
121 | 122 |
|
122 | 123 | def _create_vpc_resources(ec2_client, name): |
123 | 124 | vpc_id = ec2_client.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"]["VpcId"] |
124 | | - print("created vpc: {}".format(vpc_id)) |
| 125 | + ec2_client.create_tags(Resources=[vpc_id], Tags=[{"Key": "Name", "Value": name}]) |
125 | 126 |
|
126 | 127 | availability_zone_name = ec2_client.describe_availability_zones()["AvailabilityZones"][0][ |
127 | 128 | "ZoneName" |
@@ -163,30 +164,29 @@ def _create_vpc_resources(ec2_client, name): |
163 | 164 | ) |
164 | 165 |
|
165 | 166 | ec2_client.create_tags( |
166 | | - Resources=[vpc_id, subnet_id_a, subnet_id_b, security_group_id], |
| 167 | + Resources=[subnet_id_a, subnet_id_b, security_group_id], |
167 | 168 | Tags=[{"Key": "Name", "Value": name}], |
168 | 169 | ) |
169 | | - |
170 | 170 | return vpc_id, [subnet_id_a, subnet_id_b], security_group_id |
171 | 171 |
|
172 | 172 |
|
173 | | -def _create_vpc_with_name(ec2_client, region, name): |
| 173 | +def _create_vpc_with_name(ec2_client, name): |
174 | 174 | vpc_id, [subnet_id_a, subnet_id_b], security_group_id = _create_vpc_resources(ec2_client, name) |
175 | 175 | return [subnet_id_a, subnet_id_b], security_group_id |
176 | 176 |
|
177 | 177 |
|
178 | | -def get_or_create_vpc_resources(ec2_client, region, name=VPC_NAME): |
| 178 | +def get_or_create_vpc_resources(ec2_client): |
179 | 179 | # use lock to prevent race condition when tests are running concurrently |
180 | 180 | with lock.lock(LOCK_PATH): |
181 | | - if _vpc_exists(ec2_client, name): |
182 | | - print("using existing vpc: {}".format(name)) |
| 181 | + if _vpc_exists(ec2_client, VPC_NAME): |
| 182 | + print("using existing vpc: {}".format(VPC_NAME)) |
183 | 183 | return ( |
184 | | - _get_subnet_ids_by_name(ec2_client, name), |
185 | | - _get_security_id_by_name(ec2_client, name), |
| 184 | + _get_subnet_ids_by_name(ec2_client, VPC_NAME), |
| 185 | + _get_security_id_by_name(ec2_client, VPC_NAME), |
186 | 186 | ) |
187 | 187 | else: |
188 | | - print("creating new vpc: {}".format(name)) |
189 | | - return _create_vpc_with_name(ec2_client, region, name) |
| 188 | + print("creating new vpc: {}".format(VPC_NAME)) |
| 189 | + return _create_vpc_with_name(ec2_client, VPC_NAME) |
190 | 190 |
|
191 | 191 |
|
192 | 192 | def setup_security_group_for_encryption(ec2_client, security_group_id): |
|
0 commit comments