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(datastore): Add Datastore Admin API samples #4121

Merged

Conversation

IlyaFaer
Copy link

Fixes #4120

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jun 18, 2020
@IlyaFaer
Copy link
Author

IlyaFaer commented Jun 18, 2020

@BenWhitehead, @crwilcox, I've used the code generated by Alex Vaskman (see the generation configurations PR), to run tests. They are okay:

Безымянный
We need an access for Datastore Admin and Storage simultaneously to write tests for entities export/import on Python and Go. I'll ask Deepika about this on our meeting today.

I've written the code in Datastore fashion for now. Ready for any changes requests.

@BenWhitehead
Copy link
Contributor

I think it's okay to not have tests for the export/import calls, since those are LongRunningOperations and depend on bucket access/config.

@IlyaFaer IlyaFaer marked this pull request as ready for review June 19, 2020 08:13
@IlyaFaer IlyaFaer requested a review from a team as a code owner June 19, 2020 08:13
@tmatsuo
Copy link
Contributor

tmatsuo commented Jun 22, 2020

@BenWhitehead

I think we should add a test.

For bucket access and config, please tell us the requirements. We can set it up.
For long running operations, you can still test it. Wait for the result with a timeout that gives you around 90% success rate, then retry the test 2 or 3 times.

@BenWhitehead
Copy link
Contributor

Hey @tmatsuo,

This is the quick list of what I believe would be needed to run import/export integration tests:

  1. A storage bucket (ideally located in the same region is the datastore instance)
    • Some way of passing this bucket into the tests (env variable?)
  2. Service Account used to run the tests will need
    • Cloud Datastore Import Export Admin, or Cloud Datastore Owner or Owner (least to most permissive)
    • Storage Admin, or Owner (least to most permissive)
  3. The App Engine default service account of GCP Project used for integration tests needs to exist (it is the service account used by the backend jobs to do the import/export)
    • Cloud Datastore Import Export Admin, or Cloud Datastore Owner or Owner (least to most permissive)
    • Storage Admin, or Owner (least to most permissive) on the bucket from 1

Datastore Exporting and importing entities Permissions

@tmatsuo
Copy link
Contributor

tmatsuo commented Jun 24, 2020

@BenWhitehead

A storage bucket (ideally located in the same region is the datastore instance)

We're already using a storage bucket specified in CLOUD_STORAGE_BUCKET envvar. On Kokoro, this is set to python-docs-samples-tests bucket. I hope you can just use it.

Re: permission

I added those permissions to the service accounts.

I think Storage Object Admin is enough, instead of Storage Admin, so I only applied Storage Object Admin on the bucket to the app engine default service account. Let me know if we actually need Storage Admin.

@tmatsuo
Copy link
Contributor

tmatsuo commented Jun 24, 2020

@IlyaFaer

Can you also update the required env vars and permissions to run the tests in the README file? Actually you'll need to update README.rst.in and run the readmegen nox session to re-generate the README.rst file.

I think you can use required_role and other_required_steps field in that file (Example usage).

@IlyaFaer
Copy link
Author

IlyaFaer commented Jun 26, 2020

