Prevents the UnknownApiNameOrVersion error while upgrading google-api-python-client.
Bug: 154879379
Test: acloud create
Change-Id: I6351325244e702e7e6d30e43815da49fed5cabbb
diff --git a/internal/lib/base_cloud_client.py b/internal/lib/base_cloud_client.py
index 6e4400c..52b54d7 100755
--- a/internal/lib/base_cloud_client.py
+++ b/internal/lib/base_cloud_client.py
@@ -83,19 +83,38 @@
An apiclient.discovery.Resource object
"""
http_auth = oauth2_credentials.authorize(httplib2.Http())
- return utils.RetryExceptionType(
- exception_types=cls.RETRIABLE_AUTH_ERRORS,
- max_retries=cls.RETRY_COUNT,
- functor=build,
- sleep_multiplier=cls.RETRY_SLEEP_MULTIPLIER,
- retry_backoff_factor=cls.RETRY_BACKOFF_FACTOR,
- serviceName=cls.API_NAME,
- version=cls.API_VERSION,
- # This is workaround for a known issue of some veriosn
- # of api client.
- # https://github.com/google/google-api-python-client/issues/435
- cache_discovery=False,
- http=http_auth)
+ try:
+ return utils.RetryExceptionType(
+ exception_types=cls.RETRIABLE_AUTH_ERRORS,
+ max_retries=cls.RETRY_COUNT,
+ functor=build,
+ sleep_multiplier=cls.RETRY_SLEEP_MULTIPLIER,
+ retry_backoff_factor=cls.RETRY_BACKOFF_FACTOR,
+ serviceName=cls.API_NAME,
+ version=cls.API_VERSION,
+ # This is workaround for a known issue of some veriosn
+ # of api client.
+ # https://github.com/google/google-api-python-client/issues/435
+ cache_discovery=False,
+ # This is workaround for the errors.UnknownApiNameOrVersion
+ # https://github.com/googleapis/google-api-python-client/issues/1263
+ static_discovery=False,
+ http=http_auth)
+ except TypeError:
+ # TODO(154879379): The change should be merged before the googleapi
+ # upgraded to compatible with old googleapi version which does not
+ # support the argument 'static discovery'. The retry should be
+ # deleted afterward.
+ return utils.RetryExceptionType(
+ exception_types=cls.RETRIABLE_AUTH_ERRORS,
+ max_retries=cls.RETRY_COUNT,
+ functor=build,
+ sleep_multiplier=cls.RETRY_SLEEP_MULTIPLIER,
+ retry_backoff_factor=cls.RETRY_BACKOFF_FACTOR,
+ serviceName=cls.API_NAME,
+ version=cls.API_VERSION,
+ cache_discovery=False,
+ http=http_auth)
@staticmethod
def _ShouldRetry(exception, retry_http_codes,
diff --git a/internal/lib/base_cloud_client_test.py b/internal/lib/base_cloud_client_test.py
index fc75358..7fabfd5 100644
--- a/internal/lib/base_cloud_client_test.py
+++ b/internal/lib/base_cloud_client_test.py
@@ -44,6 +44,7 @@
serviceName=base_cloud_client.BaseCloudApiClient.API_NAME,
version=base_cloud_client.BaseCloudApiClient.API_VERSION,
cache_discovery=False,
+ static_discovery=False,
http=mock.ANY)
def _SetupInitMocks(self):