This is an automated email from the ASF dual-hosted git repository.

lcwik pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 2b4bb6b683f Update scopes to match the existing set and update test to 
clear credentials during failure (#23677)
2b4bb6b683f is described below

commit 2b4bb6b683fd59f28fb8b115da8a26ea053271e3
Author: Luke Cwik <lc...@google.com>
AuthorDate: Mon Oct 17 21:48:36 2022 -0700

    Update scopes to match the existing set and update test to clear 
credentials during failure (#23677)
    
    * Update test to clear credentials when test raises an error
    
    * Fix set of requested scopes to match original list
---
 .../apache_beam/examples/wordcount_it_test.py      | 41 ++++++++++++----------
 .../python/apache_beam/options/pipeline_options.py |  3 +-
 2 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/sdks/python/apache_beam/examples/wordcount_it_test.py 
b/sdks/python/apache_beam/examples/wordcount_it_test.py
index afbe70b9d23..ab9de736702 100644
--- a/sdks/python/apache_beam/examples/wordcount_it_test.py
+++ b/sdks/python/apache_beam/examples/wordcount_it_test.py
@@ -66,25 +66,28 @@ class WordCountIT(unittest.TestCase):
     """
     # Credentials need to be reset or this test will fail and credentials
     # from a previous test will be used.
-    auth._Credentials._credentials_init = False
-
-    ACCOUNT_TO_IMPERSONATE = (
-        'allows-impersonation@apache-'
-        'beam-testing.iam.gserviceaccount.com')
-    RUNNER_ACCOUNT = (
-        'impersonation-dataflow-worker@'
-        'apache-beam-testing.iam.gserviceaccount.com')
-    TEMP_DIR = 'gs://impersonation-test-bucket/temp-it'
-    STAGING_LOCATION = 'gs://impersonation-test-bucket/staging-it'
-    extra_options = {
-        'impersonate_service_account': ACCOUNT_TO_IMPERSONATE,
-        'service_account_email': RUNNER_ACCOUNT,
-        'temp_location': TEMP_DIR,
-        'staging_location': STAGING_LOCATION
-    }
-    self._run_wordcount_it(wordcount.run, **extra_options)
-    # Reset credentials for future tests.
-    auth._Credentials._credentials_init = False
+    with auth._Credentials._credentials_lock:
+      auth._Credentials._credentials_init = False
+    try:
+      ACCOUNT_TO_IMPERSONATE = (
+          'allows-impersonation@apache-'
+          'beam-testing.iam.gserviceaccount.com')
+      RUNNER_ACCOUNT = (
+          'impersonation-dataflow-worker@'
+          'apache-beam-testing.iam.gserviceaccount.com')
+      TEMP_DIR = 'gs://impersonation-test-bucket/temp-it'
+      STAGING_LOCATION = 'gs://impersonation-test-bucket/staging-it'
+      extra_options = {
+          'impersonate_service_account': ACCOUNT_TO_IMPERSONATE,
+          'service_account_email': RUNNER_ACCOUNT,
+          'temp_location': TEMP_DIR,
+          'staging_location': STAGING_LOCATION
+      }
+      self._run_wordcount_it(wordcount.run, **extra_options)
+    finally:
+      # Reset credentials for future tests.
+      with auth._Credentials._credentials_lock:
+        auth._Credentials._credentials_init = False
 
   @pytest.mark.it_postcommit
   @pytest.mark.it_validatescontainer
diff --git a/sdks/python/apache_beam/options/pipeline_options.py 
b/sdks/python/apache_beam/options/pipeline_options.py
index 4d8610f60f5..54eaaf19ed8 100644
--- a/sdks/python/apache_beam/options/pipeline_options.py
+++ b/sdks/python/apache_beam/options/pipeline_options.py
@@ -658,7 +658,8 @@ class GoogleCloudOptions(PipelineOptions):
       'https://www.googleapis.com/auth/devstorage.full_control',
       'https://www.googleapis.com/auth/userinfo.email',
       'https://www.googleapis.com/auth/datastore',
-      'https://www.googleapis.com/auth/spanner'
+      'https://www.googleapis.com/auth/spanner.admin',
+      'https://www.googleapis.com/auth/spanner.data'
   ]
 
   @classmethod

Reply via email to