diff --git a/gcloud/logging/_gax.py b/gcloud/logging/_gax.py index 5b70e2abf61a..b4be46e68879 100644 --- a/gcloud/logging/_gax.py +++ b/gcloud/logging/_gax.py @@ -120,7 +120,12 @@ def logger_delete(self, project, logger_name): """ options = None path = 'projects/%s/logs/%s' % (project, logger_name) - self._gax_api.delete_log(path, options) + try: + self._gax_api.delete_log(path, options) + except GaxError as exc: + if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: + raise NotFound(path) + raise class _SinksAPI(object): diff --git a/gcloud/logging/test__gax.py b/gcloud/logging/test__gax.py index ab5e4a616f6c..24eb322dd768 100644 --- a/gcloud/logging/test__gax.py +++ b/gcloud/logging/test__gax.py @@ -406,6 +406,32 @@ def test_logger_delete(self): self.assertEqual(log_name, LOG_PATH) self.assertEqual(options, None) + def test_logger_delete_not_found(self): + from gcloud.exceptions import NotFound + LOG_PATH = 'projects/%s/logs/%s' % (self.PROJECT, self.LOG_NAME) + gax_api = _GAXLoggingAPI(_delete_not_found=True) + api = self._makeOne(gax_api) + + with self.assertRaises(NotFound): + api.logger_delete(self.PROJECT, self.LOG_NAME) + + log_name, options = gax_api._delete_log_called_with + self.assertEqual(log_name, LOG_PATH) + self.assertEqual(options, None) + + def test_logger_delete_error(self): + 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(GaxError): + api.logger_delete(self.PROJECT, self.LOG_NAME) + + log_name, options = gax_api._delete_log_called_with + self.assertEqual(log_name, LOG_PATH) + self.assertEqual(options, None) + @unittest.skipUnless(_HAVE_GAX, 'No gax-python') class Test_SinksAPI(_Base, unittest.TestCase): @@ -914,6 +940,8 @@ def _make_grpc_failed_precondition(self): class _GAXLoggingAPI(_GAXBaseAPI): + _delete_not_found = False + def list_log_entries( self, projects, filter_, order_by, page_size, options): self._list_log_entries_called_with = ( @@ -926,7 +954,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 GaxError('error') + if self._delete_not_found: + raise GaxError('notfound', self._make_grpc_not_found()) class _GAXSinksAPI(_GAXBaseAPI):