]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
move faults/exceptions to l2network package,
authorYing Liu <yinliu2@cisco.com>
Thu, 25 Aug 2011 19:30:20 +0000 (12:30 -0700)
committerYing Liu <yinliu2@cisco.com>
Thu, 25 Aug 2011 19:30:20 +0000 (12:30 -0700)
remove unecessary faults definitions
change the portprofile action api's method
fix imports order and other comments issues

extensions/_credential_view.py
extensions/_exceptions.py [deleted file]
extensions/_faults.py [deleted file]
extensions/_novatenant_view.py
extensions/_pprofiles.py
extensions/_qos_view.py
extensions/credential.py
extensions/novatenant.py
extensions/portprofile.py
extensions/qos.py
quantum/plugins/cisco/tests/unit/test_cisco_extension.py

index 453cd8b24d8e19444e6084df8c0cde1ef09d8e88..3c8ce49a4962f2b2f9fc82a67039f8d16c5f9ca1 100644 (file)
@@ -47,12 +47,12 @@ class ViewBuilder(object):
         return credential
     
     def _build_simple(self, credential_data):
-        """Return a simple model of a server."""
+        """Return a simple description of credential."""
         return dict(credential=dict(id=credential_data['credential_id']))
     
     def _build_detail(self, credential_data):
