[arvados] updated: 2.6.0-250-gd17049c21
git repository hosting
git at public.arvados.org
Wed Jun 7 14:24:43 UTC 2023
Summary of changes:
sdk/python/arvados/api.py | 26 +++++++++++++-----------
sdk/python/tests/test_api.py | 47 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 12 deletions(-)
via d17049c214dda2a37a928b6ac1a4a348c8d3c9e2 (commit)
from 07ae0247ca233cd61d65dc600b8074c67291e3c0 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit d17049c214dda2a37a928b6ac1a4a348c8d3c9e2
Author: Brett Smith <brett.smith at curii.com>
Date: Wed Jun 7 10:24:04 2023 -0400
20613: Deconfigure logger after an exception
Arvados-DCO-1.1-Signed-off-by: Brett Smith <brett.smith at curii.com>
diff --git a/sdk/python/arvados/api.py b/sdk/python/arvados/api.py
index eb625c934..a1493b904 100644
--- a/sdk/python/arvados/api.py
+++ b/sdk/python/arvados/api.py
@@ -276,18 +276,20 @@ def api_client(
client_logger.setLevel(client_level)
else:
client_logger.setLevel(client_filter.retry_levelno)
- svc = apiclient_discovery.build(
- 'arvados', version,
- cache_discovery=False,
- discoveryServiceUrl=discoveryServiceUrl,
- http=http,
- num_retries=num_retries,
- **kwargs,
- )
- if client_logger_unconfigured:
- client_logger.removeHandler(log_handler)
- client_logger.removeFilter(client_filter)
- client_logger.setLevel(client_level)
+ try:
+ svc = apiclient_discovery.build(
+ 'arvados', version,
+ cache_discovery=False,
+ discoveryServiceUrl=discoveryServiceUrl,
+ http=http,
+ num_retries=num_retries,
+ **kwargs,
+ )
+ finally:
+ if client_logger_unconfigured:
+ client_logger.removeHandler(log_handler)
+ client_logger.removeFilter(client_filter)
+ client_logger.setLevel(client_level)
svc.api_token = token
svc.insecure = insecure
svc.request_id = request_id
diff --git a/sdk/python/tests/test_api.py b/sdk/python/tests/test_api.py
index 8667d5160..65d804ebb 100644
--- a/sdk/python/tests/test_api.py
+++ b/sdk/python/tests/test_api.py
@@ -11,6 +11,7 @@ import contextlib
import httplib2
import itertools
import json
+import logging
import mimetypes
import os
import socket
@@ -29,8 +30,10 @@ from arvados.api import (
normalize_api_kwargs,
api_kwargs_from_config,
OrderedJsonModel,
+ _googleapiclient_log_lock,
)
from .arvados_testutil import fake_httplib2_response, mock_api_responses, queue_with
+import httplib2.error
if not mimetypes.inited:
mimetypes.init()
@@ -391,6 +394,50 @@ class ArvadosApiTest(run_test_server.TestCaseWithServers):
args[arg_index] = arg_value
api_client(*args, insecure=True)
+ def test_initial_retry_logs(self):
+ try:
+ _googleapiclient_log_lock.release()
+ except RuntimeError:
+ # Lock was never acquired - that's the state we want anyway
+ pass
+ real_logger = logging.getLogger('googleapiclient.http')
+ mock_logger = mock.Mock(wraps=real_logger)
+ mock_logger.hasHandlers.return_value = False
+ mock_logger.level = logging.NOTSET
+ with (
+ mock.patch('logging.getLogger', return_value=mock_logger),
+ mock.patch('time.sleep'),
+ self.assertLogs(real_logger, 'INFO') as actual_logs,
+ ):
+ try:
+ api_client('v1', 'https://test.invalid/', 'NoToken', num_retries=1)
+ except httplib2.error.ServerNotFoundError:
+ pass
+ mock_logger.addFilter.assert_called()
+ mock_logger.addHandler.assert_called()
+ mock_logger.setLevel.assert_called()
+ mock_logger.removeHandler.assert_called()
+ mock_logger.removeFilter.assert_called()
+ self.assertRegex(actual_logs.output[0], r'^INFO:googleapiclient\.http:Sleeping \d')
+
+ def test_configured_logger_untouched(self):
+ real_logger = logging.getLogger('googleapiclient.http')
+ mock_logger = mock.Mock(wraps=real_logger)
+ mock_logger.hasHandlers.return_value = True
+ with (
+ mock.patch('logging.getLogger', return_value=mock_logger),
+ mock.patch('time.sleep'),
+ ):
+ try:
+ api_client('v1', 'https://test.invalid/', 'NoToken', num_retries=1)
+ except httplib2.error.ServerNotFoundError:
+ pass
+ mock_logger.addFilter.assert_not_called()
+ mock_logger.addHandler.assert_not_called()
+ mock_logger.setLevel.assert_not_called()
+ mock_logger.removeHandler.assert_not_called()
+ mock_logger.removeFilter.assert_not_called()
+
class ConstructNumRetriesTestCase(unittest.TestCase):
@staticmethod
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list