Skip to content

Commit 513c5c8

Browse files
More tests
1 parent 445beb6 commit 513c5c8

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

linode_api4/objects/linode_interfaces.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,21 @@ class LinodeInterface(DerivedBase):
350350
"""
351351
A Linode's network interface.
352352
353+
NOTE: When using the ``save()`` method, certain local fields with computed values will
354+
not be refreshed on the local object until after ``invalidate()`` has been called::
355+
356+
# Automatically assign an IPv4 address from the associated VPC Subnet
357+
interface.vpc.ipv4.addresses[0].address = "auto"
358+
359+
# Save the interface
360+
interface.save()
361+
362+
# Invalidate the interface
363+
interface.invalidate()
364+
365+
# Access the new address
366+
print(interface.vpc.ipv4.addresses[0].address)
367+
353368
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-linode-interface
354369
"""
355370

test/integration/models/linode/interfaces/test_interfaces.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
from linode_api4 import (
8+
ApiError,
89
Instance,
910
InterfaceGeneration,
1011
LinodeInterface,
@@ -338,6 +339,44 @@ def test_linode_interface_create_vpc(linode_interface_vpc):
338339
assert iface.vpc.ipv4.ranges[0].range.split("/")[1] == "29"
339340

340341

342+
def test_linode_interface_update_vpc(linode_interface_vpc):
343+
iface, instance, vpc, subnet = linode_interface_vpc
344+
345+
iface.vpc.subnet_id = 0
346+
347+
try:
348+
iface.save()
349+
except ApiError:
350+
pass
351+
else:
352+
raise Exception("Expected error when updating subnet_id to 0")
353+
354+
iface.invalidate()
355+
356+
old_ipv4 = copy.deepcopy(iface.vpc.ipv4)
357+
358+
iface.vpc.ipv4.addresses[0].address = "auto"
359+
iface.vpc.ipv4.ranges += [
360+
LinodeInterfaceVPCIPv4RangeOptions(
361+
range="/32",
362+
)
363+
]
364+
365+
iface.save()
366+
iface.invalidate()
367+
368+
address = iface.vpc.ipv4.addresses[0]
369+
assert ipaddress.ip_address(address.address)
370+
371+
range = iface.vpc.ipv4.ranges[0]
372+
assert ipaddress.ip_network(range.range)
373+
assert range.range == old_ipv4.ranges[0].range
374+
375+
range = iface.vpc.ipv4.ranges[1]
376+
assert ipaddress.ip_network(range.range)
377+
assert range.range != old_ipv4.ranges[0].range
378+
379+
341380
def test_linode_interface_create_vlan(
342381
linode_interface_vlan,
343382
):

0 commit comments

Comments
 (0)