Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: New Queued resources Samples: Create, Create Spot, Get, Delete operations + tests #12716

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

Thoughtseize1
Copy link
Contributor

@Thoughtseize1 Thoughtseize1 commented Oct 21, 2024

Description

📑Created a full set of Queued Resources Samples:

Region Tag File
tpu_queued_resources_create queued_resources_create.py
tpu_queued_resources_network queued_resources_create_network.py
tpu_queued_resources_create_spot queued_resources_create_spot.py
tpu_queued_resources_startup_script queued_resources_create_startup_script.py
tpu_queued_resources_time_bound queued_resources_create_time_bound.py
tpu_queued_resources_get queued_resources_get.py
tpu_queued_resources_list queued_resources_list.py
tpu_queued_resource_delete queued_resources_delete.py
tpu_queued_resources_delete_force queued_resources_delete_force.py

❗Issue with Deleting operation in google.cloud.tpu_v2alpha1

The delete operation in queued_resources_delete.py have issue here with this
block of code.

    try:
        op = client.delete_queued_resource(request=request)
        op.result()
        print(f"Queued resource '{queued_resource_name}' successfully deleted.")
    except TypeError as e:
        print(f"Error deleting resource: {e}")
        print(f"Queued resource '{queued_resource_name}' successfully deleted.")

Issues Encountered:
Resource Successfully Deleted but we got TypeError: After invoking op.result() the resource is indeed successfully deleted. However, despite the deletion being successful, the function throws a TypeError: Could not convert Any to QueuedResource.
This error suggests that the API response could not be properly deserialized or converted into a QueuedResource object, even though the deletion itself completed as expected.

The code should not throw a TypeError when the resources are successfully deleted. We cannot avoid using op.result() because it guarantees that an Exception will be raised when attempting to delete a resource in a status where deletion is not possible. This behavior ensures proper error handling in situations where the resource cannot be deleted, but the current implementation incorrectly throws a TypeError even when deletion is successful.

This is precisely why I had to use two separate except blocks in the code.

Checklist

@product-auto-label product-auto-label bot added samples Issues that are directly related to samples. api: tpu Issues related to the Cloud TPU API. labels Oct 21, 2024
@Thoughtseize1 Thoughtseize1 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 21, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 21, 2024
@Thoughtseize1 Thoughtseize1 added the snippet-bot:force-run Force snippet-bot runs its logic label Oct 21, 2024
@snippet-bot snippet-bot bot removed the snippet-bot:force-run Force snippet-bot runs its logic label Oct 21, 2024
Copy link

snippet-bot bot commented Oct 21, 2024

Here is the summary of changes.

You are about to add 9 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@Thoughtseize1 Thoughtseize1 added the snippet-bot:force-run Force snippet-bot runs its logic label Oct 21, 2024
@snippet-bot snippet-bot bot removed the snippet-bot:force-run Force snippet-bot runs its logic label Oct 21, 2024
@Thoughtseize1 Thoughtseize1 marked this pull request as ready for review October 21, 2024 20:27
@Thoughtseize1 Thoughtseize1 requested review from a team as code owners October 21, 2024 20:27
@Thoughtseize1 Thoughtseize1 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 22, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 22, 2024
Comment on lines 40 to 41
except Exception as e:
print(f"Error deleting resource: {e}")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think in this case we can raise e, so we don't ignore proper issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I simplified this code block.

Comment on lines 58 to 59
except Exception:
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe print the error, so it's easier to debug any potential issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 68 to 69
except Exception:
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

print

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

]


def clean_resource() -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Add some comment why you also delete TPU here, that it's liked to the queued resource etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added expanded comment

@m-strzelczyk m-strzelczyk added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Oct 22, 2024
@Thoughtseize1 Thoughtseize1 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 28, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 28, 2024
@Thoughtseize1 Thoughtseize1 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 31, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: tpu Issues related to the Cloud TPU API. do not merge Indicates a pull request not ready for merge, due to either quality or timing. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants