diff --git a/google/cloud/network_management_v1/services/reachability_service/async_client.py b/google/cloud/network_management_v1/services/reachability_service/async_client.py index d090d43..8958881 100644 --- a/google/cloud/network_management_v1/services/reachability_service/async_client.py +++ b/google/cloud/network_management_v1/services/reachability_service/async_client.py @@ -260,7 +260,7 @@ async def list_connectivity_tests( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -338,7 +338,7 @@ async def get_connectivity_test( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -446,7 +446,7 @@ async def create_connectivity_test( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, test_id, resource]) if request is not None and has_flattened_params: @@ -556,7 +556,7 @@ async def update_connectivity_test( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([update_mask, resource]) if request is not None and has_flattened_params: @@ -726,7 +726,7 @@ async def delete_connectivity_test( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: diff --git a/google/cloud/network_management_v1/services/reachability_service/client.py b/google/cloud/network_management_v1/services/reachability_service/client.py index 55d3ae7..f0c46be 100644 --- a/google/cloud/network_management_v1/services/reachability_service/client.py +++ b/google/cloud/network_management_v1/services/reachability_service/client.py @@ -454,7 +454,7 @@ def list_connectivity_tests( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -532,7 +532,7 @@ def get_connectivity_test( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -640,7 +640,7 @@ def create_connectivity_test( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, test_id, resource]) if request is not None and has_flattened_params: @@ -750,7 +750,7 @@ def update_connectivity_test( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([update_mask, resource]) if request is not None and has_flattened_params: @@ -921,7 +921,7 @@ def delete_connectivity_test( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: diff --git a/google/cloud/network_management_v1/services/reachability_service/transports/grpc.py b/google/cloud/network_management_v1/services/reachability_service/transports/grpc.py index 409f9e1..a6551ff 100644 --- a/google/cloud/network_management_v1/services/reachability_service/transports/grpc.py +++ b/google/cloud/network_management_v1/services/reachability_service/transports/grpc.py @@ -171,8 +171,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -245,7 +248,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) diff --git a/google/cloud/network_management_v1/services/reachability_service/transports/grpc_asyncio.py b/google/cloud/network_management_v1/services/reachability_service/transports/grpc_asyncio.py index dfdcff7..841ae3a 100644 --- a/google/cloud/network_management_v1/services/reachability_service/transports/grpc_asyncio.py +++ b/google/cloud/network_management_v1/services/reachability_service/transports/grpc_asyncio.py @@ -216,8 +216,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -247,7 +250,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel diff --git a/google/cloud/network_management_v1/types/connectivity_test.py b/google/cloud/network_management_v1/types/connectivity_test.py index bc57755..fe9f1e3 100644 --- a/google/cloud/network_management_v1/types/connectivity_test.py +++ b/google/cloud/network_management_v1/types/connectivity_test.py @@ -51,8 +51,8 @@ class ConnectivityTest(proto.Message): the VPC network. Otherwise, specify the VM instance, which already contains its internal IP address and VPC network information. - If the source of the test is within an on- - premises network, then you must provide the + If the source of the test is within an + on-premises network, then you must provide the destination VPC network. If the source endpoint is a Compute Engine VM diff --git a/tests/unit/gapic/network_management_v1/test_reachability_service.py b/tests/unit/gapic/network_management_v1/test_reachability_service.py index d605c5e..e477f49 100644 --- a/tests/unit/gapic/network_management_v1/test_reachability_service.py +++ b/tests/unit/gapic/network_management_v1/test_reachability_service.py @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.api_core import path_template @@ -541,25 +542,28 @@ def test_reachability_service_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ ( ReachabilityServiceClient, transports.ReachabilityServiceGrpcTransport, "grpc", + grpc_helpers, ), ( ReachabilityServiceAsyncClient, transports.ReachabilityServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_reachability_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) @@ -595,6 +599,72 @@ def test_reachability_service_client_client_options_from_dict(): ) +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + ReachabilityServiceClient, + transports.ReachabilityServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + ReachabilityServiceAsyncClient, + transports.ReachabilityServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_reachability_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "networkmanagement.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="networkmanagement.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "request_type", [reachability.ListConnectivityTestsRequest, dict,] )