Skip to content

Commit 8469467

Browse files
Weird test race to investigate tomorrow :)
1 parent c30ac02 commit 8469467

File tree

3 files changed

+164
-4
lines changed

3 files changed

+164
-4
lines changed

linode_api4/objects/linode.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ class InterfaceGeneration(StrEnum):
671671
class UpgradeInterfacesResult(JSONObject):
672672
dry_run: bool = False
673673
config_id: int = 0
674-
interfaces: List[ConfigInterface] = field(default_factory=list)
674+
interfaces: List[LinodeInterface] = field(default_factory=list)
675675

676676

677677
class Instance(Base):
@@ -1963,7 +1963,7 @@ def upgrade_interfaces(
19631963
:returns: Information about the newly upgraded interfaces.
19641964
:rtype: UpgradeInterfacesResult
19651965
"""
1966-
params = {"config_id": config, dry_run: dry_run}
1966+
params = {"config_id": config, "dry_run": dry_run}
19671967

19681968
result = self._client.post(
19691969
"{}/upgrade-interfaces".format(Instance.api_endpoint),
@@ -1974,14 +1974,14 @@ def upgrade_interfaces(
19741974
self.invalidate()
19751975

19761976
# We don't convert interface dicts to LinodeInterface objects on dry runs
1977-
# actual API entities aren't created
1977+
# actual API entities aren't created.
19781978
if dry_run:
19791979
result["interfaces"] = [
19801980
MappedObject(**iface) for iface in result["interfaces"]
19811981
]
19821982
else:
19831983
result["interfaces"] = [
1984-
LinodeInterface(self._client, self.id, iface["id"], iface)
1984+
LinodeInterface(self._client, iface["id"], self.id, iface)
19851985
for iface in result["interfaces"]
19861986
]
19871987

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"dry_run": true,
3+
"config_id": 123,
4+
"interfaces": [
5+
{
6+
"created": "2025-01-01T00:01:01",
7+
"default_route": {
8+
"ipv4": true,
9+
"ipv6": true
10+
},
11+
"id": 123,
12+
"mac_address": "22:00:AB:CD:EF:01",
13+
"public": {
14+
"ipv4": {
15+
"addresses": [
16+
{
17+
"address": "172.30.0.50",
18+
"primary": true
19+
}
20+
],
21+
"shared": [
22+
{
23+
"address": "172.30.0.51",
24+
"linode_id": 125
25+
}
26+
]
27+
},
28+
"ipv6": {
29+
"ranges": [
30+
{
31+
"range": "2600:3cO9:e001:59::/64",
32+
"route_target": "2600:3cO9::ff:feab:cdef"
33+
},
34+
{
35+
"range": "2600:3cO9:e001:5a::/64",
36+
"route_target": "2600:3cO9::ff:feab:cdef"
37+
}
38+
],
39+
"shared": [
40+
{
41+
"range": "2600:3cO9:e001:2a::/64",
42+
"route_target": null
43+
}
44+
],
45+
"slaac": [
46+
{
47+
"address": "2600:3cO9::ff:feab:cdef",
48+
"prefix": 64
49+
}
50+
]
51+
}
52+
},
53+
"updated": "2025-01-01T00:01:01",
54+
"version": 1,
55+
"vlan": null,
56+
"vpc": null
57+
},
58+
{
59+
"id": 456,
60+
"mac_address": "22:00:AB:CD:EF:01",
61+
"created": "2024-01-01T00:01:01",
62+
"updated": "2024-01-01T00:01:01",
63+
"default_route": {
64+
"ipv4": true
65+
},
66+
"version": 1,
67+
"vpc": {
68+
"vpc_id": 123456,
69+
"subnet_id": 789,
70+
"ipv4": {
71+
"addresses": [
72+
{
73+
"address": "192.168.22.3",
74+
"primary": true
75+
}
76+
],
77+
"ranges": [
78+
{
79+
"range": "192.168.22.16/28"
80+
},
81+
{
82+
"range": "192.168.22.32/28"
83+
}
84+
]
85+
}
86+
},
87+
"public": null,
88+
"vlan": null
89+
},
90+
{
91+
"id": 789,
92+
"mac_address": "22:00:AB:CD:EF:01",
93+
"created": "2024-01-01T00:01:01",
94+
"updated": "2024-01-01T00:01:01",
95+
"default_route": {},
96+
"version": 1,
97+
"vpc": null,
98+
"public": null,
99+
"vlan": {
100+
"vlan_label": "my_vlan",
101+
"ipam_address": "10.0.0.1/24"
102+
}
103+
}
104+
]
105+
}

test/unit/objects/linode_test.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,61 @@ def test_update_interfaces_settings(self):
523523
},
524524
}
525525

526+
def test_upgrade_interfaces(self):
527+
# Local import to avoid circular dependency
528+
from linode_interface_test import ( # pylint: disable=import-outside-toplevel
529+
LinodeInterfaceTest,
530+
)
531+
532+
instance = Instance(self.client, 124)
533+
534+
with self.mock_post("/linode/instances/124/upgrade-interfaces") as m:
535+
result = instance.upgrade_interfaces(123)
536+
537+
assert m.called
538+
assert m.call_data == {"config_id": 123, "dry_run": False}
539+
540+
assert result.config_id == 123
541+
assert result.dry_run
542+
543+
# We don't use the assertion helpers here because dry runs return
544+
# a MappedObject.
545+
LinodeInterfaceTest.assert_linode_124_interface_123(
546+
result.interfaces[0]
547+
)
548+
LinodeInterfaceTest.assert_linode_124_interface_456(
549+
result.interfaces[1]
550+
)
551+
LinodeInterfaceTest.assert_linode_124_interface_789(
552+
result.interfaces[2]
553+
)
554+
555+
def test_upgrade_interfaces_dry(self):
556+
instance = Instance(self.client, 124)
557+
558+
with self.mock_post("/linode/instances/124/upgrade-interfaces") as m:
559+
result = instance.upgrade_interfaces(123, dry_run=True)
560+
561+
assert m.called
562+
assert m.call_data == {
563+
"config_id": 123,
564+
"dry_run": True,
565+
}
566+
567+
assert result.config_id == 123
568+
assert result.dry_run
569+
570+
# We don't use the assertion helpers here because dry runs return
571+
# a MappedObject.
572+
assert result.interfaces[0].id == 123
573+
assert result.interfaces[0].public is not None
574+
575+
assert result.interfaces[1].id == 456
576+
assert result.interfaces[1].vpc is not None
577+
578+
assert result.interfaces[2].id == 789
579+
assert result.interfaces[2].vlan is not None
580+
526581

527582
class DiskTest(ClientBaseCase):
528583
"""

0 commit comments

Comments
 (0)