Follow-up patch of 8e5e69869d

This patch is a follow-up patch of
8e5e69869d addressing some the remaining
comments after the patch was merged. The changes are:

* Optimize the code by generating the list of reserved words for the
  nodes controller only once.

* List the reserved words in the release note.

* Improve the error string when someone tries to name a node using a
  reserved word.

* Add a comment for future reference indicating how we should try to
  model the API in case a new sub-controller needs to be added to the
  nodes controller class.

Change-Id: I43d6d9e2e92cc941a7839c60d9cd361cd94b6208
This commit is contained in:
Lucas Alvares Gomes 2016-05-09 16:11:56 +01:00 committed by Ruby Loo
parent 9996949e8e
commit 6be3448d40
2 changed files with 20 additions and 4 deletions

View File

@ -96,6 +96,16 @@ PROVISION_ACTION_STATES = (ir_states.VERBS['manage'],
ir_states.VERBS['provide'],
ir_states.VERBS['abort'])
_NODES_CONTROLLER_RESERVED_WORDS = None
def get_nodes_controller_reserved_names():
global _NODES_CONTROLLER_RESERVED_WORDS
if _NODES_CONTROLLER_RESERVED_WORDS is None:
_NODES_CONTROLLER_RESERVED_WORDS = (
api_utils.get_controller_reserved_names(NodesController))
return _NODES_CONTROLLER_RESERVED_WORDS
def hide_fields_in_newer_versions(obj):
# if requested version is < 1.3, hide driver_internal_info
@ -924,6 +934,12 @@ class NodeMaintenanceController(rest.RestController):
class NodesController(rest.RestController):
"""REST controller for Nodes."""
# NOTE(lucasagomes): For future reference. If we happen
# to need to add another sub-controller in this class let's
# try to make it a parameter instead of an endpoint due
# https://bugs.launchpad.net/ironic/+bug/1572651, e.g, instead of
# v1/nodes/(ident)/detail we could have v1/nodes/(ident)?detail=True
states = NodeStatesController()
"""Expose the state controller action as a sub-element of nodes"""
@ -1033,8 +1049,7 @@ class NodesController(rest.RestController):
if not api_utils.allow_node_logical_names():
raise exception.NotAcceptable()
reserved_names = api_utils.get_controller_reserved_names(
NodesController)
reserved_names = get_nodes_controller_reserved_names()
for name in names:
if not api_utils.is_valid_node_name(name):
raise wsme.exc.ClientSideError(
@ -1043,7 +1058,7 @@ class NodesController(rest.RestController):
if name in reserved_names:
raise wsme.exc.ClientSideError(
'The word "%(name)s" is reserved and can not be used as a '
'node name. Other reserved words are: %(reserved)s' %
'node name. Reserved words are: %(reserved)s.' %
{'name': name,
'reserved': ', '.join(reserved_names)},
status_code=http_client.BAD_REQUEST)

View File

@ -2,4 +2,5 @@
fixes:
- Fixes a problem which allowed nodes to be named with some reserved
words that are implicitly not allowed due the way the Ironic API
works.
works. The reserved words are "maintenance", "management", "ports",
"states", "vendor_passthru", "validate" and "detail".