|
16 | 16 | LinodeInterfacePublicIPv6RangeOptions, |
17 | 17 | LinodeInterfacePublicOptions, |
18 | 18 | LinodeInterfaceVLANOptions, |
19 | | - LinodeInterfaceVPCOptions, |
| 19 | + LinodeInterfaceVPCOptions, LinodeInterfaceVPCIPv4Options, LinodeInterfaceVPCIPv4AddressOptions, |
| 20 | + LinodeInterfaceVPCIPv4Range, |
| 21 | + LinodeInterfaceVPCIPv4RangeOptions, |
20 | 22 | ) |
21 | 23 |
|
22 | 24 |
|
23 | | -@pytest.fixture(scope="function") |
| 25 | + |
| 26 | +@pytest.fixture |
24 | 27 | def instance_with_interface_generation_linode( |
25 | | - test_linode_client, e2e_test_firewall |
| 28 | + test_linode_client, |
| 29 | + e2e_test_firewall, |
| 30 | + |
| 31 | + # We won't be using this all the time, but it's |
| 32 | + # necessary for certain consumers of this fixture |
| 33 | + create_vpc_with_subnet |
26 | 34 | ): |
27 | 35 | client = test_linode_client |
28 | 36 |
|
29 | 37 | label = get_test_label() |
30 | 38 |
|
31 | 39 | instance = client.linode.instance_create( |
32 | 40 | "g6-nanode-1", |
33 | | - get_region(test_linode_client, {"Linode Interfaces"}, site_type="core"), |
| 41 | + create_vpc_with_subnet[0].region, |
34 | 42 | label=label, |
35 | 43 | interface_generation=InterfaceGeneration.LINODE, |
36 | 44 | ) |
@@ -215,3 +223,58 @@ def test_linode_interface_create_public( |
215 | 223 | assert iface.public.ipv6.slaac[0].address == instance.ipv6.split("/")[0] |
216 | 224 | assert iface.public.ipv6.slaac[0].prefix == 64 |
217 | 225 | assert len(iface.public.ipv6.shared) == 0 |
| 226 | + |
| 227 | +def test_linode_interface_create_vpc( |
| 228 | + test_linode_client, |
| 229 | + e2e_test_firewall, |
| 230 | + create_vpc_with_subnet, |
| 231 | + instance_with_interface_generation_linode, |
| 232 | +): |
| 233 | + instance: Instance = instance_with_interface_generation_linode |
| 234 | + vpc, subnet = create_vpc_with_subnet |
| 235 | + subnet_network = ipaddress.ip_network(subnet.ipv4) |
| 236 | + |
| 237 | + print(vars(subnet)) |
| 238 | + |
| 239 | + # + 10 is an arbitrary offset because the subnet fixture is session scoped. |
| 240 | + subnet_allocated_ip = next(v for i, v in enumerate(subnet_network.hosts()) if v == 10) |
| 241 | + |
| 242 | + ipv6_range = test_linode_client.networking.ipv6_range_allocate( |
| 243 | + 64, linode=instance.id |
| 244 | + ) |
| 245 | + |
| 246 | + iface = instance.interface_create( |
| 247 | + firewall_id=e2e_test_firewall.id, |
| 248 | + default_route=LinodeInterfaceDefaultRouteOptions( |
| 249 | + ipv4=True, |
| 250 | + ), |
| 251 | + vpc=LinodeInterfaceVPCOptions( |
| 252 | + subnet_id=subnet.id, |
| 253 | + ipv4=LinodeInterfaceVPCIPv4Options( |
| 254 | + addresses=[ |
| 255 | + LinodeInterfaceVPCIPv4AddressOptions( |
| 256 | + address=str(subnet_allocated_ip), |
| 257 | + primary=True, |
| 258 | + nat_1_1_address="any", |
| 259 | + ) |
| 260 | + ], |
| 261 | + ranges=[ |
| 262 | + LinodeInterfaceVPCIPv4RangeOptions( |
| 263 | + range=str(subnet_allocated_ip) + "/32", |
| 264 | + ) |
| 265 | + ] |
| 266 | + ) |
| 267 | + ), |
| 268 | + ) |
| 269 | + |
| 270 | + assert iface.id is not None |
| 271 | + assert iface.linode_id == instance.id |
| 272 | + |
| 273 | + assert iface.created is not None |
| 274 | + assert iface.updated is not None |
| 275 | + |
| 276 | + assert isinstance(iface.mac_address, str) |
| 277 | + assert iface.version |
| 278 | + |
| 279 | + assert iface.default_route.ipv4 |
| 280 | + assert not iface.default_route.ipv6 |
0 commit comments