]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Merge Trunk
authorSalvatore Orlando <salvatore.orlando@eu.citrix.com>
Wed, 10 Aug 2011 12:09:48 +0000 (13:09 +0100)
committerSalvatore Orlando <salvatore.orlando@eu.citrix.com>
Wed, 10 Aug 2011 12:09:48 +0000 (13:09 +0100)
Resolve conflicts

Remove constraint on duplicate names for tenant's networks and NetworkNameExists exception
Remove PortIsDown exception and related constraint on interface plug

1  2 
quantum/api/attachments.py
quantum/api/faults.py
quantum/api/networks.py
quantum/api/ports.py
quantum/common/exceptions.py
quantum/db/api.py
quantum/plugins/SamplePlugin.py
tests/unit/test_api.py

index acb5bcab30bd5c246f58976291df3d4a163544bd,0000000000000000000000000000000000000000..14f4d940586d7e9c7ae3fd8052e39ca43e645955
mode 100644,000000..100644
--- /dev/null
@@@ -1,88 -1,0 +1,86 @@@
-         except exception.PortIsDown as e:
-             return faults.Fault(faults.PortIsDown(e))
 +# Copyright 2011 Citrix Systems.
 +# 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.
 +
 +import logging
 +
 +from webob import exc
 +
 +from quantum.api import api_common as common
 +from quantum.api import faults
 +from quantum.api.views import attachments as attachments_view
 +from quantum.common import exceptions as exception
 +
 +LOG = logging.getLogger('quantum.api.ports')
 +
 +
 +class Controller(common.QuantumController):
 +    """ Port API controller for Quantum API """
 +
 +    _attachment_ops_param_list = [{
 +        'param-name': 'id',
 +        'required': True}, ]
 +
 +    _serialization_metadata = {
 +        "application/xml": {
 +            "attributes": {
 +                "attachment": ["id"], }
 +        },
 +    }
 +
 +    def __init__(self, plugin):
 +        self._resource_name = 'attachment'
 +        super(Controller, self).__init__(plugin)
 +
 +    def get_resource(self, request, tenant_id, network_id, id):
 +        try:
 +            att_data = self._plugin.get_port_details(
 +                            tenant_id, network_id, id)
 +            builder = attachments_view.get_view_builder(request)
 +            result = builder.build(att_data)['attachment']
 +            return dict(attachment=result)
 +        except exception.NetworkNotFound as e:
 +            return faults.Fault(faults.NetworkNotFound(e))
 +        except exception.PortNotFound as e:
 +            return faults.Fault(faults.PortNotFound(e))
 +
 +    def attach_resource(self, request, tenant_id, network_id, id):
 +        try:
 +            request_params = \
 +                self._parse_request_params(request,
 +                                           self._attachment_ops_param_list)
 +        except exc.HTTPError as e:
 +            return faults.Fault(e)
 +        try:
 +            self._plugin.plug_interface(tenant_id, network_id, id,
 +                                        request_params['id'])
 +            return exc.HTTPNoContent()
 +        except exception.NetworkNotFound as e:
 +            return faults.Fault(faults.NetworkNotFound(e))
 +        except exception.PortNotFound as e:
 +            return faults.Fault(faults.PortNotFound(e))
 +        except exception.PortInUse as e:
 +            return faults.Fault(faults.PortInUse(e))
 +        except exception.AlreadyAttached as e:
 +            return faults.Fault(faults.AlreadyAttached(e))
 +
 +    def detach_resource(self, request, tenant_id, network_id, id):
 +        try:
 +            self._plugin.unplug_interface(tenant_id,
 +                                          network_id, id)
 +            return exc.HTTPNoContent()
 +        except exception.NetworkNotFound as e:
 +            return faults.Fault(faults.NetworkNotFound(e))
 +        except exception.PortNotFound as e:
 +            return faults.Fault(faults.PortNotFound(e))
Simple merge
index 58d105155df88cf5455b388e881cbed01ee989bc,27709eb5941f641ce9d2923681628e9d55e15b81..3f733b8f9c9d792350d94ff5a4866a700041af1e
@@@ -37,10 -37,8 +37,9 @@@ class Controller(common.QuantumControll
              "attributes": {
                  "network": ["id", "name"],
                  "port": ["id", "state"],
-                 "attachment": ["id"]
--            },
 -            "plurals": {"networks": "network"}
++                "attachment": ["id"]},
 +            "plurals": {"networks": "network",
 +                        "ports": "port"}
          },
      }
  
                                             self._network_ops_param_list)
          except exc.HTTPError as e:
              return faults.Fault(e)
 -        try:
 -            network = self._plugin.\
 -                       create_network(tenant_id,
 -                                      request_params['net-name'])
 -            builder = networks_view.get_view_builder(request)
 -            result = builder.build(network)
 -            return dict(networks=result)
 -        except exception.NetworkNameExists as e:
 -            return faults.Fault(faults.NetworkNameExists(e))
 +        network = self._plugin.\
