|
1 | 1 | import ipaddress |
| 2 | +from test.integration.conftest import get_region |
2 | 3 | from test.integration.helpers import get_test_label |
3 | 4 |
|
4 | 5 | import pytest |
|
9 | 10 | LinodeInterface, |
10 | 11 | LinodeInterfaceDefaultRouteOptions, |
11 | 12 | LinodeInterfaceOptions, |
| 13 | + LinodeInterfacePublicIPv4AddressOptions, |
| 14 | + LinodeInterfacePublicIPv4Options, |
| 15 | + LinodeInterfacePublicIPv6Options, |
| 16 | + LinodeInterfacePublicIPv6RangeOptions, |
12 | 17 | LinodeInterfacePublicOptions, |
13 | 18 | LinodeInterfaceVLANOptions, |
14 | 19 | LinodeInterfaceVPCOptions, |
15 | 20 | ) |
16 | 21 |
|
17 | 22 |
|
| 23 | +@pytest.fixture(scope="function") |
| 24 | +def instance_with_interface_generation_linode( |
| 25 | + test_linode_client, e2e_test_firewall |
| 26 | +): |
| 27 | + client = test_linode_client |
| 28 | + |
| 29 | + label = get_test_label() |
| 30 | + |
| 31 | + instance, _ = client.linode.instance_create( |
| 32 | + "g6-nanode-1", |
| 33 | + get_region(test_linode_client, {"Linode Interfaces"}, site_type="core"), |
| 34 | + label=label, |
| 35 | + interface_generation=InterfaceGeneration.LINODE, |
| 36 | + ) |
| 37 | + |
| 38 | + yield instance |
| 39 | + |
| 40 | + instance.delete() |
| 41 | + |
| 42 | + |
18 | 43 | @pytest.fixture(scope="session") |
19 | | -def linode_create_with_interfaces( |
| 44 | +def instance_with_interfaces( |
20 | 45 | test_linode_client, e2e_test_firewall, create_vpc_with_subnet |
21 | 46 | ): |
22 | 47 | client = test_linode_client |
23 | 48 | vpc, subnet = create_vpc_with_subnet |
24 | 49 |
|
25 | | - # Are there regions where VPCs are supported but Linode Interfaces aren't |
| 50 | + # Are there regions where VPCs are supported but Linode Interfaces aren't? |
26 | 51 | region = vpc.region |
27 | 52 | label = get_test_label() |
28 | 53 |
|
@@ -61,9 +86,9 @@ def linode_create_with_interfaces( |
61 | 86 |
|
62 | 87 | def test_linode_create_with_linode_interfaces( |
63 | 88 | create_vpc_with_subnet, |
64 | | - linode_create_with_interfaces, |
| 89 | + instance_with_interfaces, |
65 | 90 | ): |
66 | | - instance: Instance = linode_create_with_interfaces |
| 91 | + instance: Instance = instance_with_interfaces |
67 | 92 | vpc, subnet = create_vpc_with_subnet |
68 | 93 |
|
69 | 94 | def __assert_base(iface: LinodeInterface): |
@@ -126,3 +151,55 @@ def __assert_vlan(iface: LinodeInterface): |
126 | 151 | __assert_public(instance.interfaces[0]) |
127 | 152 | __assert_vpc(instance.interfaces[1]) |
128 | 153 | __assert_vlan(instance.interfaces[2]) |
| 154 | + |
| 155 | + |
| 156 | +def test_linode_interface_create_public( |
| 157 | + e2e_test_firewall, |
| 158 | + instance_with_interface_generation_linode, |
| 159 | +): |
| 160 | + instance: Instance = instance_with_interface_generation_linode |
| 161 | + |
| 162 | + ip = instance.ip_allocate() |
| 163 | + instance |
| 164 | + |
| 165 | + iface = instance.interface_create( |
| 166 | + firewall_id=e2e_test_firewall.id, |
| 167 | + default_route=LinodeInterfaceDefaultRouteOptions( |
| 168 | + ipv4=True, |
| 169 | + ipv6=True, |
| 170 | + ), |
| 171 | + public=LinodeInterfacePublicOptions( |
| 172 | + ipv4=LinodeInterfacePublicIPv4Options( |
| 173 | + addresses=[ |
| 174 | + LinodeInterfacePublicIPv4AddressOptions( |
| 175 | + address=ip.address, |
| 176 | + primary=True, |
| 177 | + ) |
| 178 | + ] |
| 179 | + ), |
| 180 | + ipv6=LinodeInterfacePublicIPv6Options( |
| 181 | + ranges=[LinodeInterfacePublicIPv6RangeOptions()] |
| 182 | + ), |
| 183 | + ), |
| 184 | + ) |
| 185 | + |
| 186 | + assert iface.id is not None |
| 187 | + assert iface.linode_id == instance.id |
| 188 | + |
| 189 | + assert iface.created is not None |
| 190 | + assert iface.updated is not None |
| 191 | + |
| 192 | + assert isinstance(iface.mac_address, str) |
| 193 | + assert iface.version |
| 194 | + |
| 195 | + assert iface.default_route.ipv4 |
| 196 | + assert iface.default_route.ipv6 |
| 197 | + |
| 198 | + assert iface.public.ipv4.addresses[0].address == ip.address |
| 199 | + assert iface.public.ipv4.addresses[0].primary |
| 200 | + assert len(iface.public.ipv4.shared) == 0 |
| 201 | + |
| 202 | + assert iface.public.ipv6.slaac[0].address == instance.ipv6.split("/")[0] |
| 203 | + assert iface.public.ipv6.slaac[0].prefix == 64 |
| 204 | + assert len(iface.public.ipv6.shared) == 0 |
| 205 | + assert len(iface.public.ipv6.ranges) == 0 |
0 commit comments