Fixing tox pylint errors in cgts-client component

Below is an explanation/reasoning for the fixes:
    - Unused variable 'resp': This came about when unpacking a
      functions return value into multiple variables. These
      variables were replaced with '_' to signal that they are
      unused.

    - Added "# noqa" to lines referencing self.resource_class(...)
      to suppress a false positive pylint error.

    - importing urlparse on it's own instead of from the six module.

    - Multi line format strings cannot be concatenated together
      using '+'. When this is the case, '.format()' only takes into
      account the last of the strings and you get an error similar
      to "too many values to unpack to format string". The fix is
      to remove the '+'s so python sees it as one big string.

    - Removed unused function _get_pvs() from file
      cgtsclient/v1/ilvg.py

    - Removed unused function _get_cpus() from file
      cgtsclient/v1/inode.py

    - Removed a few imports which became unused from the removal
      of the above functions.

    - Added 4 exceptions which were referenced but never created.

Story: 2002888
Task: 23161

Change-Id: Ia1ed9158db5766fbab279950fdcdcea50789de96
Signed-off-by: Mathieu Robinson <mathieu.robinson@windriver.com>
This commit is contained in:
Mathieu Robinson 2018-07-04 17:01:41 -04:00
parent 967e4f5840
commit 41c563646f
6 changed files with 72 additions and 32 deletions

View File

@ -48,9 +48,9 @@ class Manager(object):
self.api = api
def _create(self, url, body):
resp, body = self.api.json_request('POST', url, body=body)
_, body = self.api.json_request('POST', url, body=body)
if body:
return self.resource_class(self, body)
return self.resource_class(self, body) # noqa
def _upload(self, url, body, data=None):
resp = self.api.upload_request_with_data(
@ -59,11 +59,11 @@ class Manager(object):
def _json_get(self, url, body=None):
"""send a GET request and return a json serialized object"""
resp, body = self.api.json_request('GET', url, body=body)
_, body = self.api.json_request('GET', url, body=body)
return body
def _list(self, url, response_key=None, obj_class=None, body=None):
resp, body = self.api.json_request('GET', url)
_, body = self.api.json_request('GET', url)
if obj_class is None:
obj_class = self.resource_class
@ -81,10 +81,10 @@ class Manager(object):
return [obj_class(self, res, loaded=True) for res in data if res]
def _update(self, url, body, http_method='PATCH', response_key=None):
resp, body = self.api.json_request(http_method, url, body=body)
_, body = self.api.json_request(http_method, url, body=body)
# PATCH/PUT requests may not return a body
if body:
return self.resource_class(self, body)
return self.resource_class(self, body) # noqa
def _delete(self, url):
self.api.raw_request('DELETE', url)

View File

@ -23,7 +23,7 @@ import socket
import httplib2
import six
import six.moves.urllib.parse as urlparse
import urlparse
try:
import ssl
@ -99,10 +99,10 @@ class ServiceCatalog(object):
if not matching_endpoints:
raise exceptions.EndpointNotFound()
elif len(matching_endpoints) > 1:
raise exceptions.AmbiguousEndpoints(matching_endpoints)
raise exceptions.AmbiguousEndpoints(reason=matching_endpoints)
else:
if endpoint_type not in matching_endpoints[0]:
raise exceptions.EndpointTypeNotFound(endpoint_type)
raise exceptions.EndpointTypeNotFound(reason=endpoint_type)
return matching_endpoints[0][endpoint_type]
@ -407,7 +407,7 @@ class HTTPClient(httplib2.Http):
if (endpoint['type'] == 'platform' and endpoint.get('region') == self.region_name):
if self.endpoint_type not in endpoint:
raise exceptions.EndpointTypeNotFound(
self.endpoint_type)
reason=self.endpoint_type)
return endpoint[self.endpoint_type]
raise exceptions.EndpointNotFound()
@ -446,7 +446,7 @@ class HTTPClient(httplib2.Http):
_class = six.moves.http_client.HTTPConnection
else:
msg = 'Unsupported scheme: %s' % parts.scheme
raise exceptions.EndpointException(msg)
raise exceptions.EndpointException(reason=msg)
return (_class, _args, _kwargs)

