Skip to content

Commit

Permalink
Making alias for grpc _Rendezvous.
Browse files Browse the repository at this point in the history
Relates to #2156.
  • Loading branch information
dhermes committed Sep 19, 2016
1 parent f916093 commit b185ee8
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 83 deletions.
2 changes: 1 addition & 1 deletion google/cloud/bigtable/row_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class InvalidChunk(RuntimeError):
class PartialRowsData(object):
"""Convenience wrapper for consuming a ``ReadRows`` streaming response.
:type response_iterator: :class:`grpc._channel._Rendezvous`
:type response_iterator: :class:`~google.cloud.exceptions.GrpcRendezvous`
:param response_iterator: A streaming iterator returned from a
``ReadRows`` request.
"""
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/bigtable/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def sample_row_keys(self):
samples would require space roughly equal to the difference in their
``offset_bytes`` fields.
:rtype: :class:`grpc._channel._Rendezvous`
:rtype: :class:`~google.cloud.exceptions.GrpcRendezvous`
:returns: A cancel-able iterator. Can be consumed by calling ``next()``
or by casting to a :class:`list` and can be cancelled by
calling ``cancel()``.
Expand Down
5 changes: 2 additions & 3 deletions google/cloud/datastore/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@
from google.cloud.environment_vars import DISABLE_GRPC
from google.cloud.environment_vars import GCD_HOST
from google.cloud.exceptions import Conflict
from google.cloud.exceptions import GrpcRendezvous
from google.cloud.exceptions import make_exception
from google.cloud.datastore._generated import datastore_pb2 as _datastore_pb2
# pylint: disable=ungrouped-imports
try:
from grpc import StatusCode
from grpc._channel import _Rendezvous
from google.cloud.datastore._generated import datastore_grpc_pb2
except ImportError: # pragma: NO COVER
_HAVE_GRPC = False
datastore_grpc_pb2 = None
StatusCode = None
_Rendezvous = Exception
else:
_HAVE_GRPC = True
# pylint: enable=ungrouped-imports
Expand Down Expand Up @@ -313,7 +312,7 @@ def commit(self, project, request_pb):
request_pb.project_id = project
try:
return self._stub.Commit(request_pb)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.ABORTED:
raise Conflict(exc.details())
raise
Expand Down
11 changes: 11 additions & 0 deletions google/cloud/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@

_HTTP_CODE_TO_EXCEPTION = {} # populated at end of module

try:
from grpc._channel import _Rendezvous
except ImportError: # pragma: NO COVER
_Rendezvous = None


# pylint: disable=invalid-name
GrpcRendezvous = _Rendezvous
"""Exception class raised by gRPC stable."""
# pylint: enable=invalid-name


