-
Notifications
You must be signed in to change notification settings - Fork 25
feat: Adding code samples and tests for them #55
Conversation
Here is the summary of changes. You are about to add 10 region tags.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've opened cl/374662458 to enable samples CI.
samples/snippets/quickstart.py
Outdated
print(f"Creating the {machine_name} instance in {zone}...") | ||
operation = instance_client.insert(request=request) | ||
# wait_result = operation_client.wait(operation=operation.name, zone=zone, project=project) | ||
operation = wait_for_operation(operation, project) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The LRO experience looks different from existing GAPICs. @vam-google Does the Compute API have a non-standard LRO representation? It doesn't look like the generator produced the usual google.api_core.Operation
type.
For comparison, see videointelligence where you can do operation.result(timeout=90)
to poll for the result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@busunkim96 would a simpler approach suggest by @bshaffer work here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how I saw the team use the operations in their test code. It is an instance of google.cloud.compute_v1.types.Operation
and not google.api_core.Operation
.
samples/snippets/quickstart.py
Outdated
# [START compute_instances_operation_check] | ||
import typing | ||
|
||
import google.cloud.compute_v1 as gce |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style suggestion for consistency with existing python samples.
import google.cloud.compute_v1 as gce | |
from google.cloud import compute_v1 |
Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>
I think there's something wrong with Kokoro -samples tests. They're trying to use samples/snippets/noxfile.py which doesn't exist. The tests can be run from the root directory with |
@busunkim96 I read the configs in Please let me know how should I proceed. Should I create |
@busunkim96 I have adjusted my tests to work with the automated kokoro scripts :) |
@dinagraves Can you review this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The LRO handling still looks a little odd to me - I'll poke at the existing tests to see if there's a nicer option.
Otherwise this looks very nice!
samples/snippets/quickstart.py
Outdated
|
||
print(f"Creating the {instance_name} instance in {zone}...") | ||
operation = instance_client.insert(request=request) | ||
# wait_result = operation_client.wait(operation=operation.name, zone=zone, project=project) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a stray comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Changed that part already.
samples/snippets/quickstart.py
Outdated
if operation.error: | ||
pass | ||
if operation.warnings: | ||
pass | ||
print(f"Instance {machine_name} deleted.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the sample show error handling? (Even if it is just printing out the error/warnings?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally LGTM. A few suggestions.
samples/snippets/README.md
Outdated
1. If you haven't already, set up a Python Development Environment by following the [python setup guide](https://cloud.google.com/python/setup) and | ||
[create a project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#creating_a_project). | ||
|
||
1. Create a service account with the 'Editor' permissions by following these |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend using gcloud auth application-default login
instead. It's more secure if you don't have to download a JSON key. It's also easier. You can skip the next 3 steps with this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Good point. Done.
samples/snippets/quickstart.py
Outdated
"or set GOOGLE_APPLICATION_CREDENTIALS to use this script." | ||
) | ||
else: | ||
test_instance_name = "i" + uuid.uuid4().hex[:10] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this called test_instance_name
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other note, can you concatenate something like "quickstart" to the instance name, so it's easier to identify? I ran this on a current project and got a little confused and worried before I recognized which one was the quickstart.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to just instance_name
and made the name start with quickstart-
* README suggests using `gcloud auth application-default login` which is safer than Service Account key. * The name of created instance now starts with "quickstart-". * Changed one variable name.
🤖 I have created a release \*beep\* \*boop\* --- ## [0.4.0](https://www.github.com/googleapis/python-compute/compare/v0.3.0...v0.4.0) (2021-06-07) ### Features * Adding code samples and tests for them ([#55](https://www.github.com/googleapis/python-compute/issues/55)) ([14cd352](https://www.github.com/googleapis/python-compute/commit/14cd352079281ddde3602597334e3c88c942ed30)) * Raise GoogleAPICallError on REST response errors ([01db23b](https://www.github.com/googleapis/python-compute/commit/01db23bc0af3ab30bfb5ad8205446ae49417f0f1)) * Re-generated to pick up changes from googleapis-discovery with latest fixes ([#60](https://www.github.com/googleapis/python-compute/issues/60)) ([01db23b](https://www.github.com/googleapis/python-compute/commit/01db23bc0af3ab30bfb5ad8205446ae49417f0f1)) * remove support for google-api-core < 1.28.0 ([01db23b](https://www.github.com/googleapis/python-compute/commit/01db23bc0af3ab30bfb5ad8205446ae49417f0f1)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Hi, I tried uploading those samples to the python-docs-samples repo, but I was told that it'd be better to put them here. So here I am, with the first batch of code samples for our documentation :)