View File

@ -652,8 +652,8 @@ def build_wrapping_formatters(objs, fields, field_labels, format_spec, add_blank
wrapping_formatters_as_functions = {}
if len(fields) != len(field_labels):
raise Exception("Error in buildWrappingFormatters: " +
"len(fields) = {}, len(field_labels) = {}," +
raise Exception("Error in buildWrappingFormatters: "
"len(fields) = {}, len(field_labels) = {},"
" they must be the same length!".format(len(fields),
len(field_labels)))
field_to_label = {}
@ -672,8 +672,8 @@ def build_wrapping_formatters(objs, fields, field_labels, format_spec, add_blank
for k in format_spec.keys():
if k not in fields:
raise Exception("Error in buildWrappingFormatters: format_spec " +
"specifies a field {} that is not specified " +
raise Exception("Error in buildWrappingFormatters: format_spec "
"specifies a field {} that is not specified "
"in fields : {}".format(k, fields))
format_spec_for_k = copy.deepcopy(format_spec[k])

View File

@ -169,6 +169,63 @@ class AmbiguousAuthSystem(ClientException):
"""Could not obtain token and endpoint using provided credentials."""
pass
class CgtsclientException(Exception):
"""Base Cgts-Client Exception
To correctly use this class, inherit from it and define
a 'message' property. That message will get printf'd
with the keyword arguments provided to the constructor.
"""
message = "An unknown exception occurred."
code = 500
headers = {}
safe = False
def __init__(self, message=None, **kwargs):
self.kwargs = kwargs
if 'code' not in self.kwargs:
try:
self.kwargs['code'] = self.code
except AttributeError:
pass
if not message:
try:
message = self.message % kwargs
except Exception as e:
# kwargs doesn't match a variable in the message
# at least get the core message out if something happened
message = self.message
super(CgtsclientException, self).__init__(message)
def format_message(self):
if self.__class__.__name__.endswith('_Remote'):
return self.args[0]
else:
return unicode(self)
class AmbiguousEndpoints(CgtsclientException):
message = "Endpoints are ambiguous. reason=%(reason)s"
class EndpointTypeNotFound(CgtsclientException):
message = "The type of the endpoint was not found. reason=%(reason)s"
class SslCertificateValidationError(CgtsclientException):
message = "Validation of the Ssl certificate failed. reason=%(reason)s"
class EndpointException(CgtsclientException):
message = "Generic endpoint exception. reason=%(reason)s"
# Alias for backwards compatibility
AmbigiousAuthSystem = AmbiguousAuthSystem

View File

@ -9,7 +9,6 @@
from cgtsclient.common import base
from cgtsclient import exc
from cgtsclient.v1 import ipv as ipv_utils
CREATION_ATTRIBUTES = ['lvm_vg_name', 'ihost_uuid']
@ -55,14 +54,6 @@ class ilvgManager(base.Manager):
return self._update(path, patch)
def _get_pvs(cc, ihost, lvg):
pvs = cc.ipv.list(ihost.uuid)
pv_list = [ipv_utils.get_pv_display_name(pv)
for pv in pvs
if pv.ilvg_uuid and pv.ilvg_uuid == lvg.uuid]
lvg.pvs = pv_list
def _find_ilvg(cc, ihost, ilvg):
if ilvg.isdigit():
try:

View File

@ -9,7 +9,6 @@
from cgtsclient.common import base
from cgtsclient import exc
from cgtsclient.v1 import icpu as icpu_utils
CREATION_ATTRIBUTES = ['numa_node', 'capabilities', 'ihost_uuid']
@ -51,10 +50,3 @@ class inodeManager(base.Manager):
def update(self, inode_id, patch):
path = '/v1/inodes/%s' % inode_id
return self._update(path, patch)
def _get_cpus(cc, ihost, node):
cpus = cc.icpu.list(ihost.uuid)
cpu_list = [icpu_utils.get_cpu_display_name(p) for p in cpus if
p.inode_uuid and p.inode_uuid == node.uuid]
node.cpus = cpu_list