|
| 1 | +import ipaddress |
| 2 | +import json |
1 | 3 | import re |
2 | 4 |
|
3 | 5 | import pytest |
4 | 6 |
|
5 | 7 | from linodecli.exit_codes import ExitCodes |
6 | 8 | from tests.integration.helpers import ( |
7 | 9 | BASE_CMDS, |
| 10 | + delete_target_id, |
8 | 11 | exec_failing_test_command, |
9 | 12 | exec_test_command, |
10 | 13 | ) |
11 | 14 |
|
12 | 15 |
|
| 16 | +def nodebalancer_created(): |
| 17 | + return "[0-9]+,balancer[0-9]+,us-ord,[0-9]+-[0-9]+-[0-9]+-[0-9]+.ip.linodeusercontent.com,0" |
| 18 | + |
| 19 | + |
13 | 20 | def test_fail_to_create_nodebalancer_without_region(): |
14 | 21 | result = exec_failing_test_command( |
15 | 22 | BASE_CMDS["nodebalancers"] |
@@ -537,5 +544,77 @@ def test_view_node_for_node_balancer_udp_configuration( |
537 | 544 | ) |
538 | 545 |
|
539 | 546 |
|
540 | | -def nodebalancer_created(): |
541 | | - return "[0-9]+,balancer[0-9]+,us-ord,[0-9]+-[0-9]+-[0-9]+-[0-9]+.ip.linodeusercontent.com,0" |
| 547 | +def test_nb_with_backend_vpc_only(get_vpc_with_subnet): |
| 548 | + vpc = get_vpc_with_subnet |
| 549 | + |
| 550 | + nb_attrs = exec_test_command( |
| 551 | + BASE_CMDS["nodebalancers"] |
| 552 | + + [ |
| 553 | + "create", |
| 554 | + "--region", |
| 555 | + vpc["region"], |
| 556 | + "--backend_vpcs.subnet_id", |
| 557 | + str(vpc["subnets"][0]["id"]), |
| 558 | + "--text", |
| 559 | + "--delimiter", |
| 560 | + ",", |
| 561 | + "--no-headers", |
| 562 | + ] |
| 563 | + ).split(",") |
| 564 | + |
| 565 | + assert isinstance(ipaddress.ip_address(nb_attrs[5]), ipaddress.IPv4Address) |
| 566 | + assert isinstance(ipaddress.ip_address(nb_attrs[6]), ipaddress.IPv6Address) |
| 567 | + assert nb_attrs[-2] == "public" |
| 568 | + assert nb_attrs[-1] == "" |
| 569 | + |
| 570 | + nb_vpcs = exec_test_command( |
| 571 | + BASE_CMDS["nodebalancers"] |
| 572 | + + [ |
| 573 | + "vpcs-list", |
| 574 | + nb_attrs[0], |
| 575 | + "--json", |
| 576 | + ] |
| 577 | + ) |
| 578 | + nb_vpcs = json.loads(nb_vpcs) |
| 579 | + |
| 580 | + assert len(nb_vpcs) == 1 |
| 581 | + assert nb_vpcs[0]["purpose"] == "backend" |
| 582 | + |
| 583 | + nb_vpc = exec_test_command( |
| 584 | + BASE_CMDS["nodebalancers"] |
| 585 | + + [ |
| 586 | + "vpc-view", |
| 587 | + nb_attrs[0], |
| 588 | + str(nb_vpcs[0]["id"]), |
| 589 | + "--json", |
| 590 | + ] |
| 591 | + ) |
| 592 | + nb_vpc = json.loads(nb_vpc) |
| 593 | + |
| 594 | + assert nb_vpc[0]["purpose"] == "backend" |
| 595 | + |
| 596 | + # TODO: Uncomment when API implementation of /backend_vpcs and /frontend_vpcs endpoints is finished |
| 597 | + # nb_backend_vpcs = exec_test_command( |
| 598 | + # BASE_CMDS["nodebalancers"] |
| 599 | + # + [ |
| 600 | + # "backend_vpcs-list", |
| 601 | + # nb_attrs[0], |
| 602 | + # "--json", |
| 603 | + # ] |
| 604 | + # ) |
| 605 | + # nb_backend_vpcs = json.loads(nb_backend_vpcs) |
| 606 | + # assert len(nb_backend_vpcs) == 1 |
| 607 | + # assert nb_backend_vpcs[0]["purpose"] == "backend" |
| 608 | + # |
| 609 | + # nb_frontend_vpcs = exec_test_command( |
| 610 | + # BASE_CMDS["nodebalancers"] |
| 611 | + # + [ |
| 612 | + # "frontend_vpcs-list", |
| 613 | + # nb_attrs[0], |
| 614 | + # "--json", |
| 615 | + # ] |
| 616 | + # ) |
| 617 | + # nb_frontend_vpcs = json.loads(nb_frontend_vpcs) |
| 618 | + # assert len(nb_frontend_vpcs) == 0 |
| 619 | + |
| 620 | + delete_target_id(target="nodebalancers", id=nb_attrs[0]) |
0 commit comments