-
Notifications
You must be signed in to change notification settings - Fork 87
TPT-4285: Implement integration tests for ReservedIP for IPv4 #688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: proj/reserved-ips
Are you sure you want to change the base?
Changes from all commits
bf13f2e
8985109
2f35543
8a07407
1c63131
ccd3020
799f113
3d70ecc
7da867a
6ee4d06
5a98989
a56bf1e
3f0838a
3930e05
f24e2af
f058877
bb5fabe
09bf1d0
6a6afc9
5d57dc1
f88bff4
155d377
42bd110
2a630ae
b52e666
b9ca4cf
9e68fea
d910f89
9f9610e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,16 @@ | ||
| import copy | ||
| import ipaddress | ||
| from test.integration.helpers import get_test_label | ||
|
|
||
| import pytest | ||
|
|
||
| from linode_api4 import ( | ||
| ApiError, | ||
| Instance, | ||
| InterfaceGeneration, | ||
| LinodeInterface, | ||
| LinodeInterfaceDefaultRouteOptions, | ||
| LinodeInterfaceOptions, | ||
| LinodeInterfacePublicIPv4AddressOptions, | ||
| LinodeInterfacePublicIPv4Options, | ||
| LinodeInterfacePublicIPv6Options, | ||
|
|
@@ -18,9 +21,54 @@ | |
| LinodeInterfaceVPCIPv4Options, | ||
| LinodeInterfaceVPCIPv4RangeOptions, | ||
| LinodeInterfaceVPCOptions, | ||
| ReservedIPAddress, | ||
| ) | ||
|
|
||
|
|
||
| def build_interface_public_ipv4(firewall, ip_address): | ||
| return LinodeInterfaceOptions( | ||
| firewall_id=firewall, | ||
| default_route=LinodeInterfaceDefaultRouteOptions( | ||
| ipv4=True, | ||
| ), | ||
| public=LinodeInterfacePublicOptions( | ||
| ipv4=LinodeInterfacePublicIPv4Options( | ||
| addresses=[ | ||
| LinodeInterfacePublicIPv4AddressOptions( | ||
| address=ip_address, primary=True | ||
| ) | ||
| ], | ||
| ), | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| def create_linode_with_legacy_config(client, ip_address, label, firewall): | ||
| linode, _ = client.linode.instance_create( | ||
| "g6-nanode-1", | ||
| ip_address.region, | ||
| image="linode/debian12", | ||
| label=label, | ||
| firewall=firewall, | ||
| interface_generation=InterfaceGeneration.LEGACY_CONFIG, | ||
| ipv4=[ip_address.address], | ||
| ) | ||
| return linode | ||
|
|
||
|
|
||
| def create_linode_with_standard_interfaces(client, ip_address, label, firewall): | ||
| interface = build_interface_public_ipv4(firewall.id, ip_address.address) | ||
| linode, _ = client.linode.instance_create( | ||
| "g6-nanode-1", | ||
| ip_address.region, | ||
| image="linode/debian12", | ||
| label=label, | ||
| interface_generation=InterfaceGeneration.LINODE, | ||
| interfaces=[interface], | ||
| ) | ||
| return linode | ||
|
|
||
|
|
||
| def test_linode_create_with_linode_interfaces( | ||
| create_vpc_with_subnet, | ||
| linode_with_linode_interfaces, | ||
|
|
@@ -359,3 +407,39 @@ def test_linode_interface_firewalls(e2e_test_firewall, linode_interface_public): | |
| firewall = firewalls[0] | ||
| assert firewall.id == e2e_test_firewall.id | ||
| assert firewall.label == e2e_test_firewall.label | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "create_linode_fn", | ||
| [create_linode_with_legacy_config, create_linode_with_standard_interfaces], | ||
| ids=["legacy_config", "standard_interfaces"], | ||
| ) | ||
| def test_linode_interfaces_with_reserved_ips( | ||
| test_linode_client, e2e_test_firewall, create_reserved_ip, create_linode_fn | ||
| ): | ||
| client = test_linode_client | ||
| reserved_ip = create_reserved_ip | ||
| label = get_test_label(length=8) | ||
|
|
||
| linode = create_linode_fn(client, reserved_ip, label, e2e_test_firewall) | ||
|
|
||
| linode_ips = linode.ips.ipv4.public | ||
| assert len(linode_ips) == 1 | ||
| assert linode_ips[0].address == reserved_ip.address | ||
| assert linode_ips[0].reserved == True | ||
| assert linode_ips[0].linode_id == linode.id | ||
| assert linode_ips[0].assigned_entity.id == linode.id | ||
| assert linode_ips[0].assigned_entity.type == "linode" | ||
| assert linode_ips[0].assigned_entity.label == linode.label | ||
| assert ( | ||
| linode_ips[0].assigned_entity.url == f"/v4/linode/instances/{linode.id}" | ||
| ) | ||
|
|
||
| linode.delete() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use fixture pattern to ensure the Linode is deleted even if the test failed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @zliang-akamai , in this case Does it make sense?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that will work too I think.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And I am wondering if we can implement a context manager for use case like this. (optional, but it's something fun in Python world) |
||
| reserved_ips_list = client.networking.reserved_ips( | ||
| ReservedIPAddress.address == reserved_ip.address | ||
| ) | ||
| assert len(reserved_ips_list) == 1 | ||
| assert reserved_ips_list[0].reserved == True | ||
| assert reserved_ips_list[0].linode_id is None | ||
| assert reserved_ips_list[0].assigned_entity is None | ||
Uh oh!
There was an error while loading. Please reload this page.