Enable parameter check before node composition

This patch enabled check for "name" field in request body before
node composition, raise BadRequest exception if if don't exits.
Changed "description" to optional, and will set it to empty string
if it don't exist.

Change-Id: Ib3624ad85e12823c5f6fd6321d3161b88a7b6ecf
Closes-Bug: #1677046
This commit is contained in:
Lin Yang 2017-03-28 15:58:58 -07:00 committed by Anusha Ramineni
parent 65710b799c
commit d0b9f60bba
3 changed files with 14 additions and 2 deletions

View File

@ -217,7 +217,7 @@ node_request_description:
description: |
A description for a new composed node
in: body
required: tree
required: false
type: string
node_request_name:
description: |

View File

@ -77,8 +77,12 @@ class Node(object):
"processor": {}
}
if not("name" in request_body and request_body["name"].strip()):
raise exception.BadRequest(
detail="Please specify a name of the node to compose")
name = request_body["name"]
description = request_body["description"]
# "description" is optional
description = request_body.get("description", "")
compose_request = cls._create_compose_request(name,
description,

View File

@ -73,6 +73,14 @@ class TestAPINodes(unittest.TestCase):
requirements)
self.assertEqual(expected, result)
def test_compose_node_with_wrong_parameters(self):
"""Test compose node with no name input"""
with self.assertRaises(exception.BadRequest) as context:
nodes.Node.compose_node({"no_name": "fake_value"})
self.assertTrue("Please specify a name of the node to compose"
in context.exception.detail)
@mock.patch("valence.db.api.Connection.create_composed_node")
@mock.patch("valence.common.utils.generate_uuid")
@mock.patch("valence.controller.nodes.Node.list_composed_nodes")