Pylint fixing base_could_client,acloud_main,avd and common_operations.
- fix pylint errors
- Add some pylint disable comments to avoid pylint error temporarily
Bug: None
Test: run pylint
Change-Id: Ibf2ca67631d540cb6dc8d2fa463225cb52860a1e
diff --git a/internal/lib/base_cloud_client.py b/internal/lib/base_cloud_client.py
index e9dd097..67e26b1 100755
--- a/internal/lib/base_cloud_client.py
+++ b/internal/lib/base_cloud_client.py
@@ -13,17 +13,16 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-
"""Base Cloud API Client.
BasicCloudApiCliend does basic setup for a cloud API.
"""
import httplib
import logging
-import os
import socket
import ssl
+# pylint: disable=import-error
from apiclient import errors as gerrors
from apiclient.discovery import build
import apiclient.http
@@ -83,16 +82,17 @@
"""
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,
- http=http_auth)
+ 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,
+ http=http_auth)
- def _ShouldRetry(self, exception, retry_http_codes,
+ @staticmethod
+ def _ShouldRetry(exception, retry_http_codes,
other_retriable_errors):
"""Check if exception is retriable.
@@ -116,12 +116,14 @@
logger.debug("_ShouldRetry: Exception code %s not in %s: %s",
exception.code, retry_http_codes, str(exception))
- logger.debug(
- "_ShouldRetry: Exception %s is not one of %s: %s", type(exception),
- list(other_retriable_errors) + [errors.HttpError], str(exception))
+ logger.debug("_ShouldRetry: Exception %s is not one of %s: %s",
+ type(exception),
+ list(other_retriable_errors) + [errors.HttpError],
+ str(exception))
return False
- def _TranslateError(self, exception):
+ @staticmethod
+ def _TranslateError(exception):
"""Translate the exception to a desired type.
Args:
@@ -137,8 +139,8 @@
if isinstance(exception, gerrors.HttpError):
exception = errors.HttpError.CreateFromHttpError(exception)
if exception.code == errors.HTTP_NOT_FOUND_CODE:
- exception = errors.ResourceNotFoundError(exception.code,
- str(exception))
+ exception = errors.ResourceNotFoundError(
+ exception.code, str(exception))
return exception
def ExecuteOnce(self, api):
@@ -185,12 +187,12 @@
Raises:
See ExecuteOnce.
"""
- retry_http_codes = (self.RETRY_HTTP_CODES if retry_http_codes is None
- else retry_http_codes)
+ retry_http_codes = (self.RETRY_HTTP_CODES
+ if retry_http_codes is None else retry_http_codes)
max_retry = (self.RETRY_COUNT if max_retry is None else max_retry)
sleep = (self.RETRY_SLEEP_MULTIPLIER if sleep is None else sleep)
- backoff_factor = (self.RETRY_BACKOFF_FACTOR if backoff_factor is None
- else backoff_factor)
+ backoff_factor = (self.RETRY_BACKOFF_FACTOR
+ if backoff_factor is None else backoff_factor)
other_retriable_errors = (self.RETRIABLE_ERRORS
if other_retriable_errors is None else
other_retriable_errors)
@@ -212,9 +214,12 @@
return False
return utils.Retry(
- _Handler, max_retries=max_retry, functor=self.ExecuteOnce,
- sleep_multiplier=sleep, retry_backoff_factor=backoff_factor,
- api=api)
+ _Handler,
+ max_retries=max_retry,
+ functor=self.ExecuteOnce,
+ sleep_multiplier=sleep,
+ retry_backoff_factor=backoff_factor,
+ api=api)
def BatchExecuteOnce(self, requests):
"""Execute requests in a batch.
@@ -237,9 +242,8 @@
batch = apiclient.http.BatchHttpRequest()
for request_id, request in requests.iteritems():
- batch.add(request=request,
- callback=_CallBack,
- request_id=request_id)
+ batch.add(
+ request=request, callback=_CallBack, request_id=request_id)
batch.execute()
return results
@@ -278,8 +282,8 @@
max_retry=max_retry or self.RETRY_COUNT,
sleep=sleep or self.RETRY_SLEEP_MULTIPLIER,
backoff_factor=backoff_factor or self.RETRY_BACKOFF_FACTOR,
- other_retriable_errors=other_retriable_errors or
- self.RETRIABLE_ERRORS)
+ other_retriable_errors=other_retriable_errors
+ or self.RETRIABLE_ERRORS)
executor.Execute()
return executor.GetResults()
diff --git a/internal/lib/base_cloud_client_test.py b/internal/lib/base_cloud_client_test.py
index 96eb3c3..3254729 100644
--- a/internal/lib/base_cloud_client_test.py
+++ b/internal/lib/base_cloud_client_test.py
@@ -17,10 +17,12 @@
"""Tests for acloud.internal.lib.base_cloud_client."""
import time
-import apiclient
-import mock
import unittest
+import mock
+
+import apiclient
+
from acloud.internal.lib import base_cloud_client
from acloud.internal.lib import driver_test_lib
from acloud.public import errors
@@ -33,14 +35,9 @@
class BaseCloudApiClientTest(driver_test_lib.BaseDriverTest):
"""Test BaseCloudApiClient."""
- def setUp(self):
- """Set up test."""
- super(BaseCloudApiClientTest, self).setUp()
-
def testInitResourceHandle(self):
"""Test InitResourceHandle."""
# Setup mocks
- mock_credentials = mock.MagicMock()
self.Patch(base_cloud_client, "build")
# Call the method
base_cloud_client.BaseCloudApiClient(mock.MagicMock())
@@ -113,7 +110,9 @@
"r2": (None, error_1),
"r3": (None, error_2)
}
+
self.assertEqual(results, expected_results)
+ # pylint: disable=no-member
self.assertEqual(requests["r1"].execute.call_count, 1)
self.assertEqual(requests["r2"].execute.call_count,
client.RETRY_COUNT + 1)
@@ -147,6 +146,7 @@
api_mock = mock.MagicMock()
api_mock.execute.side_effect = FakeError("fake retriable error.")
+ # pylint: disable=no-member
self.assertRaises(
FakeError,
client.Execute,