Skip to content

Commit a5bb176

Browse files
authored
Merge pull request #2094 from tseaver/2091-logging-gax-logger-delete-raise-not-found
logger_delete: map gRPC 'NOT_FOUND' error onto our 'NotFound' exception.
2 parents d71c0d4 + 11cfa64 commit a5bb176

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

gcloud/logging/_gax.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,12 @@ def logger_delete(self, project, logger_name):
120120
"""
121121
options = None
122122
path = 'projects/%s/logs/%s' % (project, logger_name)
123-
self._gax_api.delete_log(path, options)
123+
try:
124+
self._gax_api.delete_log(path, options)
125+
except GaxError as exc:
126+
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
127+
raise NotFound(path)
128+
raise
124129

125130

126131
class _SinksAPI(object):

gcloud/logging/test__gax.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,32 @@ def test_logger_delete(self):
406406
self.assertEqual(log_name, LOG_PATH)
407407
self.assertEqual(options, None)
408408

409+
def test_logger_delete_not_found(self):
410+
from gcloud.exceptions import NotFound
411+
LOG_PATH = 'projects/%s/logs/%s' % (self.PROJECT, self.LOG_NAME)
412+
gax_api = _GAXLoggingAPI(_delete_not_found=True)
413+
api = self._makeOne(gax_api)
414+
415+
with self.assertRaises(NotFound):
416+
api.logger_delete(self.PROJECT, self.LOG_NAME)
417+
418+
log_name, options = gax_api._delete_log_called_with
419+
self.assertEqual(log_name, LOG_PATH)
420+
self.assertEqual(options, None)
421+
422+
def test_logger_delete_error(self):
423+
from google.gax.errors import GaxError
424+
LOG_PATH = 'projects/%s/logs/%s' % (self.PROJECT, self.LOG_NAME)
425+
gax_api = _GAXLoggingAPI(_random_gax_error=True)
426+
api = self._makeOne(gax_api)
427+
428+
with self.assertRaises(GaxError):
429+
api.logger_delete(self.PROJECT, self.LOG_NAME)
430+
431+
log_name, options = gax_api._delete_log_called_with
432+
self.assertEqual(log_name, LOG_PATH)
433+
self.assertEqual(options, None)
434+
409435

410436
@unittest.skipUnless(_HAVE_GAX, 'No gax-python')
411437
class Test_SinksAPI(_Base, unittest.TestCase):
@@ -914,6 +940,8 @@ def _make_grpc_failed_precondition(self):
914940

915941
class _GAXLoggingAPI(_GAXBaseAPI):
916942

943+
_delete_not_found = False
944+
917945
def list_log_entries(
918946
self, projects, filter_, order_by, page_size, options):
919947
self._list_log_entries_called_with = (
@@ -926,7 +954,12 @@ def write_log_entries(self, entries, log_name, resource, labels,
926954
entries, log_name, resource, labels, partial_success, options)
927955

928956
def delete_log(self, log_name, options):
957+
from google.gax.errors import GaxError
929958
self._delete_log_called_with = log_name, options
959+
if self._random_gax_error:
960+
raise GaxError('error')
961+
if self._delete_not_found:
962+
raise GaxError('notfound', self._make_grpc_not_found())
930963

931964

932965
class _GAXSinksAPI(_GAXBaseAPI):

0 commit comments

Comments
 (0)