Skip to content

Commit 76f1a7a

Browse files
authored
VPC test related to Dual stack (#831)
1 parent 0b5b673 commit 76f1a7a

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed

tests/integration/conftest.py

Lines changed: 2 additions & 0 deletions
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",

tests/integration/vpc/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def test_vpc_wo_subnet():
3434
label,
3535
"--region",
3636
region,
37+
"--ipv6.range",
38+
"auto",
3739
"--no-headers",
3840
"--text",
3941
"--format=id",

tests/integration/vpc/test_vpc.py

Lines changed: 143 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,145 @@ 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+
319+
320+
def test_fails_to_create_vpc_with_invalid_ipv6_range():
321+
region = get_random_region_with_caps(required_capabilities=["VPCs"])
322+
label = get_random_text(5) + "-invalidvpc"
323+
324+
res = exec_failing_test_command(
325+
BASE_CMD
326+
+ [
327+
"create",
328+
"--label",
329+
label,
330+
"--region",
331+
region,
332+
"--ipv6.range",
333+
"10.0.0.0/64",
334+
],
335+
ExitCodes.REQUEST_FAILED,
336+
)
337+
338+
assert "Request failed: 400" in res
339+
340+
341+
def test_list_vpc_ip_address():
342+
343+
res = exec_test_command(
344+
BASE_CMD + ["ips-all-list", "--text", "--delimiter=,"]
345+
)
346+
347+
lines = res.splitlines()
348+
349+
headers = ["address", "region", "subnet_id"]
350+
351+
for header in headers:
352+
assert header in lines[0]
353+
354+
355+
def test_list_vpc_ipv6s_address():
356+
357+
res = exec_test_command(
358+
BASE_CMD + ["ipv6s-all-list", "--text", "--delimiter=,"]
359+
)
360+
361+
lines = res.splitlines()
362+
363+
headers = ["address", "region", "subnet_id"]
364+
365+
for header in headers:
366+
assert header in lines[0]

0 commit comments

Comments
 (0)