class GoogleCloudError(Exception):
"""Base error class for Google Cloud errors (abstract).
Expand Down
20 changes: 10 additions & 10 deletions google/cloud/logging/_gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
from google.logging.v2.log_entry_pb2 import LogEntry
from google.protobuf.json_format import Parse
from grpc import StatusCode
from grpc._channel import _Rendezvous

# pylint: disable=ungrouped-imports
from google.cloud._helpers import _datetime_to_pb_timestamp
from google.cloud._helpers import _pb_timestamp_to_rfc3339
from google.cloud.exceptions import Conflict
from google.cloud.exceptions import GrpcRendezvous
from google.cloud.exceptions import NotFound
# pylint: enable=ungrouped-imports

Expand Down Expand Up @@ -122,7 +122,7 @@ def logger_delete(self, project, logger_name):
path = 'projects/%s/logs/%s' % (project, logger_name)
try:
self._gax_api.delete_log(path, options)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
raise NotFound(path)
raise
Expand Down Expand Up @@ -194,7 +194,7 @@ def sink_create(self, project, sink_name, filter_, destination):
destination=destination)
try:
self._gax_api.create_sink(parent, sink_pb, options)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.FAILED_PRECONDITION:
path = 'projects/%s/sinks/%s' % (project, sink_name)
raise Conflict(path)
Expand All @@ -217,7 +217,7 @@ def sink_get(self, project, sink_name):
path = 'projects/%s/sinks/%s' % (project, sink_name)
try:
sink_pb = self._gax_api.get_sink(path, options)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
raise NotFound(path)
raise
Expand Down Expand Up @@ -249,7 +249,7 @@ def sink_update(self, project, sink_name, filter_, destination):
sink_pb = LogSink(name=path, filter=filter_, destination=destination)
try:
self._gax_api.update_sink(path, sink_pb, options)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
raise NotFound(path)
raise
Expand All @@ -268,7 +268,7 @@ def sink_delete(self, project, sink_name):
path = 'projects/%s/sinks/%s' % (project, sink_name)
try:
self._gax_api.delete_sink(path, options)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
raise NotFound(path)
raise
Expand Down Expand Up @@ -339,7 +339,7 @@ def metric_create(self, project, metric_name, filter_, description):
description=description)
try:
self._gax_api.create_log_metric(parent, metric_pb, options)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.FAILED_PRECONDITION:
path = 'projects/%s/metrics/%s' % (project, metric_name)
raise Conflict(path)
Expand All @@ -362,7 +362,7 @@ def metric_get(self, project, metric_name):
path = 'projects/%s/metrics/%s' % (project, metric_name)
try:
metric_pb = self._gax_api.get_log_metric(path, options)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
raise NotFound(path)
raise
Expand Down Expand Up @@ -394,7 +394,7 @@ def metric_update(self, project, metric_name, filter_, description):
description=description)
try:
self._gax_api.update_log_metric(path, metric_pb, options)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
raise NotFound(path)
raise
Expand All @@ -413,7 +413,7 @@ def metric_delete(self, project, metric_name):
path = 'projects/%s/metrics/%s' % (project, metric_name)
try:
self._gax_api.delete_log_metric(path, options)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
raise NotFound(path)
raise
Expand Down
26 changes: 13 additions & 13 deletions google/cloud/pubsub/_gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
from google.pubsub.v1.pubsub_pb2 import PushConfig
from grpc import insecure_channel
from grpc import StatusCode
from grpc._channel import _Rendezvous

# pylint: disable=ungrouped-imports
from google.cloud._helpers import _to_bytes
from google.cloud._helpers import _pb_timestamp_to_rfc3339
from google.cloud.exceptions import Conflict
from google.cloud.exceptions import GrpcRendezvous
from google.cloud.exceptions import NotFound
# pylint: enable=ungrouped-imports

Expand Down Expand Up @@ -92,7 +92,7 @@ def topic_create(self, topic_path):
"""
try:
topic_pb = self._gax_api.create_topic(topic_path)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.FAILED_PRECONDITION:
raise Conflict(topic_path)
raise
Expand All @@ -115,7 +115,7 @@ def topic_get(self, topic_path):
"""
try:
topic_pb = self._gax_api.get_topic(topic_path)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
raise NotFound(topic_path)
raise
Expand All @@ -133,7 +133,7 @@ def topic_delete(self, topic_path):
"""
try:
self._gax_api.delete_topic(topic_path)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
raise NotFound(topic_path)
raise
Expand Down Expand Up @@ -162,7 +162,7 @@ def topic_publish(self, topic_path, messages):
try:
result = self._gax_api.publish(topic_path, message_pbs,
options=options)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
raise NotFound(topic_path)
raise
Expand Down Expand Up @@ -200,7 +200,7 @@ def topic_list_subscriptions(self, topic_path, page_size=0,
try:
page_iter = self._gax_api.list_topic_subscriptions(
topic_path, page_size=page_size, options=options)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
raise NotFound(topic_path)
raise
Expand Down Expand Up @@ -293,7 +293,7 @@ def subscription_create(self, subscription_path, topic_path,
try:
sub_pb = self._gax_api.create_subscription(
subscription_path, topic_path, push_config, ack_deadline)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.FAILED_PRECONDITION:
raise Conflict(topic_path)
raise
Expand All @@ -315,7 +315,7 @@ def subscription_get(self, subscription_path):
"""
try:
sub_pb = self._gax_api.get_subscription(subscription_path)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
raise NotFound(subscription_path)
raise
Expand All @@ -334,7 +334,7 @@ def subscription_delete(self, subscription_path):
"""
try:
self._gax_api.delete_subscription(subscription_path)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
raise NotFound(subscription_path)
raise
Expand All @@ -359,7 +359,7 @@ def subscription_modify_push_config(self, subscription_path,
push_config = PushConfig(push_endpoint=push_endpoint)
try:
self._gax_api.modify_push_config(subscription_path, push_config)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
raise NotFound(subscription_path)
raise
Expand Down Expand Up @@ -391,7 +391,7 @@ def subscription_pull(self, subscription_path, return_immediately=False,
try:
response_pb = self._gax_api.pull(
subscription_path, max_messages, return_immediately)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
raise NotFound(subscription_path)
raise
Expand All @@ -414,7 +414,7 @@ def subscription_acknowledge(self, subscription_path, ack_ids):
"""
try:
self._gax_api.acknowledge(subscription_path, ack_ids)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
raise NotFound(subscription_path)
raise
Expand All @@ -441,7 +441,7 @@ def subscription_modify_ack_deadline(self, subscription_path, ack_ids,
try:
self._gax_api.modify_ack_deadline(
subscription_path, ack_ids, ack_deadline)
except _Rendezvous as exc:
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
raise NotFound(subscription_path)
raise
Expand Down
5 changes: 3 additions & 2 deletions system_tests/bigtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ def _retry_on_unavailable(exc):


def setUpModule():
from grpc._channel import _Rendezvous
from google.cloud.exceptions import GrpcRendezvous

Config.CLIENT = Client(admin=True)
Config.INSTANCE = Config.CLIENT.instance(INSTANCE_ID, LOCATION_ID)
retry = RetryErrors(_Rendezvous, error_predicate=_retry_on_unavailable)
retry = RetryErrors(GrpcRendezvous, error_predicate=_retry_on_unavailable)
instances, failed_locations = retry(Config.CLIENT.list_instances)()

if len(failed_locations) != 0:
Expand Down
4 changes: 2 additions & 2 deletions system_tests/logging_.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def _logger_name():
return 'system-tests-logger' + unique_resource_id('-')

def _list_entries(self, logger):
from grpc._channel import _Rendezvous
from google.cloud.exceptions import GrpcRendezvous
inner = RetryResult(_has_entries)(logger.list_entries)
outer = RetryErrors(_Rendezvous, _retry_on_unavailable)(inner)
outer = RetryErrors(GrpcRendezvous, _retry_on_unavailable)(inner)
return outer()

def test_log_text(self):
Expand Down
4 changes: 2 additions & 2 deletions system_tests/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import unittest

from grpc import StatusCode
from grpc._channel import _Rendezvous
import httplib2

# pylint: disable=ungrouped-imports
from google.cloud.environment_vars import PUBSUB_EMULATOR
from google.cloud.exceptions import GrpcRendezvous
from google.cloud.pubsub import client
# pylint: enable=ungrouped-imports

Expand All @@ -35,7 +35,7 @@ def _unavailable(exc):
return exc.code() == StatusCode.UNAVAILABLE


retry_unavailable = RetryErrors(_Rendezvous, _unavailable)
retry_unavailable = RetryErrors(GrpcRendezvous, _unavailable)


class Config(object):
Expand Down
4 changes: 2 additions & 2 deletions unit_tests/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ def __init__(self, **kw):
self.__dict__.update(kw)

def _make_grpc_error(self, status_code=None):
from grpc._channel import _Rendezvous
from grpc._channel import _RPCState
from grpc import StatusCode
from google.cloud.exceptions import GrpcRendezvous

if status_code is None:
status_code = StatusCode.UNKNOWN

details = 'Some error details.'
exc_state = _RPCState((), None, None, status_code, details)
return _Rendezvous(exc_state, None, None, None)
return GrpcRendezvous(exc_state, None, None, None)

def _make_grpc_not_found(self):
from grpc import StatusCode
Expand Down
10 changes: 5 additions & 5 deletions unit_tests/datastore/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,24 +243,24 @@ def _commit_failure_helper(self, exc, err_class):
@unittest.skipUnless(_HAVE_GRPC, 'No gRPC')
def test_commit_failure_aborted(self):
from grpc import StatusCode
from grpc._channel import _Rendezvous
from grpc._channel import _RPCState
from google.cloud.exceptions import Conflict
from google.cloud.exceptions import GrpcRendezvous

details = 'Bad things.'
exc_state = _RPCState((), None, None, StatusCode.ABORTED, details)
exc = _Rendezvous(exc_state, None, None, None)
exc = GrpcRendezvous(exc_state, None, None, None)
self._commit_failure_helper(exc, Conflict)

@unittest.skipUnless(_HAVE_GRPC, 'No gRPC')
def test_commit_failure_cancelled(self):
from grpc import StatusCode
from grpc._channel import _Rendezvous
from grpc._channel import _RPCState
from google.cloud.exceptions import GrpcRendezvous

exc_state = _RPCState((), None, None, StatusCode.CANCELLED, None)
exc = _Rendezvous(exc_state, None, None, None)
self._commit_failure_helper(exc, _Rendezvous)
exc = GrpcRendezvous(exc_state, None, None, None)
self._commit_failure_helper(exc, GrpcRendezvous)

@unittest.skipUnless(_HAVE_GRPC, 'No gRPC')
def test_commit_failure_non_grpc_err(self):
Expand Down
Loading

0 comments on commit b185ee8

Please sign in to comment.