Integration tests for support Linode integration with alerts#669
Conversation
There was a problem hiding this comment.
Pull request overview
Adds integration test coverage for Linode Instance “alerts” behavior in the Python SDK, focusing on listing, rebuilding, updating, cloning, and validating error behavior when mixing legacy and ACLP alerts.
Changes:
- Add a new integration test to verify alerts are present when listing Linodes.
- Extend the rebuild integration test to assert alerts fields are populated.
- Add workflow/error-path integration tests for updating alerts and validating legacy vs ACLP alert incompatibilities.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return type in str(linode.type) | ||
|
|
||
|
|
||
| def test_get_linodes_verify_alerts(test_linode_client, create_linode): |
There was a problem hiding this comment.
create_linode is not used in this test. Probably can be removed.
There was a problem hiding this comment.
Correct, but we need at least one linode to verify get linodes endpoint. It was suggested by copilot #669 (comment). What do you think about this?
There was a problem hiding this comment.
The copilot suggests to not use the listing endpoint linode.instance() and use create_linode. I agree that it's safer to not assume there is linode available by listing.
| new_linode.delete() | ||
|
|
||
|
|
||
| def test_try_to_update_linode_alerts_legacy_and_aclp_at_the_same_time( |
There was a problem hiding this comment.
We can consider not testing this case, because this behavior will be removed in a following api change. I will send the doc to you.
| assert linode.status == "running" | ||
|
|
||
|
|
||
| def test_linode_alerts_workflow(test_linode_client, create_linode): |
There was a problem hiding this comment.
Can we add a test case to creat linode with aclp alerts? Adding system_alerts should be good
There was a problem hiding this comment.
Good point, please verify test just added: test_update_linode_aclp_alerts
There was a problem hiding this comment.
Pull request overview
Adds integration coverage to validate Linode “alerts” behavior is present and consistent across common instance operations in the SDK’s integration test suite.
Changes:
- Add an instances-list test that asserts alerts fields are present and non-negative.
- Extend the rebuild integration test to assert alerts are accessible during rebuild.
- Add workflow tests for reading/updating alerts, cloning behavior, and an error case when mixing legacy + ACLP alerts.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| linodes_list = test_linode_client.linode.instances().lists[0] | ||
| assert len(linodes_list) > 0 | ||
| assert linodes_list[0].alerts.cpu >= 0 | ||
| assert linodes_list[0].alerts.io >= 0 | ||
| assert linodes_list[0].alerts.network_in >= 0 | ||
| assert linodes_list[0].alerts.network_out >= 0 | ||
| assert linodes_list[0].alerts.transfer_quota >= 0 | ||
|
|
||
|
|
There was a problem hiding this comment.
test_get_linodes_verify_alerts is non-deterministic: it creates a Linode via the create_linode fixture but then asserts against instances().lists[0][0], which may be an unrelated instance (ordering/pagination is not guaranteed). To make the test reliable, assert against the specific Linode created by the fixture (e.g., load by create_linode.id or filter the list for that ID), and avoid reaching into the internal .lists cache when plain indexing/iteration works.
| linodes_list = test_linode_client.linode.instances().lists[0] | |
| assert len(linodes_list) > 0 | |
| assert linodes_list[0].alerts.cpu >= 0 | |
| assert linodes_list[0].alerts.io >= 0 | |
| assert linodes_list[0].alerts.network_in >= 0 | |
| assert linodes_list[0].alerts.network_out >= 0 | |
| assert linodes_list[0].alerts.transfer_quota >= 0 | |
| linode = test_linode_client.load(Instance, create_linode.id) | |
| assert linode.alerts.cpu >= 0 | |
| assert linode.alerts.io >= 0 | |
| assert linode.alerts.network_in >= 0 | |
| assert linode.alerts.network_out >= 0 | |
| assert linode.alerts.transfer_quota >= 0 |
| linode.alerts = { | ||
| "cpu": 50, | ||
| "io": 6000, | ||
| "network_in": 20, | ||
| "network_out": 20, | ||
| "transfer_quota": 40, | ||
| } | ||
| linode.save() | ||
|
|
||
| wait_for_condition(10, 100, get_status, linode, "running") | ||
| new_linode = retry_sending_request( | ||
| 5, | ||
| linode.clone, | ||
| region=linode.region.id, | ||
| instance_type=linode.type.id, | ||
| label=get_test_label(), | ||
| ) | ||
| assert new_linode.alerts.cpu == 90 | ||
| assert new_linode.alerts.io == 10000 | ||
| assert new_linode.alerts.network_in == 10 | ||
| assert new_linode.alerts.network_out == 10 | ||
| assert new_linode.alerts.transfer_quota == 80 | ||
| assert isinstance(new_linode.alerts.system_alerts, list) | ||
| assert isinstance(new_linode.alerts.user_alerts, list) |
There was a problem hiding this comment.
In test_linode_alerts_workflow, the test updates linode.alerts (cpu/io/network_*/transfer_quota) and calls linode.save(), but none of the subsequent assertions check that the update actually took effect. As written, the test would still pass even if the save was a no-op, which weakens the intended coverage. Consider asserting the saved values after a reload, and then align the clone assertions with the intended behavior (either the clone inherits the updated alerts, or it resets to defaults—right now it asserts the same default values as before the update).
| if new_linode is not None: | ||
| new_linode.delete() |
There was a problem hiding this comment.
if new_linode is not None: is redundant here: the test already dereferences new_linode.alerts.* above, so new_linode must be non-None for the test to reach the cleanup. Prefer unconditional deletion (or a try/finally around assertions) to make the cleanup intent clearer.
| if new_linode is not None: | |
| new_linode.delete() | |
| new_linode.delete() |
…ame_time and add test test_update_linode_aclp_alerts
📝 Description
Integration tests for support Linode integration with alerts
✔️ How to Test
make TEST_CASE=test_get_linodes_verify_alerts test-int
make TEST_CASE=test_linode_rebuild test-int
make TEST_CASE=test_linode_alerts_workflow test-int
make TEST_CASE=test_try_to_update_linode_alerts_legacy_and_aclp_at_the_same_time test-int