Skip to content

Commit fbab7ef

Browse files
Fix backups attempted update on non-editable last_successful (#748)
1 parent e35b61d commit fbab7ef

3 files changed

Lines changed: 65 additions & 1 deletion

File tree

‎linode_api4/objects/linode.py‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,42 @@ class UpgradeInterfacesResult(JSONObject):
790790
)
791791

792792

793+
@dataclass
794+
class InstanceBackupSchedule(JSONObject):
795+
"""
796+
InstanceBackupSchedule represents when automatic backups of a Linode Instance are taken.
797+
"""
798+
799+
include_none_values = True
800+
801+
day: Optional[str] = None
802+
window: Optional[str] = None
803+
804+
805+
@dataclass
806+
class InstanceBackupsOptions(JSONObject):
807+
"""
808+
InstanceBackupsOptions is used to update the backup settings of a Linode Instance.
809+
"""
810+
811+
enabled: bool = False
812+
schedule: Optional[InstanceBackupSchedule] = None
813+
814+
815+
@dataclass
816+
class InstanceBackups(JSONObject):
817+
"""
818+
InstanceBackups represents the backup settings and status of a Linode Instance.
819+
"""
820+
821+
put_class = InstanceBackupsOptions
822+
823+
enabled: bool = False
824+
available: bool = False
825+
schedule: Optional[InstanceBackupSchedule] = None
826+
last_successful: Optional[str] = None
827+
828+
793829
class Instance(Base):
794830
"""
795831
A Linode Instance.
@@ -811,7 +847,7 @@ class Instance(Base):
811847
"disks": Property(derived_class=Disk),
812848
"configs": Property(derived_class=Config),
813849
"type": Property(slug_relationship=Type),
814-
"backups": Property(mutable=True),
850+
"backups": Property(mutable=True, json_object=InstanceBackups),
815851
"ipv4": Property(unordered=True),
816852
"ipv6": Property(),
817853
"hypervisor": Property(),

‎test/fixtures/linode_instances.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"label": "linode123",
2020
"backups": {
2121
"enabled": true,
22+
"available": true,
23+
"last_successful": "2018-01-01T00:01:01",
2224
"schedule": {
2325
"window": "W02",
2426
"day": "Scheduling"

‎test/unit/objects/linode_test.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
Disk,
2727
Image,
2828
Instance,
29+
InstanceBackups,
30+
InstanceBackupSchedule,
2931
StackScript,
3032
Type,
3133
VPCSubnet,
@@ -59,6 +61,14 @@ def test_get_linode(self):
5961
self.assertEqual(linode.lke_cluster_id, None)
6062
self.assertEqual(linode.maintenance_policy, "linode/migrate")
6163

64+
self.assertIsInstance(linode.backups, InstanceBackups)
65+
self.assertTrue(linode.backups.enabled)
66+
self.assertTrue(linode.backups.available)
67+
self.assertEqual(linode.backups.last_successful, "2018-01-01T00:01:01")
68+
self.assertIsInstance(linode.backups.schedule, InstanceBackupSchedule)
69+
self.assertEqual(linode.backups.schedule.day, "Scheduling")
70+
self.assertEqual(linode.backups.schedule.window, "W02")
71+
6272
json = linode._raw_json
6373
self.assertIsNotNone(json)
6474
self.assertEqual(json["id"], 123)
@@ -229,6 +239,22 @@ def test_update_linode(self):
229239
},
230240
)
231241

242+
def test_update_linode_backups_disabled(self):
243+
"""
244+
Tests that an unset backup schedule is sent as explicit nulls
245+
"""
246+
with self.mock_put("linode/instances/456") as m:
247+
linode = self.client.load(Instance, 456)
248+
linode.save()
249+
250+
self.assertEqual(
251+
m.call_data["backups"],
252+
{
253+
"enabled": False,
254+
"schedule": {"day": None, "window": None},
255+
},
256+
)
257+
232258
def test_delete_linode(self):
233259
"""
234260
Tests that deleting a Linode creates the correct api request

0 commit comments

Comments
 (0)