Skip to content

Commit 1cb5034

Browse files
committed
Add resource lock support for NodeBalancer
1 parent 7708f87 commit 1cb5034

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

linode_api4/objects/nodebalancer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ class NodeBalancer(Base):
252252
"transfer": Property(),
253253
"tags": Property(mutable=True, unordered=True),
254254
"client_udp_sess_throttle": Property(mutable=True),
255+
"locks": Property(unordered=True),
255256
}
256257

257258
# create derived objects

test/fixtures/nodebalancers.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"updated": "2018-01-01T00:01:01",
1111
"label": "balancer123456",
1212
"client_conn_throttle": 0,
13-
"tags": ["something"]
13+
"tags": ["something"],
14+
"locks": ["cannot_delete_with_subresources"]
1415
},
1516
{
1617
"created": "2018-01-01T00:01:01",
@@ -22,7 +23,8 @@
2223
"updated": "2018-01-01T00:01:01",
2324
"label": "balancer123457",
2425
"client_conn_throttle": 0,
25-
"tags": []
26+
"tags": [],
27+
"locks": []
2628
}
2729
],
2830
"results": 2,

test/fixtures/nodebalancers_123456.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
"client_conn_throttle": 0,
1111
"tags": [
1212
"something"
13+
],
14+
"locks": [
15+
"cannot_delete_with_subresources"
1316
]
1417
}

test/unit/objects/nodebalancers_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,24 @@ def test_update(self):
175175
},
176176
)
177177

178+
def test_locks_not_in_put(self):
179+
"""
180+
Test that locks are not included in PUT request when updating a NodeBalancer.
181+
Locks are managed through the separate /v4/locks endpoint.
182+
"""
183+
nb = NodeBalancer(self.client, 123456)
184+
# Access locks to ensure it's loaded
185+
self.assertEqual(nb.locks, ["cannot_delete_with_subresources"])
186+
187+
nb.label = "new-label"
188+
189+
with self.mock_put("nodebalancers/123456") as m:
190+
nb.save()
191+
self.assertEqual(m.call_url, "/nodebalancers/123456")
192+
# Verify locks is NOT in the PUT data
193+
self.assertNotIn("locks", m.call_data)
194+
self.assertEqual(m.call_data["label"], "new-label")
195+
178196
def test_firewalls(self):
179197
"""
180198
Test that you can get the firewalls for the requested NodeBalancer.

0 commit comments

Comments
 (0)