@BenWhitehead, @tmatsuo, looks like we were provided with all the necessary permissions in our project, thanks. I've run the tests locally - they're okay (I assume on kokoro they'll be failing until the next Datastore release):

Безымянный

I've unioned import and export tests as it's easier to run them sequentially and use the results of the export as an argument for import. Hope it's okay.

And, if I understood correctly, this CLOUD_STORAGE_BUCKET already exists in samples kokoro environment, so I don't need to create/delete it on every test run.

Can you also update the required env vars and permissions to run the tests in the README file? Actually you'll need to update README.rst.in and run the readmegen nox session to re-generate the README.rst file

Pushed. There is no noxfile.py in datastore directory by the way. Should be generated I guess.

@tmatsuo tmatsuo added the kokoro:run Add this label to force Kokoro to re-run the tests. label Jun 26, 2020
@kokoro-team kokoro-team removed kokoro:run Add this label to force Kokoro to re-run the tests. labels Jun 26, 2020
@BenWhitehead BenWhitehead added the kokoro:run Add this label to force Kokoro to re-run the tests. label Jun 29, 2020
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Jun 29, 2020
datastore/cloud-client/README.rst.in Show resolved Hide resolved
datastore/cloud-client/requirements-test.txt Outdated Show resolved Hide resolved
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 14, 2020
@IlyaFaer
Copy link
Author

Thanks, @crwilcox! All the files are there now. I suppose only renovate PR is left, and kokoro checks will become green.

@tmatsuo
Copy link
Contributor

tmatsuo commented Jul 16, 2020

@IlyaFaer FYI, I think the test will automatically executed if you join googlecloudplatform org.

@tmatsuo tmatsuo added the kokoro:run Add this label to force Kokoro to re-run the tests. label Jul 16, 2020
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Jul 16, 2020
@BenWhitehead
Copy link
Contributor

@IlyaFaer looks like there are some test bootstrapping issues

==================================== ERRORS ====================================
____________ ERROR collecting datastore/cloud-client/admin_test.py _____________
ImportError while importing test module '/workspace/datastore/cloud-client/admin_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
admin_test.py:19: in <module>
    import admin
admin.py:15: in <module>
    from google.cloud.datastore_admin_v1.gapic import datastore_admin_client
E   ModuleNotFoundError: No module named 'google.cloud.datastore_admin_v1.gapic'
----- generated xml file: /workspace/datastore/cloud-client/sponge_log.xml -----
=========================== short test summary info ============================
ERROR admin_test.py
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.51s ===============================

@IlyaFaer IlyaFaer added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 17, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 17, 2020
@IlyaFaer
Copy link
Author

IlyaFaer commented Jul 17, 2020

@BenWhitehead, @crwilcox, I've updated the branch with renovate PR changes. Now another error appeared:

____________ ERROR collecting datastore/cloud-client/admin_test.py _____________
Traceback (most recent call last):
  File "/workspace/datastore/cloud-client/admin_test.py", line 19, in <module>
    import admin
  File "/workspace/datastore/cloud-client/admin.py", line 15, in <module>
    from google.cloud.datastore_admin_v1.gapic import datastore_admin_client
  File "/workspace/datastore/cloud-client/.nox/py-3-6/lib/python3.6/site-packages/google/cloud/datastore_admin_v1/__init__.py", line 23, in <module>
    from google.cloud.datastore_admin_v1.gapic import datastore_admin_client
  File "/workspace/datastore/cloud-client/.nox/py-3-6/lib/python3.6/site-packages/google/cloud/datastore_admin_v1/gapic/datastore_admin_client.py", line 48, in <module>
    "google-cloud-datastore-admin",
  File "/workspace/datastore/cloud-client/.nox/py-3-6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 481, in get_distribution
    dist = get_provider(dist)
  File "/workspace/datastore/cloud-client/.nox/py-3-6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 357, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "/workspace/datastore/cloud-client/.nox/py-3-6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 900, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/workspace/datastore/cloud-client/.nox/py-3-6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 786, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'google-cloud-datastore-admin' distribution was not found and is required by the application

I suspect the problem caused with the generated lines:
https://github.com/googleapis/python-datastore/blob/592c7aa636990533a9c02f73a413de44b71dcc98/google/cloud/datastore_admin_v1/gapic/datastore_admin_client.py#L47-L49

There is no such a Python package google-cloud-datastore-admin.

@IlyaFaer IlyaFaer added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 20, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 20, 2020
@IlyaFaer IlyaFaer added kokoro:force-run Add this label to force Kokoro to re-run the tests. kokoro:run Add this label to force Kokoro to re-run the tests. and removed kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jul 22, 2020
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Jul 23, 2020
@IlyaFaer
Copy link
Author

IlyaFaer commented Jul 23, 2020

@tmatsuo, @crwilcox, @BenWhitehead, all the checks are green 🎉
Thanks for the re-generation and dependencies!

@tmatsuo tmatsuo added kokoro:run Add this label to force Kokoro to re-run the tests. automerge Merge the pull request once unit tests and other checks pass. labels Aug 3, 2020
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Aug 3, 2020
@tmatsuo tmatsuo merged commit b546ae2 into GoogleCloudPlatform:master Aug 3, 2020
@IlyaFaer IlyaFaer deleted the datastore_admin_api_samples branch August 4, 2020 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge the pull request once unit tests and other checks pass. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Datastore Admin API samples
7 participants