diff --git a/google/cloud/logging/_gax.py b/google/cloud/logging/_gax.py index f84ef53b6f42..90230b743f51 100644 --- a/google/cloud/logging/_gax.py +++ b/google/cloud/logging/_gax.py @@ -18,6 +18,8 @@ from google.gax import CallOptions from google.gax import INITIAL_PAGE +from google.gax.errors import GaxError +from google.gax.grpc import exc_to_code from google.logging.type.log_severity_pb2 import LogSeverity from google.logging.v2.logging_config_pb2 import LogSink from google.logging.v2.logging_metrics_pb2 import LogMetric @@ -29,7 +31,6 @@ 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 @@ -122,8 +123,8 @@ def logger_delete(self, project, logger_name): path = 'projects/%s/logs/%s' % (project, logger_name) try: self._gax_api.delete_log(path, options) - except GrpcRendezvous as exc: - if exc.code() == StatusCode.NOT_FOUND: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: raise NotFound(path) raise @@ -194,8 +195,8 @@ def sink_create(self, project, sink_name, filter_, destination): destination=destination) try: self._gax_api.create_sink(parent, sink_pb, options) - except GrpcRendezvous as exc: - if exc.code() == StatusCode.FAILED_PRECONDITION: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.FAILED_PRECONDITION: path = 'projects/%s/sinks/%s' % (project, sink_name) raise Conflict(path) raise @@ -217,8 +218,8 @@ 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 GrpcRendezvous as exc: - if exc.code() == StatusCode.NOT_FOUND: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: raise NotFound(path) raise return _log_sink_pb_to_mapping(sink_pb) @@ -249,8 +250,8 @@ 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 GrpcRendezvous as exc: - if exc.code() == StatusCode.NOT_FOUND: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: raise NotFound(path) raise return _log_sink_pb_to_mapping(sink_pb) @@ -268,8 +269,8 @@ def sink_delete(self, project, sink_name): path = 'projects/%s/sinks/%s' % (project, sink_name) try: self._gax_api.delete_sink(path, options) - except GrpcRendezvous as exc: - if exc.code() == StatusCode.NOT_FOUND: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: raise NotFound(path) raise @@ -339,8 +340,8 @@ def metric_create(self, project, metric_name, filter_, description): description=description) try: self._gax_api.create_log_metric(parent, metric_pb, options) - except GrpcRendezvous as exc: - if exc.code() == StatusCode.FAILED_PRECONDITION: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.FAILED_PRECONDITION: path = 'projects/%s/metrics/%s' % (project, metric_name) raise Conflict(path) raise @@ -362,8 +363,8 @@ 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 GrpcRendezvous as exc: - if exc.code() == StatusCode.NOT_FOUND: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: raise NotFound(path) raise return _log_metric_pb_to_mapping(metric_pb) @@ -394,8 +395,8 @@ def metric_update(self, project, metric_name, filter_, description): description=description) try: self._gax_api.update_log_metric(path, metric_pb, options) - except GrpcRendezvous as exc: - if exc.code() == StatusCode.NOT_FOUND: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: raise NotFound(path) raise return _log_metric_pb_to_mapping(metric_pb) @@ -413,8 +414,8 @@ 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 GrpcRendezvous as exc: - if exc.code() == StatusCode.NOT_FOUND: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: raise NotFound(path) raise diff --git a/google/cloud/pubsub/_gax.py b/google/cloud/pubsub/_gax.py index c05d1f352518..d51342a7ce45 100644 --- a/google/cloud/pubsub/_gax.py +++ b/google/cloud/pubsub/_gax.py @@ -18,6 +18,8 @@ from google.cloud.gapic.pubsub.v1.subscriber_api import SubscriberApi from google.gax import CallOptions from google.gax import INITIAL_PAGE +from google.gax.errors import GaxError +from google.gax.grpc import exc_to_code from google.pubsub.v1.pubsub_pb2 import PubsubMessage from google.pubsub.v1.pubsub_pb2 import PushConfig from grpc import insecure_channel @@ -27,7 +29,6 @@ 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 @@ -92,8 +93,8 @@ def topic_create(self, topic_path): """ try: topic_pb = self._gax_api.create_topic(topic_path) - except GrpcRendezvous as exc: - if exc.code() == StatusCode.FAILED_PRECONDITION: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.FAILED_PRECONDITION: raise Conflict(topic_path) raise return {'name': topic_pb.name} @@ -115,8 +116,8 @@ def topic_get(self, topic_path): """ try: topic_pb = self._gax_api.get_topic(topic_path) - except GrpcRendezvous as exc: - if exc.code() == StatusCode.NOT_FOUND: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: raise NotFound(topic_path) raise return {'name': topic_pb.name} @@ -133,8 +134,8 @@ def topic_delete(self, topic_path): """ try: self._gax_api.delete_topic(topic_path) - except GrpcRendezvous as exc: - if exc.code() == StatusCode.NOT_FOUND: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: raise NotFound(topic_path) raise @@ -162,8 +163,8 @@ def topic_publish(self, topic_path, messages): try: result = self._gax_api.publish(topic_path, message_pbs, options=options) - except GrpcRendezvous as exc: - if exc.code() == StatusCode.NOT_FOUND: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: raise NotFound(topic_path) raise return result.message_ids @@ -200,8 +201,8 @@ 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 GrpcRendezvous as exc: - if exc.code() == StatusCode.NOT_FOUND: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: raise NotFound(topic_path) raise subs = page_iter.next() @@ -293,8 +294,8 @@ 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 GrpcRendezvous as exc: - if exc.code() == StatusCode.FAILED_PRECONDITION: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.FAILED_PRECONDITION: raise Conflict(topic_path) raise return _subscription_pb_to_mapping(sub_pb) @@ -315,8 +316,8 @@ def subscription_get(self, subscription_path): """ try: sub_pb = self._gax_api.get_subscription(subscription_path) - except GrpcRendezvous as exc: - if exc.code() == StatusCode.NOT_FOUND: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: raise NotFound(subscription_path) raise return _subscription_pb_to_mapping(sub_pb) @@ -334,8 +335,8 @@ def subscription_delete(self, subscription_path): """ try: self._gax_api.delete_subscription(subscription_path) - except GrpcRendezvous as exc: - if exc.code() == StatusCode.NOT_FOUND: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: raise NotFound(subscription_path) raise @@ -359,8 +360,8 @@ 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 GrpcRendezvous as exc: - if exc.code() == StatusCode.NOT_FOUND: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: raise NotFound(subscription_path) raise @@ -391,8 +392,8 @@ def subscription_pull(self, subscription_path, return_immediately=False, try: response_pb = self._gax_api.pull( subscription_path, max_messages, return_immediately) - except GrpcRendezvous as exc: - if exc.code() == StatusCode.NOT_FOUND: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: raise NotFound(subscription_path) raise return [_received_message_pb_to_mapping(rmpb) @@ -414,8 +415,8 @@ def subscription_acknowledge(self, subscription_path, ack_ids): """ try: self._gax_api.acknowledge(subscription_path, ack_ids) - except GrpcRendezvous as exc: - if exc.code() == StatusCode.NOT_FOUND: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: raise NotFound(subscription_path) raise @@ -441,8 +442,8 @@ def subscription_modify_ack_deadline(self, subscription_path, ack_ids, try: self._gax_api.modify_ack_deadline( subscription_path, ack_ids, ack_deadline) - except GrpcRendezvous as exc: - if exc.code() == StatusCode.NOT_FOUND: + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: raise NotFound(subscription_path) raise diff --git a/setup.py b/setup.py index f1e9a2eac826..1ea55a2db99e 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ GRPC_PACKAGES = [ 'grpcio >= 1.0.0', - 'google-gax >= 0.13.0, < 0.14dev', + 'google-gax >= 0.14.1, < 0.15dev', 'gapic-google-pubsub-v1 >= 0.9.0, < 0.10dev', 'grpc-google-pubsub-v1 >= 0.9.0, < 0.10dev', 'gapic-google-logging-v2 >= 0.9.0, < 0.10dev', diff --git a/system_tests/logging_.py b/system_tests/logging_.py index 5292c0afce64..dad765bfca80 100644 --- a/system_tests/logging_.py +++ b/system_tests/logging_.py @@ -73,9 +73,10 @@ def _logger_name(): return 'system-tests-logger' + unique_resource_id('-') def _list_entries(self, logger): - from google.cloud.exceptions import GrpcRendezvous + from google.gax.errors import GaxError + inner = RetryResult(_has_entries)(logger.list_entries) - outer = RetryErrors(GrpcRendezvous, _retry_on_unavailable)(inner) + outer = RetryErrors(GaxError, _retry_on_unavailable)(inner) return outer() def test_log_text(self): diff --git a/system_tests/pubsub.py b/system_tests/pubsub.py index 7da8600df946..880810dad1d3 100644 --- a/system_tests/pubsub.py +++ b/system_tests/pubsub.py @@ -15,12 +15,13 @@ import os import unittest +from google.gax.errors import GaxError +from google.gax.grpc import exc_to_code from grpc import StatusCode 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 @@ -32,10 +33,10 @@ def _unavailable(exc): - return exc.code() == StatusCode.UNAVAILABLE + return exc_to_code(exc) == StatusCode.UNAVAILABLE -retry_unavailable = RetryErrors(GrpcRendezvous, _unavailable) +retry_unavailable = RetryErrors(GaxError, _unavailable) class Config(object): diff --git a/unit_tests/_testing.py b/unit_tests/_testing.py index f181b7c94a6b..4ca985ca0086 100644 --- a/unit_tests/_testing.py +++ b/unit_tests/_testing.py @@ -57,14 +57,10 @@ class _GAXBaseAPI(object): def __init__(self, **kw): self.__dict__.update(kw) - def _make_grpc_error(self, status_code=None): + def _make_grpc_error(self, status_code): 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 GrpcRendezvous(exc_state, None, None, None) diff --git a/unit_tests/logging/test__gax.py b/unit_tests/logging/test__gax.py index c27068c2d770..12baa74d5d4a 100644 --- a/unit_tests/logging/test__gax.py +++ b/unit_tests/logging/test__gax.py @@ -423,13 +423,12 @@ def test_logger_delete_not_found(self): self.assertIsNone(options) def test_logger_delete_error(self): - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError LOG_PATH = 'projects/%s/logs/%s' % (self.PROJECT, self.LOG_NAME) gax_api = _GAXLoggingAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.logger_delete(self.PROJECT, self.LOG_NAME) log_name, options = gax_api._delete_log_called_with @@ -504,12 +503,11 @@ def test_list_sinks_w_paging(self): self.assertEqual(options.page_token, TOKEN) def test_sink_create_error(self): - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError gax_api = _GAXSinksAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.sink_create( self.PROJECT, self.SINK_NAME, self.FILTER, self.DESTINATION_URI) @@ -550,12 +548,11 @@ def test_sink_get_error(self): api.sink_get(self.PROJECT, self.SINK_NAME) def test_sink_get_miss(self): - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError gax_api = _GAXSinksAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.sink_get(self.PROJECT, self.SINK_NAME) def test_sink_get_hit(self): @@ -578,12 +575,11 @@ def test_sink_get_hit(self): self.assertIsNone(options) def test_sink_update_error(self): - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError gax_api = _GAXSinksAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.sink_update( self.PROJECT, self.SINK_NAME, self.FILTER, self.DESTINATION_URI) @@ -618,12 +614,11 @@ def test_sink_update_hit(self): self.assertIsNone(options) def test_sink_delete_error(self): - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError gax_api = _GAXSinksAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.sink_delete(self.PROJECT, self.SINK_NAME) def test_sink_delete_miss(self): @@ -712,12 +707,11 @@ def test_list_metrics_w_paging(self): self.assertEqual(options.page_token, TOKEN) def test_metric_create_error(self): - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError gax_api = _GAXMetricsAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.metric_create( self.PROJECT, self.METRIC_NAME, self.FILTER, self.DESCRIPTION) @@ -758,12 +752,11 @@ def test_metric_get_error(self): api.metric_get(self.PROJECT, self.METRIC_NAME) def test_metric_get_miss(self): - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError gax_api = _GAXMetricsAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.metric_get(self.PROJECT, self.METRIC_NAME) def test_metric_get_hit(self): @@ -786,12 +779,11 @@ def test_metric_get_hit(self): self.assertIsNone(options) def test_metric_update_error(self): - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError gax_api = _GAXMetricsAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.metric_update( self.PROJECT, self.METRIC_NAME, self.FILTER, self.DESCRIPTION) @@ -826,12 +818,11 @@ def test_metric_update_hit(self): self.assertIsNone(options) def test_metric_delete_error(self): - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError gax_api = _GAXMetricsAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.metric_delete(self.PROJECT, self.METRIC_NAME) def test_metric_delete_miss(self): @@ -938,11 +929,12 @@ def write_log_entries(self, entries, log_name, resource, labels, entries, log_name, resource, labels, partial_success, options) def delete_log(self, log_name, options): + from google.gax.errors import GaxError self._delete_log_called_with = log_name, options if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') if self._delete_not_found: - raise self._make_grpc_not_found() + raise GaxError('notfound', self._make_grpc_not_found()) class _GAXSinksAPI(_GAXBaseAPI): @@ -955,36 +947,40 @@ def list_sinks(self, parent, page_size, options): return self._list_sinks_response def create_sink(self, parent, sink, options): + from google.gax.errors import GaxError self._create_sink_called_with = parent, sink, options if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') if self._create_sink_conflict: - raise self._make_grpc_failed_precondition() + raise GaxError('conflict', self._make_grpc_failed_precondition()) def get_sink(self, sink_name, options): + from google.gax.errors import GaxError self._get_sink_called_with = sink_name, options if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') try: return self._get_sink_response except AttributeError: - raise self._make_grpc_not_found() + raise GaxError('notfound', self._make_grpc_not_found()) def update_sink(self, sink_name, sink, options=None): + from google.gax.errors import GaxError self._update_sink_called_with = sink_name, sink, options if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') try: return self._update_sink_response except AttributeError: - raise self._make_grpc_not_found() + raise GaxError('notfound', self._make_grpc_not_found()) def delete_sink(self, sink_name, options=None): + from google.gax.errors import GaxError self._delete_sink_called_with = sink_name, options if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') if self._sink_not_found: - raise self._make_grpc_not_found() + raise GaxError('notfound', self._make_grpc_not_found()) class _GAXMetricsAPI(_GAXBaseAPI): @@ -997,36 +993,40 @@ def list_log_metrics(self, parent, page_size, options): return self._list_log_metrics_response def create_log_metric(self, parent, metric, options): + from google.gax.errors import GaxError self._create_log_metric_called_with = parent, metric, options if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') if self._create_log_metric_conflict: - raise self._make_grpc_failed_precondition() + raise GaxError('conflict', self._make_grpc_failed_precondition()) def get_log_metric(self, metric_name, options): + from google.gax.errors import GaxError self._get_log_metric_called_with = metric_name, options if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') try: return self._get_log_metric_response except AttributeError: - raise self._make_grpc_not_found() + raise GaxError('notfound', self._make_grpc_not_found()) def update_log_metric(self, metric_name, metric, options=None): + from google.gax.errors import GaxError self._update_log_metric_called_with = metric_name, metric, options if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') try: return self._update_log_metric_response except AttributeError: - raise self._make_grpc_not_found() + raise GaxError('notfound', self._make_grpc_not_found()) def delete_log_metric(self, metric_name, options=None): + from google.gax.errors import GaxError self._delete_log_metric_called_with = metric_name, options if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') if self._log_metric_not_found: - raise self._make_grpc_not_found() + raise GaxError('notfound', self._make_grpc_not_found()) class _HTTPRequestPB(object): diff --git a/unit_tests/pubsub/test__gax.py b/unit_tests/pubsub/test__gax.py index ad7752c17aa6..4dd061d9cf8e 100644 --- a/unit_tests/pubsub/test__gax.py +++ b/unit_tests/pubsub/test__gax.py @@ -123,12 +123,11 @@ def test_topic_create_already_exists(self): self.assertIsNone(options) def test_topic_create_error(self): - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError gax_api = _GAXPublisherAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.topic_create(self.TOPIC_PATH) topic_path, options = gax_api._create_topic_called_with @@ -160,12 +159,11 @@ def test_topic_get_miss(self): self.assertIsNone(options) def test_topic_get_error(self): - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError gax_api = _GAXPublisherAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.topic_get(self.TOPIC_PATH) topic_path, options = gax_api._get_topic_called_with @@ -195,12 +193,11 @@ def test_topic_delete_miss(self): self.assertIsNone(options) def test_topic_delete_error(self): - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError gax_api = _GAXPublisherAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.topic_delete(self.TOPIC_PATH) topic_path, options = gax_api._delete_topic_called_with @@ -248,15 +245,14 @@ def test_topic_publish_miss_w_attrs_w_bytes_payload(self): def test_topic_publish_error(self): import base64 - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError PAYLOAD = b'This is the message text' B64 = base64.b64encode(PAYLOAD).decode('ascii') MESSAGE = {'data': B64, 'attributes': {}} gax_api = _GAXPublisherAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.topic_publish(self.TOPIC_PATH, [MESSAGE]) topic_path, message_pbs, options = gax_api._publish_called_with @@ -333,12 +329,11 @@ def test_topic_list_subscriptions_miss(self): def test_topic_list_subscriptions_error(self): from google.gax import INITIAL_PAGE - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError gax_api = _GAXPublisherAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.topic_list_subscriptions(self.TOPIC_PATH) topic_path, page_size, options = ( @@ -455,12 +450,11 @@ def test_subscription_create_already_exists(self): self.assertIsNone(options) def test_subscription_create_error(self): - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError gax_api = _GAXSubscriberAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.subscription_create(self.SUB_PATH, self.TOPIC_PATH) name, topic, push_config, ack_deadline, options = ( @@ -505,12 +499,11 @@ def test_subscription_get_miss(self): self.assertIsNone(options) def test_subscription_get_error(self): - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError gax_api = _GAXSubscriberAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.subscription_get(self.SUB_PATH) sub_path, options = gax_api._get_subscription_called_with @@ -540,12 +533,11 @@ def test_subscription_delete_miss(self): self.assertIsNone(options) def test_subscription_delete_error(self): - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError gax_api = _GAXSubscriberAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.subscription_delete(self.TOPIC_PATH) sub_path, options = gax_api._delete_subscription_called_with @@ -578,12 +570,11 @@ def test_subscription_modify_push_config_miss(self): self.assertIsNone(options) def test_subscription_modify_push_config_error(self): - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError gax_api = _GAXSubscriberAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.subscription_modify_push_config( self.SUB_PATH, self.PUSH_ENDPOINT) @@ -645,12 +636,11 @@ def test_subscription_pull_defaults_miss(self): self.assertIsNone(options) def test_subscription_pull_defaults_error(self): - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError gax_api = _GAXSubscriberAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.subscription_pull(self.SUB_PATH) sub_path, max_messages, return_immediately, options = ( @@ -689,14 +679,13 @@ def test_subscription_acknowledge_miss(self): self.assertIsNone(options) def test_subscription_acknowledge_error(self): - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError ACK_ID1 = 'DEADBEEF' ACK_ID2 = 'BEADCAFE' gax_api = _GAXSubscriberAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.subscription_acknowledge(self.SUB_PATH, [ACK_ID1, ACK_ID2]) sub_path, ack_ids, options = gax_api._acknowledge_called_with @@ -741,15 +730,14 @@ def test_subscription_modify_ack_deadline_miss(self): self.assertIsNone(options) def test_subscription_modify_ack_deadline_error(self): - from google.cloud.exceptions import GrpcRendezvous - + from google.gax.errors import GaxError ACK_ID1 = 'DEADBEEF' ACK_ID2 = 'BEADCAFE' NEW_DEADLINE = 90 gax_api = _GAXSubscriberAPI(_random_gax_error=True) api = self._makeOne(gax_api) - with self.assertRaises(GrpcRendezvous): + with self.assertRaises(GaxError): api.subscription_modify_ack_deadline( self.SUB_PATH, [ACK_ID1, ACK_ID2], NEW_DEADLINE) @@ -876,46 +864,51 @@ def list_topics(self, name, page_size, options): return self._list_topics_response def create_topic(self, name, options=None): + from google.gax.errors import GaxError self._create_topic_called_with = name, options if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') if self._create_topic_conflict: - raise self._make_grpc_failed_precondition() + raise GaxError('conflict', self._make_grpc_failed_precondition()) return self._create_topic_response def get_topic(self, name, options=None): + from google.gax.errors import GaxError self._get_topic_called_with = name, options if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') try: return self._get_topic_response except AttributeError: - raise self._make_grpc_not_found() + raise GaxError('miss', self._make_grpc_not_found()) def delete_topic(self, name, options=None): + from google.gax.errors import GaxError self._delete_topic_called_with = name, options if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') if not self._delete_topic_ok: - raise self._make_grpc_not_found() + raise GaxError('miss', self._make_grpc_not_found()) def publish(self, topic, messages, options=None): + from google.gax.errors import GaxError self._publish_called_with = topic, messages, options if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') try: return self._publish_response except AttributeError: - raise self._make_grpc_not_found() + raise GaxError('miss', self._make_grpc_not_found()) def list_topic_subscriptions(self, topic, page_size, options=None): + from google.gax.errors import GaxError self._list_topic_subscriptions_called_with = topic, page_size, options if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') try: return self._list_topic_subscriptions_response except AttributeError: - raise self._make_grpc_not_found() + raise GaxError('miss', self._make_grpc_not_found()) class _GAXSubscriberAPI(_GAXBaseAPI): @@ -932,61 +925,68 @@ def list_subscriptions(self, project, page_size, options=None): def create_subscription(self, name, topic, push_config, ack_deadline_seconds, options=None): + from google.gax.errors import GaxError self._create_subscription_called_with = ( name, topic, push_config, ack_deadline_seconds, options) if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') if self._create_subscription_conflict: - raise self._make_grpc_failed_precondition() + raise GaxError('conflict', self._make_grpc_failed_precondition()) return self._create_subscription_response def get_subscription(self, name, options=None): + from google.gax.errors import GaxError self._get_subscription_called_with = name, options if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') try: return self._get_subscription_response except AttributeError: - raise self._make_grpc_not_found() + raise GaxError('miss', self._make_grpc_not_found()) def delete_subscription(self, name, options=None): + from google.gax.errors import GaxError self._delete_subscription_called_with = name, options if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') if not self._delete_subscription_ok: - raise self._make_grpc_not_found() + raise GaxError('miss', self._make_grpc_not_found()) def modify_push_config(self, name, push_config, options=None): + from google.gax.errors import GaxError self._modify_push_config_called_with = name, push_config, options if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') if not self._modify_push_config_ok: - raise self._make_grpc_not_found() + raise GaxError('miss', self._make_grpc_not_found()) def pull(self, name, max_messages, return_immediately, options=None): + from google.gax.errors import GaxError self._pull_called_with = ( name, max_messages, return_immediately, options) if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') try: return self._pull_response except AttributeError: - raise self._make_grpc_not_found() + raise GaxError('miss', self._make_grpc_not_found()) def acknowledge(self, name, ack_ids, options=None): + from google.gax.errors import GaxError self._acknowledge_called_with = name, ack_ids, options if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') if not self._acknowledge_ok: - raise self._make_grpc_not_found() + raise GaxError('miss', self._make_grpc_not_found()) def modify_ack_deadline(self, name, ack_ids, deadline, options=None): + from google.gax.errors import GaxError self._modify_ack_deadline_called_with = ( name, ack_ids, deadline, options) if self._random_gax_error: - raise self._make_grpc_error() + raise GaxError('error') if not self._modify_ack_deadline_ok: - raise self._make_grpc_not_found() + raise GaxError('miss', self._make_grpc_not_found()) class _TopicPB(object):