Merge "Return appropriate error for invalid-port state in create port API."

This commit is contained in:
Jenkins 2012-02-25 18:16:09 +00:00 committed by Gerrit Code Review
commit 543e150d6d
2 changed files with 19 additions and 1 deletions

View File

@ -145,7 +145,11 @@ def port_create(net_id, state=None, op_status=OperationalStatus.UNKNOWN):
session = get_session() session = get_session()
with session.begin(): with session.begin():
port = models.Port(net_id, op_status) 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.add(port)
session.flush() session.flush()
return port return port

View File

@ -526,6 +526,14 @@ class BaseAPIOperationsTest(AbstractAPITest):
custom_req_body=bad_body, expected_res_status=400) custom_req_body=bad_body, expected_res_status=400)
LOG.debug("_test_create_port_badrequest - fmt:%s - END", fmt) 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): def _test_delete_port(self, fmt):
LOG.debug("_test_delete_port - fmt:%s - START", fmt) LOG.debug("_test_delete_port - fmt:%s - START", fmt)
content_type = "application/%s" % fmt content_type = "application/%s" % fmt
@ -1032,6 +1040,12 @@ class BaseAPIOperationsTest(AbstractAPITest):
def test_create_port_badrequest_xml(self): def test_create_port_badrequest_xml(self):
self._test_create_port_badrequest('xml') 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): def test_delete_port_xml(self):
self._test_delete_port('xml') self._test_delete_port('xml')