-        """Return a simple model of a server."""
+        """Return a detailed description of credential."""
         
         return dict(credential=dict(id=credential_data['credential_id'],
                                 name=credential_data['user_name'],
-                                password=credential_data['password']))
\ No newline at end of file
+                                password=credential_data['password']))
diff --git a/extensions/_exceptions.py b/extensions/_exceptions.py
deleted file mode 100644 (file)
index 2310d44..0000000
+++ /dev/null
@@ -1,160 +0,0 @@
-"""
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
-# Copyright 2011 Cisco Systems, Inc.  All rights reserved.
-#
-#    Licensed under the Apache License, Version 2.0 (the "License"); you may
-#    not use this file except in compliance with the License. You may obtain
-#    a copy of the License at
-#
-#         http://www.apache.org/licenses/LICENSE-2.0
-#
-#    Unless required by applicable law or agreed to in writing, software
-#    distributed under the License is distributed on an "AS IS" BASIS, 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.
-#
-# @author: Ying Liu, Cisco Systems, Inc.
-#
-"""
-import logging
-
-
-# pylint: disable-msg=E0602
-class ExtensionException(Exception):
-    """Quantum Cisco api Exception
-    
-    Taken from nova.exception.NovaException
-    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.")
-
-    def __init__(self, **kwargs):
-        try:
-            self._error_string = self.message % kwargs
-
-        except Exception:
-            # at least get the core message out if something happened
-            self._error_string = self.message
-
-    def __str__(self):
-        """Error Msg"""
-        return self._error_string
-
-
-class ProcessExecutionError(IOError):
-    """Process Exe Error"""
-    def __init__(self, stdout=None, stderr=None, exit_code=None, cmd=None,
-                 description=None):
-        if description is None:
-            description = "Unexpected error while running command."
-        if exit_code is None:
-            exit_code = '-'
-        message = "%s\nCommand: %s\nExit code: %s\nStdout: %r\nStderr: %r" % (
-                  description, cmd, exit_code, stdout, stderr)
-        IOError.__init__(self, message)
-
-
-class Error(Exception):
-    """Error Class"""
-    def __init__(self, message=None):
-        super(Error, self).__init__(message)
-
-
-class ApiError(Error):
-    """Api Error"""
-    def __init__(self, message='Unknown', code='Unknown'):
-        self.message = message
-        self.code = code
-        super(ApiError, self).__init__('%s: %s' % (code, message))
-
-
-class NotFound(ExtensionException):
-    """Error Msg"""
-    pass
-
-
-class ClassNotFound(NotFound):
-    """Extension Error Msg"""
-    message = _("Class %(class_name)s could not be found")
-
-
-class PortprofileNotFound(NotFound):
-    """Extension Error Msg"""
-    message = _("Portprofile %(_id)s could not be found")
-    
-    
-class NovatenantNotFound(NotFound):
-    """Extension Error Msg"""
-    message = _("Novatenant %(_id)s could not be found")
-
-
-class PortNotFound(NotFound):
-    """Extension Error"""
-    message = _("Port %(port_id)s could not be found " \
-                "on Network %(net_id)s")
-    
-    
-class CredentialNotFound(NotFound):
-    """Extension Error"""
-    message = _("Credential %(_id)s could not be found")
-    
-    
-class QosNotFound(NotFound):
-    """Extension Error"""
-    message = _("QoS %(_id)s could not be found")
-    
-
-class Duplicate(Error):
-    """Duplication Error"""
-    pass
-
-
-class NotAuthorized(Error):
-    "Not Auth Error"
-    pass
-
-
-class NotEmpty(Error):
-    """Not Empty Error"""
-    pass
-
-
-class Invalid(Error):
-    """Invalid Error"""
-    pass
-
-
-class InvalidContentType(Invalid):
-    message = _("Invalid content type %(content_type)s.")
-
-
-class BadInputError(Exception):
-    """Error resulting from a client sending bad input to a server"""
-    pass
-
-
-class MissingArgumentError(Error):
-    """Miss arg error"""
-    pass
-
-
-def wrap_exception(afunc):
-    """Wrap Exception"""
-    def _wrap(*args, **kw):
-        """Internal Wrap Exception func"""
-        try:
-            return afunc(*args, **kw)
-        except Exception, exp:
-            if not isinstance(exp, Error):
-                #exc_type, exc_value, exc_traceback = sys.exc_info()
-                logging.exception('Uncaught exception')
-                #logging.error(traceback.extract_stack(exc_traceback))
-                raise Error(str(exp))
-            raise
-    _wrap.func_name = afunc.func_name
-    return _wrap
diff --git a/extensions/_faults.py b/extensions/_faults.py
deleted file mode 100644 (file)
index 5b9c233..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-"""
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
-# Copyright 2011 Cisco Systems, Inc.  All rights reserved.
-#
-#    Licensed under the Apache License, Version 2.0 (the "License"); you may
-#    not use this file except in compliance with the License. You may obtain
-#    a copy of the License at
-#
-#         http://www.apache.org/licenses/LICENSE-2.0
-#
-#    Unless required by applicable law or agreed to in writing, software
-#    distributed under the License is distributed on an "AS IS" BASIS, 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.
-#
-# @author: Ying Liu, Cisco Systems, Inc.
-#
-"""
-import webob.dec
-
-from quantum.common import wsgi
-
-
-class Fault(webob.exc.HTTPException):
-    """Error codes for API faults"""
-
-    _fault_names = {
-            400: "malformedRequest",
-            401: "unauthorized",
-            420: "networkNotFound",
-            421: "PortprofileInUse",
-            430: "portNotFound",
-            431: "requestedStateInvalid",
-            432: "portInUse",
-            440: "alreadyAttached",
-            450: "PortprofileNotFound",
-            451: "CredentialNotFound",
-            452: "QoSNotFound",
-            453: "NovatenantNotFound",
-            470: "serviceUnavailable",
-            471: "pluginFault"}
-
-    def __init__(self, exception):
-        """Create a Fault for the given webob.exc.exception."""
-        self.wrapped_exc = exception
-
-    @webob.dec.wsgify(RequestClass=wsgi.Request)
-    def __call__(self, req):
-        """Generate a WSGI response based on the
-         exception passed to constructor."""
-        # Replace the body with fault details.
-        code = self.wrapped_exc.status_int
-        fault_name = self._fault_names.get(code, "quantumServiceFault")
-        fault_data = {
-            fault_name: {
-                'code': code,
-                'message': self.wrapped_exc.explanation}}
-        # 'code' is an attribute on the fault tag itself
-        content_type = req.best_match_content_type()
-        self.wrapped_exc.body = wsgi.Serializer().\
-        serialize(fault_data, content_type)
-        self.wrapped_exc.content_type = content_type
-        return self.wrapped_exc
-
-
-class PortprofileNotFound(webob.exc.HTTPClientError):
-    """
-    subclass of :class:`~HTTPClientError`
-
-    This indicates that the server did not find the Portprofile specified
-    in the HTTP request
-
-    code: 450, title: Portprofile not Found
-    """
-    code = 450
-    title = 'Portprofile Not Found'
-    explanation = ('Unable to find a Portprofile with' 
-                   + ' the specified identifier.')
-
-
-class PortNotFound(webob.exc.HTTPClientError):
-    """
-    subclass of :class:`~HTTPClientError`
-
-    This indicates that the server did not find the port specified
-    in the HTTP request for a given network
-
-    code: 430, title: Port not Found
-    """
-    code = 430
-    title = 'Port not Found'
-    explanation = ('Unable to find a port with the specified identifier.')
-    
-    
-class CredentialNotFound(webob.exc.HTTPClientError):
-    """
-    subclass of :class:`~HTTPClientError`
-
-    This indicates that the server did not find the Credential specified
-    in the HTTP request
-
-    code: 460, title: Credential not Found
-    """
-    code = 451
-    title = 'Credential Not Found'
-    explanation = ('Unable to find a Credential with' 
-                   + ' the specified identifier.')
-  
-    
-class QosNotFound(webob.exc.HTTPClientError):
-    """
-    subclass of :class:`~HTTPClientError`
-
-    This indicates that the server did not find the QoS specified
-    in the HTTP request
-
-    code: 480, title: QoS not Found
-    """
-    code = 452
-    title = 'QoS Not Found'
-    explanation = ('Unable to find a QoS with' 
-                   + ' the specified identifier.')
-  
-    
-class NovatenantNotFound(webob.exc.HTTPClientError):
-    """
-    subclass of :class:`~HTTPClientError`
-
-    This indicates that the server did not find the Novatenant specified
-    in the HTTP request
-
-    code: 480, title: Nova tenant not Found
-    """
-    code = 453
-    title = 'Nova tenant Not Found'
-    explanation = ('Unable to find a Novatenant with' 
-                   + ' the specified identifier.')
-
-
-class RequestedStateInvalid(webob.exc.HTTPClientError):
-    """
-    subclass of :class:`~HTTPClientError`
-
-    This indicates that the server could not update the port state to
-    to the request value
-
-    code: 431, title: Requested State Invalid
-    """
-    code = 431
-    title = 'Requested State Invalid'
-    explanation = ('Unable to update port state with specified value.')
index 6843361fb212d0ef1b1157217d9719dcacc053da..a25654916e75afd36039898d6926ce2afedc0614 100644 (file)
@@ -18,6 +18,7 @@
 # @author: Ying Liu, Cisco Systems, Inc.
 #
 """
