fix some pylint warnings.

1. Parent class should have instance variables used in its method(s).
2. remove some unused imports
Patch 2: fix according to comments
Patch 4: fix problem under pep8 1.1
Change-Id: Iafd89a6017b30484fb8da50219be6b4ae073f083
This commit is contained in:
Yong Sheng Gong 2012-05-25 20:10:07 +08:00
parent 686982198c
commit d2a21ec921
13 changed files with 39 additions and 63 deletions

View File

@ -40,6 +40,7 @@ class APIRouter(wsgi.Router):
"""
Base class for Quantum API routes.
"""
_version = None
def __init__(self, options=None):
mapper = self._mapper()

View File

@ -165,6 +165,8 @@ class HeaderSerializer11(HeaderSerializer10):
class QuantumController(object):
""" Base controller class for Quantum API """
# _resource_name will be redefined in sub concrete controller
_resource_name = None
def __init__(self, plugin):
self._plugin = plugin

View File

@ -37,7 +37,9 @@ def create_resource(plugin, version):
class Controller(common.QuantumController):
""" Port API controller for Quantum API """
_resource_name = 'attachment'
# version will be redefined by in child class
version = None
_attachment_ops_param_list = [
{
'param-name': 'id',
@ -53,10 +55,6 @@ class Controller(common.QuantumController):
},
}
def __init__(self, plugin):
self._resource_name = 'attachment'
super(Controller, self).__init__(plugin)
@common.APIFaultWrapper([exception.NetworkNotFound,
exception.PortNotFound])
def get_resource(self, request, tenant_id, network_id, id):
@ -83,15 +81,9 @@ class Controller(common.QuantumController):
class ControllerV10(Controller):
"""Attachment resources controller for Quantum v1.0 API"""
def __init__(self, plugin):
self.version = "1.0"
super(ControllerV10, self).__init__(plugin)
version = "1.0"
class ControllerV11(Controller):
"""Attachment resources controller for Quantum v1.1 API"""
def __init__(self, plugin):
self.version = "1.1"
super(ControllerV11, self).__init__(plugin)
version = "1.1"

View File

@ -15,10 +15,8 @@
import logging
from webob import exc
from quantum.api import api_common as common
from quantum.api import faults
from quantum.api.views import filters
from quantum.api.views import networks as networks_view
from quantum.common import exceptions as exception
@ -41,15 +39,13 @@ def create_resource(plugin, version):
class Controller(common.QuantumController):
""" Network API controller for Quantum API """
_resource_name = 'network'
# version will be redefined in child class
version = None
_network_ops_param_list = [
{'param-name': 'name', 'required': True},
]
def __init__(self, plugin):
self._resource_name = 'network'
super(Controller, self).__init__(plugin)
def _item(self, request, tenant_id, network_id,
net_details=True, port_details=False):
# We expect get_network_details to return information
@ -165,9 +161,7 @@ class ControllerV10(Controller):
},
}
def __init__(self, plugin):
self.version = "1.0"
super(ControllerV10, self).__init__(plugin)
version = "1.0"
class ControllerV11(Controller):
@ -191,6 +185,4 @@ class ControllerV11(Controller):
},
}
def __init__(self, plugin):
self.version = "1.1"
super(ControllerV11, self).__init__(plugin)
version = "1.1"

View File

@ -38,15 +38,13 @@ def create_resource(plugin, version):
class Controller(common.QuantumController):
""" Port API controller for Quantum API """
_resource_name = 'port'
# version will be redefined in child class
version = None
_port_ops_param_list = [
{'param-name': 'state', 'default-value': 'DOWN', 'required': False},
]
def __init__(self, plugin):
self._resource_name = 'port'
super(Controller, self).__init__(plugin)
def _items(self, request, tenant_id, network_id,
port_details=False):
""" Returns a list of ports.
@ -168,9 +166,7 @@ class ControllerV10(Controller):
},
}
def __init__(self, plugin):
self.version = "1.0"
super(ControllerV10, self).__init__(plugin)
version = "1.0"
class ControllerV11(Controller):
@ -186,6 +182,4 @@ class ControllerV11(Controller):
},
}
def __init__(self, plugin):
self.version = "1.1"
super(ControllerV11, self).__init__(plugin)
version = "1.1"

View File

@ -25,7 +25,11 @@ from quantum.api.views import versions as versions_view
LOG = logging.getLogger(__name__)
class Versions(wsgi.Application):
class Versions(object):
@classmethod
def factory(cls, global_config, **local_config):
return cls()
@webob.dec.wsgify(RequestClass=wsgi.Request)
def __call__(self, req):
@ -37,7 +41,7 @@ class Versions(wsgi.Application):
},
{
"id": "v1.1",
"status": "PROPOSED",
"status": "CURRENT",
},
]

View File

@ -21,23 +21,15 @@
"""Utilities and helper functions."""
import base64
import ConfigParser
import datetime
import functools
import inspect
import json
import logging
import os
import random
import re
import socket
import string
import struct
import subprocess
import sys
import time
import types
from quantum.common import exceptions as exception
from quantum.common.exceptions import ProcessExecutionError

View File

@ -364,7 +364,7 @@ class ExtensionManager(object):
resources = []
resources.append(ResourceExtension('extensions',
ExtensionController(self)))
for alias, ext in self.extensions.iteritems():
for ext in self.extensions.itervalues():
try:
resources.extend(ext.get_resources())
except AttributeError:
@ -376,7 +376,7 @@ class ExtensionManager(object):
def get_actions(self):
"""Returns a list of ActionExtension objects."""
actions = []
for alias, ext in self.extensions.iteritems():
for ext in self.extensions.itervalues():
try:
actions.extend(ext.get_actions())
except AttributeError:
@ -388,7 +388,7 @@ class ExtensionManager(object):
def get_request_extensions(self):
"""Returns a list of RequestExtension objects."""
request_exts = []
for alias, ext in self.extensions.iteritems():
for ext in self.extensions.itervalues():
try:
request_exts.extend(ext.get_request_extensions())
except AttributeError:

View File

@ -80,7 +80,9 @@ class QuantumApiService(WsgiService):
items = dict([(k, v) for k, v in conf.items()
if k not in ('__file__', 'here')])
for key, value in sorted(items.items()):
LOG.debug("%(key)-30s %(value)s" % locals())
LOG.debug("%(key)-30s %(value)s" % {'key': key,
'value': value,
})
LOG.debug("*" * 80)
service = cls(app_name, conf_file, conf)
return service

View File

@ -15,8 +15,6 @@
# under the License.
import json
import os
import sys
import unittest
import routes
@ -39,7 +37,6 @@ from quantum.tests.unit.extension_stubs import (
StubBaseAppController,
StubExtension,
StubPlugin,
StubPluginInterface,
)
import quantum.tests.unit.extensions
from quantum import wsgi

View File

@ -310,7 +310,7 @@ class ResponseSerializer(object):
self.body_serializers.update(body_serializers or {})
self.headers_serializer = (headers_serializer or
ResponseHeadersSerializer())
ResponseHeaderSerializer())
def serialize(self, response_data, content_type, action='default'):
"""Serialize a dict into a string and wrap in a wsgi.Request object.