-                        create_network(tenant_id,
-                                       request_params['name'])
++                   create_network(tenant_id,
++                                  request_params['name'])
 +        builder = networks_view.get_view_builder(request)
 +        result = builder.build(network)['network']
 +        #MUST RETURN 202???
 +        return dict(network=result)
  
      def update(self, request, tenant_id, id):
          """ Updates the name for the network with the given id """
index 0568e1575ee5db24559945072d876309e23c696b,042ea673c3a6ac0aee6498e803dc4499db6aec4d..f9a44ea53b83dc1ab232a4a687470a4ebf37f2a3
@@@ -36,9 -36,11 +36,8 @@@ class Controller(common.QuantumControll
      _serialization_metadata = {
          "application/xml": {
              "attributes": {
 -                "port": ["id", "state"], },
 +                "port": ["id", "state"],
-                 "attachment": ["id"]
-                 },
++                "attachment": ["id"]},
              "plurals": {"ports": "port"}
          },
      }
Simple merge
index ebdc3cb1ae2bac858596a0a77e7353b2855daa1f,436df84152becce8ec164e489a84bc4b81cbcedc..0c7e9d218d6ae79979ad8488acc780e6d7be715a
@@@ -78,21 -76,29 +79,33 @@@ def unregister_models()
      BASE.metadata.drop_all(_ENGINE)
  
  
- def network_create(tenant_id, name):
+ def _check_duplicate_net_name(tenant_id, net_name):
++    """Checks whether a network with the same name
++       already exists for the tenant.
++    """
++
++    #TODO(salvatore-orlando): Not used anymore - candidate for removal
      session = get_session()
-     net = None
      try:
          net = session.query(models.Network).\
-           filter_by(tenant_id=tenant_id, name=name).\
+           filter_by(tenant_id=tenant_id, name=net_name).\
            one()
-         raise Exception("Network with name %(name)s already " \
-                         "exists for tenant %(tenant_id)s" % locals())
+         raise q_exc.NetworkNameExists(tenant_id=tenant_id,
+                         net_name=net_name, net_id=net.uuid)
      except exc.NoResultFound:
-         with session.begin():
-             net = models.Network(tenant_id, name)
-             session.add(net)
-             session.flush()
-     return net
+         # this is the "normal" path, as API spec specifies
+         # that net-names are unique within a tenant
+         pass
+ def network_create(tenant_id, name):
+     session = get_session()
 -    _check_duplicate_net_name(tenant_id, name)
+     with session.begin():
+         net = models.Network(tenant_id, name)
+         session.add(net)
+         session.flush()
+         return net
  
  
  def network_list(tenant_id):
index 62feffebc2e30fd73dc8367daf0802c3db0a7a25,9b155a2c14894ef749cd65db4272f4c708ab198e..73b8f256ad67af0064343b816d4a716ef1a5f869
@@@ -405,10 -402,6 +402,7 @@@ class FakePlugin(object)
          specified Virtual Network.
          """
          LOG.debug("FakePlugin.plug_interface() called")
-         # Verify port state
-         if port['state'] == 'DOWN':
-             raise exc.PortIsDown(net_id=net_id, port_id=port_id)
 +        port = self._get_port(tenant_id, net_id, port_id)
          # Validate attachment
          self._validate_attachment(tenant_id, net_id, port_id,
                                    remote_interface_id)
index dc778b0e7002e532323b1bef8479fd778e318082,dfda244c6a9071b584bf7e82c91ec9b2e9e9b7cf..e46032e287b7d795de80600f8f3d5a7a97d6fb41
@@@ -527,6 -440,23 +527,23 @@@ class APITest(unittest.TestCase)
                          show_port_res.body, content_type)
          self.assertEqual({'id': port_id, 'state': new_port_state},
                           port_data['port'])
 -        self.assertEqual(update_port_res.status_int, 200)
+         # now set it back to the original value
+         update_port_req = testlib.update_port_request(self.tenant_id,
+                                                         network_id, port_id,
+                                                         port_state,
+                                                         format)
+         update_port_res = update_port_req.get_response(self.api)
++        self.assertEqual(update_port_res.status_int, 204)
+         show_port_req = testlib.show_port_request(self.tenant_id,
+                                                   network_id, port_id,
+                                                   format)
+         show_port_res = show_port_req.get_response(self.api)
+         self.assertEqual(show_port_res.status_int, 200)
+         port_data = self._port_serializer.deserialize(
+                         show_port_res.body, content_type)
+         self.assertEqual({'id': port_id, 'state': port_state},
+                          port_data['port'])
          LOG.debug("_test_set_port_state - format:%s - END", format)
  
      def _test_set_port_state_networknotfound(self, format):