+from quantum.plugins.cisco.common import cisco_constants as const
 
 
 def get_view_builder(req):
@@ -39,8 +40,8 @@ class ViewBuilder(object):
     
     def build_host(self, host_data):
         """Return host description."""
-        return dict(host_list=host_data['host_list'])
+        return dict(host_list=host_data[const.HOST_LIST])
     
     def build_vif(self, vif_data):
         """Return VIF description."""
-        return dict(vif_desc=vif_data['vif_desc'])   
+        return dict(vif_desc=vif_data[const.VIF_DESC])   
index ba94c472bcf81fb7b8d6a2d6bef19b9bf224dd4e..cf851bae085171bdb956e423fff7b6ab230ded0e 100644 (file)
@@ -47,7 +47,7 @@ class ViewBuilder(object):
         return portprofile
     
     def _build_simple(self, portprofile_data):
-        """Return a simple model of a portprofile"""
+        """Return a simple description of a portprofile"""
         return dict(portprofile=dict(id=portprofile_data['profile_id']))
     
     def _build_detail(self, portprofile_data):
index ca3f76caf1e54ad7a0be435bdd22915ba84bcc82..3ad0d30c3c99a210e2772f1dbf4e080bc3b2bafd 100644 (file)
@@ -46,11 +46,11 @@ class ViewBuilder(object):
         return qos
     
     def _build_simple(self, qos_data):
-        """Return a simple model of a server."""
+        """Return a simple description of qos."""
         return dict(qos=dict(id=qos_data['qos_id']))
     
     def _build_detail(self, qos_data):
-        """Return a simple model of a server."""
+        """Return a detailed description of qos."""
         return dict(qos=dict(id=qos_data['qos_id'],
                                 name=qos_data['qos_name'],
                                 description=qos_data['qos_desc']))
index 0b69284818385c3072cbb3a67859afaea6c80085..31c49bdd0979490f07b3e4f5c11c310b2f50c1fe 100644 (file)
 import logging
 
 from webob import exc
-from extensions import _credential_view as credential_view
-from quantum.plugins.cisco.common import cisco_exceptions as exception
-from extensions import _faults as faults
 
+from extensions import _credential_view as credential_view
 from quantum.api import api_common as common
 from quantum.common import extensions
 from quantum.manager import QuantumManager
+from quantum.plugins.cisco.common import cisco_exceptions as exception
+from quantum.plugins.cisco.common import cisco_faults as faults
 
 LOG = logging.getLogger('quantum.api.credentials')
 
@@ -36,7 +36,7 @@ class Credential(object):
     """extension class Credential"""
     def __init__(self):
         pass
-    
+
     @classmethod
     def get_name(cls):
         """ Returns Ext Resource Name """
@@ -67,7 +67,6 @@ class Credential(object):
         """ Returns Ext Resources """
         parent_resource = dict(member_name="tenant",
                                collection_name="extensions/csco/tenants")
-       
         controller = CredentialController(QuantumManager.get_plugin())
         return [extensions.ResourceExtension('credentials', controller,
                                              parent=parent_resource)]
@@ -84,7 +83,7 @@ class CredentialController(common.QuantumController):
         'required': True}, {
         'param-name': 'password',
         'required': True}]
-   
+
     _serialization_metadata = {
         "application/xml": {
             "attributes": {
@@ -96,7 +95,7 @@ class CredentialController(common.QuantumController):
     def __init__(self, plugin):
         self._resource_name = 'credential'
         self._plugin = plugin
-             
+
     def index(self, request, tenant_id):
         """ Returns a list of credential ids """
         return self._items(request, tenant_id, is_detail=False)
@@ -165,4 +164,3 @@ class CredentialController(common.QuantumController):
             return exc.HTTPAccepted()
         except exception.CredentialNotFound as exp:
             return faults.Fault(faults.CredentialNotFound(exp))
-        
index c4ab55db0bd45697eb4afb2bdb205cbf3a0afbd0..84453ccfb51a37d21a4d7430704936c8935676d0 100644 (file)
 from webob import exc
 
 from extensions import _novatenant_view as novatenant_view
-from quantum.common import exceptions as qexception
-from extensions import _faults as faults
-
 from quantum.api import api_common as common
+from quantum.common import exceptions as qexception
 from quantum.common import extensions
 from quantum.manager import QuantumManager
+from quantum.plugins.cisco.common import cisco_faults as faults
 
 
 class Novatenant(object):
@@ -97,33 +96,9 @@ class NovatenantsController(common.QuantumController):
     def __init__(self, plugin):
         self._resource_name = 'novatenant'
         self._plugin = plugin
-             
-    def index(self, request, tenant_id):
-        """ Returns a list of novatenant ids """
-        return "novatenant is a dummy resource"
-
-    def _items(self, request, tenant_id, is_detail):
-        """ Returns a list of novatenants. """
-        return "novatenant is a dummy resource"
-
-    # pylint: disable-msg=E1101,W0613
-    def show(self, request, tenant_id, id):
-        """ Returns novatenant details for the given novatenant id """
-        return "novatenant is a dummy resource"
-
-    def create(self, request, tenant_id):
-        """ Creates a new novatenant for a given tenant """
-        return "novatenant is a dummy resource"
-
-    def update(self, request, tenant_id, id):
-        """ Updates the name for the novatenant with the given id """
-        return "novatenant is a dummy resource"
-
-    def delete(self, request, tenant_id, id):
-        """ Destroys the Novatenant with the given id """
-        return "novatenant is a dummy resource"
-         
+                  
     #added for cisco's extension
+    # pylint: disable-msg=E1101,W0613
     def get_host(self, request, tenant_id, id):
         content_type = request.best_match_content_type()
         print "Content type:%s" % content_type
index c20eea3ac9dd491acf8c16af490d0573ef3d7959..4dd9c7b41c1686f9f861b37f39ed86a66779a296 100644 (file)
 from webob import exc
 
 from extensions import _pprofiles as pprofiles_view
-from quantum.plugins.cisco.common import cisco_exceptions as exception
-from quantum.common import exceptions as qexception
-from extensions import _faults as faults
-
 from quantum.api import api_common as common
+from quantum.common import exceptions as qexception
 from quantum.common import extensions
 from quantum.manager import QuantumManager
+from quantum.plugins.cisco.common import cisco_exceptions as exception
+from quantum.plugins.cisco.common import cisco_faults as faults
 
 
 class Portprofile(object):
@@ -67,7 +66,7 @@ class Portprofile(object):
         parent_resource = dict(member_name="tenant", 
                                collection_name="extensions/csco/tenants")
         member_actions = {'associate_portprofile': "PUT",
-                          'disassociate_portprofile': "POST"}
+                          'disassociate_portprofile': "PUT"}
         controller = PortprofilesController(QuantumManager.get_plugin())
         return [extensions.ResourceExtension('portprofiles', controller,
                                              parent=parent_resource,
index bcff6de8af4a41b8d1e7f7847e122e307fb30b8d..6e8cb723349d4241ec3047f0d09406a7094ee4e9 100644 (file)
@@ -22,13 +22,12 @@ import logging
 
 from webob import exc
 from extensions import _qos_view as qos_view
-from quantum.plugins.cisco.common import cisco_exceptions as exception
-from extensions import _exceptions as exte
-from extensions import _faults as faults
-
 from quantum.api import api_common as common
 from quantum.common import extensions
 from quantum.manager import QuantumManager
+from quantum.plugins.cisco.common import cisco_exceptions as exception
+from quantum.plugins.cisco.common import cisco_faults as faults
+
 
 LOG = logging.getLogger('quantum.api.qoss')
 
index a6bbe3c6492a7acd58e686e7fcf8da42e8a5014c..e1f2391bf4044aaddcf67ed224ac4877c689aaac 100644 (file)
@@ -68,7 +68,7 @@ class PortprofileExtensionTest(unittest.TestCase):
         parent_resource = dict(member_name="tenant",
                                collection_name="extensions/csco/tenants")
         member_actions = {'associate_portprofile': "PUT",
-                          'disassociate_portprofile': "POST"}
+                          'disassociate_portprofile': "PUT"}
         controller = portprofile.PortprofilesController(
                                QuantumManager.get_plugin())
         res_ext = extensions.ResourceExtension('portprofiles', controller,
@@ -206,7 +206,7 @@ class PortprofileExtensionTest(unittest.TestCase):
         rename_response = self.test_app.put(rename_path, rename_req_body)
         self.assertEqual(200, rename_response.status_int)
 
-         # Clean Up - Delete the Port Profile
+        # Clean Up - Delete the Port Profile
         self.tear_down_profile(rename_path)
         LOG.debug("test_update_portprofile - END")
 
@@ -410,7 +410,7 @@ class PortprofileExtensionTest(unittest.TestCase):
                             "/disassociate_portprofile"
 
         disassociate_path = str(disassociate_path_temp)
-        disassociate_response = self.test_app.post(
+        disassociate_response = self.test_app.put(
                                      disassociate_path, req_assign_body,
                                      content_type=self.contenttype)
         self.assertEqual(202, disassociate_response.status_int)
@@ -433,7 +433,7 @@ class PortprofileExtensionTest(unittest.TestCase):
 
         """ Tear down associate profile"""
 
-        self.test_app.post(dissociate_profile_path, req_body,
+        self.test_app.put(dissociate_profile_path, req_body,
                            content_type=self.contenttype)
         self.tear_down_profile(delete_profile_path)
 
@@ -475,8 +475,8 @@ class NovatenantExtensionTest(unittest.TestCase):
         req_body = json.dumps(self.test_instance_data)
         host_path = self.novatenants_path + "001/get_host"
         host_response = self.test_app.put(
-                                  host_path, req_body,
-                                  content_type=self.contenttype)
+                                 host_path, req_body,
+                                 content_type=self.contenttype)
         self.assertEqual(200, host_response.status_int)
         LOG.debug("test_get_host - END")
 
@@ -487,8 +487,8 @@ class NovatenantExtensionTest(unittest.TestCase):
         LOG.debug("test_get_hostBADRequest - START")
         host_path = self.novatenants_path + "001/get_host"
         host_response = self.test_app.put(
-                                  host_path, 'BAD_REQUEST',
-                                  content_type=self.contenttype, status='*')
+                                 host_path, 'BAD_REQUEST',
+                                content_type=self.contenttype, status='*')
         self.assertEqual(400, host_response.status_int)
         LOG.debug("test_get_hostBADRequest - END")