diff --git a/google/cloud/spanner_v1/services/spanner/client.py b/google/cloud/spanner_v1/services/spanner/client.py index e853b2dfd5..d69c427314 100644 --- a/google/cloud/spanner_v1/services/spanner/client.py +++ b/google/cloud/spanner_v1/services/spanner/client.py @@ -370,16 +370,17 @@ def get_mtls_endpoint_and_cert_source( ) if client_options is None: client_options = client_options_lib.ClientOptions() - use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_client_cert not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - ) - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) + + ( + use_client_cert, + use_mtls_endpoint, + universe_domain_env, + ) = SpannerClient._read_environment_variables() + + universe_domain_opt = getattr(client_options, "universe_domain", None) + universe_domain = SpannerClient._get_universe_domain( + universe_domain_opt, universe_domain_env + ) # Figure out the client cert source to use. client_cert_source = None @@ -397,7 +398,9 @@ def get_mtls_endpoint_and_cert_source( ): api_endpoint = cls.DEFAULT_MTLS_ENDPOINT else: - api_endpoint = cls.DEFAULT_ENDPOINT + api_endpoint = SpannerClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=universe_domain + ) return api_endpoint, client_cert_source diff --git a/google/cloud/spanner_v1/testing/database_test.py b/google/cloud/spanner_v1/testing/database_test.py index 5af89fea42..800cabaad0 100644 --- a/google/cloud/spanner_v1/testing/database_test.py +++ b/google/cloud/spanner_v1/testing/database_test.py @@ -110,7 +110,7 @@ def _create_spanner_client_for_tests(self, client_options, credentials): default_host=SpannerTransport.DEFAULT_HOST, ) channel = grpc.intercept_channel(channel, *self._interceptors) - transport = SpannerGrpcTransport(channel=channel) + transport = SpannerGrpcTransport(channel=channel, host=api_endpoint) return SpannerClient( client_options=client_options, transport=transport, diff --git a/testing/constraints-3.12.txt b/testing/constraints-3.12.txt index ad3f0fa58e..e8a39cf7b5 100644 --- a/testing/constraints-3.12.txt +++ b/testing/constraints-3.12.txt @@ -5,3 +5,8 @@ google-api-core proto-plus protobuf grpc-google-iam-v1 +grpc-interceptor +google-cloud-core +google-cloud-testutils +mock +sqlparse \ No newline at end of file diff --git a/tests/system/_helpers.py b/tests/system/_helpers.py index 1fc897b39c..97bb8f8b96 100644 --- a/tests/system/_helpers.py +++ b/tests/system/_helpers.py @@ -27,7 +27,7 @@ CREATE_INSTANCE = os.getenv(CREATE_INSTANCE_ENVVAR) is not None INSTANCE_ID_ENVVAR = "GOOGLE_CLOUD_TESTS_SPANNER_INSTANCE" -INSTANCE_ID_DEFAULT = "google-cloud-python-systest" +INSTANCE_ID_DEFAULT = "test-instance-1" INSTANCE_ID = os.environ.get(INSTANCE_ID_ENVVAR, INSTANCE_ID_DEFAULT) API_ENDPOINT_ENVVAR = "GOOGLE_CLOUD_TESTS_SPANNER_HOST" diff --git a/tests/system/conftest.py b/tests/system/conftest.py index bc94d065b2..fe2930cb4f 100644 --- a/tests/system/conftest.py +++ b/tests/system/conftest.py @@ -16,6 +16,7 @@ import time import pytest +from google.api_core.client_options import ClientOptions from google.cloud import spanner_v1 from google.cloud.spanner_admin_database_v1 import DatabaseDialect @@ -105,9 +106,12 @@ def spanner_client(): credentials=credentials, ) else: - client_options = {"api_endpoint": _helpers.API_ENDPOINT} return spanner_v1.Client( - client_options=client_options + project="tpczero-system:bootstrap-libraries", + client_options=ClientOptions( + api_endpoint=_helpers.API_ENDPOINT, + universe_domain="apis-tpczero.goog", + ) ) # use google.auth.default credentials diff --git a/tests/system/test_database_api.py b/tests/system/test_database_api.py index 57ce49c8a2..ae5856b064 100644 --- a/tests/system/test_database_api.py +++ b/tests/system/test_database_api.py @@ -37,7 +37,7 @@ "include_replicas": { "replica_selections": [ { - "location": "us-west1", + "location": "u-us-prp1", "type_": DirectedReadOptions.ReplicaSelection.Type.READ_ONLY, }, ], @@ -281,7 +281,7 @@ def test_iam_policy( new_binding = policy_pb2.Binding( role="roles/spanner.fineGrainedAccessUser", - members=["user:asthamohta@google.com"], + members=["user:sasubramanian@google.com"], condition=expr_pb2.Expr( title="condition title", expression='resource.name.endsWith("/databaseRoles/parent")',