Skip to content

Commit b4718f8

Browse files
committed
vpc_tests
1 parent 4d94db1 commit b4718f8

File tree

3 files changed

+153
-1
lines changed

3 files changed

+153
-1
lines changed

tests/integration/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ def create_vpc_w_subnet():
215215
vpc_label,
216216
"--region",
217217
region,
218+
"--ipv6.range",
219+
"auto",
218220
"--subnets.ipv4",
219221
"10.0.0.0/24",
220222
"--subnets.label",
@@ -223,7 +225,7 @@ def create_vpc_w_subnet():
223225
"--suppress-warnings",
224226
]
225227
)
226-
)[0]
228+
)
227229

228230
return vpc_json
229231

tests/integration/vpc/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
@pytest.fixture
1414
def test_vpc_w_subnet():
1515
vpc_json = create_vpc_w_subnet()
16+
if isinstance(vpc_json, list):
17+
vpc_json = vpc_json[0]
1618
vpc_id = str(vpc_json["id"])
1719

1820
yield vpc_id
@@ -34,6 +36,8 @@ def test_vpc_wo_subnet():
3436
label,
3537
"--region",
3638
region,
39+
"--ipv6.range",
40+
"auto",
3741
"--no-headers",
3842
"--text",
3943
"--format=id",

tests/integration/vpc/test_vpc.py

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import re
23

34
import pytest
@@ -221,3 +222,148 @@ def test_fails_to_update_vpc_subenet_w_invalid_label(test_vpc_w_subnet):
221222

222223
assert "Request failed: 400" in res
223224
assert "Label must include only ASCII" in res
225+
226+
227+
def test_create_vpc_with_ipv6_auto():
228+
region = get_random_region_with_caps(required_capabilities=["VPCs"])
229+
label = get_random_text(5) + "-vpc"
230+
231+
res = exec_test_command(
232+
BASE_CMD
233+
+ [
234+
"create",
235+
"--label",
236+
label,
237+
"--region",
238+
region,
239+
"--ipv6.range",
240+
"auto",
241+
"--json",
242+
]
243+
)
244+
245+
vpc_data = json.loads(res)[0]
246+
247+
assert "id" in vpc_data
248+
assert "ipv6" in vpc_data
249+
assert isinstance(vpc_data["ipv6"], list)
250+
assert len(vpc_data["ipv6"]) > 0
251+
252+
ipv6_entry = vpc_data["ipv6"][0]
253+
assert "range" in ipv6_entry
254+
255+
256+
@pytest.mark.parametrize("prefix_len", ["52"])
257+
def test_create_vpc_with_custom_ipv6_prefix_length(prefix_len):
258+
region = get_random_region_with_caps(required_capabilities=["VPCs"])
259+
label = get_random_text(5) + f"-vpc{prefix_len}"
260+
261+
res = exec_test_command(
262+
BASE_CMD
263+
+ [
264+
"create",
265+
"--label",
266+
label,
267+
"--region",
268+
region,
269+
"--ipv6.range",
270+
f"/{prefix_len}",
271+
"--json",
272+
]
273+
)
274+
275+
vpc_data = json.loads(res)[0]
276+
277+
assert "ipv6" in vpc_data
278+
ipv6_entry = vpc_data["ipv6"][0]
279+
ipv6_range = ipv6_entry.get("range", "")
280+
assert isinstance(ipv6_range, str)
281+
assert ipv6_range.endswith(f"/{prefix_len}")
282+
283+
284+
def test_create_subnet_with_ipv6_auto(test_vpc_wo_subnet):
285+
vpc_id = test_vpc_wo_subnet
286+
subnet_label = get_random_text(5) + "-ipv6subnet"
287+
288+
res = exec_test_command(
289+
BASE_CMD
290+
+ [
291+
"subnet-create",
292+
"--label",
293+
subnet_label,
294+
"--ipv4",
295+
"10.0.10.0/24",
296+
"--ipv6.range",
297+
"auto",
298+
vpc_id,
299+
"--json",
300+
]
301+
)
302+
303+
subnet_data = json.loads(res)[0]
304+
305+
assert "id" in subnet_data
306+
assert (
307+
"ipv6" in subnet_data
308+
), f"No IPv6 info found in response: {subnet_data}"
309+
310+
ipv6_entries = subnet_data["ipv6"]
311+
assert (
312+
isinstance(ipv6_entries, list) and len(ipv6_entries) > 0
313+
), "Expected non-empty IPv6 list"
314+
315+
ipv6_range = ipv6_entries[0].get("range", "")
316+
assert isinstance(ipv6_range, str)
317+
assert "/" in ipv6_range, f"Unexpected IPv6 CIDR format: {ipv6_range}"
318+
assert (
319+
ipv6_range.startswith("2600:") or ipv6_range == "auto"
320+
), f"Unexpected IPv6 range value: {ipv6_range}"
321+
322+
323+
def test_fails_to_create_vpc_with_invalid_ipv6_range():
324+
region = get_random_region_with_caps(required_capabilities=["VPCs"])
325+
label = get_random_text(5) + "-invalidvpc"
326+
327+
res = exec_failing_test_command(
328+
BASE_CMD
329+
+ [
330+
"create",
331+
"--label",
332+
label,
333+
"--region",
334+
region,
335+
"--ipv6.range",
336+
"10.0.0.0/64",
337+
],
338+
ExitCodes.REQUEST_FAILED,
339+
)
340+
341+
assert "Request failed: 400" in res
342+
343+
344+
def test_list_vpc_ip_address():
345+
346+
res = exec_test_command(
347+
BASE_CMD + ["ips-all-list", "--text", "--delimiter=,"]
348+
)
349+
350+
lines = res.splitlines()
351+
352+
headers = ["address", "region", "subnet_id"]
353+
354+
for header in headers:
355+
assert header in lines[0]
356+
357+
358+
def test_list_vpc_ipv6s_address():
359+
360+
res = exec_test_command(
361+
BASE_CMD + ["ipv6s-all-list", "--text", "--delimiter=,"]
362+
)
363+
364+
lines = res.splitlines()
365+
366+
headers = ["address", "region", "subnet_id"]
367+
368+
for header in headers:
369+
assert header in lines[0]

0 commit comments

Comments
 (0)