Skip to content

new: Add handling for failed events in EventPoller(...).wait_for_next_event_finished(...) - #384

Merged
lgarber-akamai merged 3 commits into
linode:devfrom
lgarber-akamai:new/polling-failure
Mar 25, 2024
Merged

new: Add handling for failed events in EventPoller(...).wait_for_next_event_finished(...)#384
lgarber-akamai merged 3 commits into
linode:devfrom
lgarber-akamai:new/polling-failure

Conversation

@lgarber-akamai

Copy link
Copy Markdown
Contributor

📝 Description

This change adds support for handling events in the failed status when polling using the EventPoller(...).wait_for_next_event_finished(...) method. When an event enters the failed status, an EventError will not be raised. Previously a failed event would cause the method to poll indefinitely.

✔️ How to Test

The following test steps assume you have pulled down this change locally and run make install.

Unit Testing

make testunit

Manual Testing

  1. In a linode_api4-python sandbox environment (e.g. dx-devenv), run the following:
import os

from linode_api4 import LinodeClient, Instance

client = LinodeClient(os.getenv("LINODE_TOKEN"))

# Create an instance
instance: Instance = client.linode.instance_create(
    "g6-nanode-1",
    "us-mia",
    label="test-instance",
    image="linode/alpine3.18",
    root_pass="v3rys3cur3r00tp4ssw0rd!!!!!!!!!!!!!",
    booted=False,
)

client.polling.wait_for_entity_free(
    entity_id=instance.id,
    entity_type="linode"
)

# Delete the first disk to make this instance un-bootable
instance.disks[0].delete()

boot_poller = client.polling.event_poller_create(
    "linode",
    "linode_boot"
)

boot_poller.set_entity_id(instance.id)

# Attempt to boot anyway
instance.boot()

# Poll and expect error
boot_poller.wait_for_next_event_finished()
  1. Ensure an error is raised similar to the following:
linode_api4.polling.EventError: Event 667654736 failed

@lgarber-akamai
lgarber-akamai requested a review from a team as a code owner March 14, 2024 18:22
@lgarber-akamai
lgarber-akamai requested review from yec-akamai and ykim-akamai and removed request for a team March 14, 2024 18:22
@lgarber-akamai lgarber-akamai added the enhancement issues that request a enhancement label Mar 14, 2024
assert result.status == "finished"

@httpretty.activate
def test_wait_for_event_finished_failed(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted not to implement an integration test for this change because we generally shouldn't rely on runtime errors.

@yec-akamai yec-akamai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well on my end!

@ykim-akamai ykim-akamai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lgarber-akamai
lgarber-akamai merged commit 58dcd1d into linode:dev Mar 25, 2024
@jriddle-linode jriddle-linode added improvement for improvements in existing functionality in the changelog. and removed enhancement issues that request a enhancement labels Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement for improvements in existing functionality in the changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants