]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Return appropriate error for invalid-port state in create port API.
authorMadhav Puri <madhav.puri@gmail.com>
Fri, 24 Feb 2012 06:44:07 +0000 (22:44 -0800)
committerMadhav Puri <madhav.puri@gmail.com>
Fri, 24 Feb 2012 07:05:04 +0000 (23:05 -0800)
Fixes ovs-plugin to return appropriate error code when create port API is passed a port state value other than ACTIVE or DOWN. Fixes bug 919265.

Also added unit-test to test the behavior and verified it using ovs-plugin with devstack.

Change-Id: Ibd4e7bfdf4483c7ad1ef4ca70a336cb164493ae1

quantum/db/api.py
quantum/tests/unit/_test_api.py

index de8c452996270fbbc24c73bebcdd38fc4e3fd7ab..deef3c06e57c93c681db027a000e4e40836abc70 100644 (file)
@@ -145,7 +145,11 @@ def port_create(net_id, state=None, op_status=OperationalStatus.UNKNOWN):
     session = get_session()
     with session.begin():
         port = models.Port(net_id, op_status)
-        port['state'] = state or 'DOWN'
+        if state is None:
+            state = 'DOWN'
+        elif state not in ('ACTIVE', 'DOWN'):
+            raise q_exc.StateInvalid(port_state=state)
+        port['state'] = state
         session.add(port)
         session.flush()
         return port
index 7a444c09db2fa95ae707e0fcbc5b79fa7e68d668..4755ad9f776a70a8177ea2b222f226eaff6ced26 100644 (file)
@@ -526,6 +526,14 @@ class BaseAPIOperationsTest(AbstractAPITest):
                           custom_req_body=bad_body, expected_res_status=400)
         LOG.debug("_test_create_port_badrequest - fmt:%s - END", fmt)
 
+    def _test_create_port_badportstate(self, fmt):
+        LOG.debug("_test_create_port_badportstate - fmt:%s - START", fmt)
+        network_id = self._create_network(fmt)
+        port_state = "BADSTATE"
+        self._create_port(network_id, port_state, fmt,
+                          expected_res_status=self._port_state_invalid_code)
+        LOG.debug("_test_create_port_badportstate - fmt:%s - END", fmt)
+
     def _test_delete_port(self, fmt):
         LOG.debug("_test_delete_port - fmt:%s - START", fmt)
         content_type = "application/%s" % fmt
@@ -1032,6 +1040,12 @@ class BaseAPIOperationsTest(AbstractAPITest):
     def test_create_port_badrequest_xml(self):
         self._test_create_port_badrequest('xml')
 
+    def test_create_port_badportstate_json(self):
+        self._test_create_port_badportstate('json')
+
+    def test_create_port_badportstate_xml(self):
+        self._test_create_port_badportstate('xml')
+
     def test_delete_port_xml(self):
         self._test_delete_port('xml')