summaryrefslogtreecommitdiff
path: root/ironic/api/controllers/v1/utils.py
diff options
context:
space:
mode:
authorSteve Baker <sbaker@redhat.com>2020-11-18 21:18:48 +1300
committerSteve Baker <sbaker@redhat.com>2020-11-26 11:05:48 +1300
commite41893c9d085b4883366db65b9a74104f1949e1d (patch)
tree3a2b9362a8772e65ac40451cf8703dba62a56aa9 /ironic/api/controllers/v1/utils.py
parenta08da8551a66815bedef7c6444fde5f9082a6aea (diff)
downloadironic-e41893c9d085b4883366db65b9a74104f1949e1d.tar.gz
JSON conversion followup change
This change addresses nit-level review comments from this task. Story: 1651346 Task: 10551 Change-Id: I01608004ce90facadb73e252203900a1e62cbea1
Diffstat (limited to 'ironic/api/controllers/v1/utils.py')
-rw-r--r--ironic/api/controllers/v1/utils.py22
1 files changed, 7 insertions, 15 deletions
diff --git a/ironic/api/controllers/v1/utils.py b/ironic/api/controllers/v1/utils.py
index 2ad7cd7b4..474987f9a 100644
--- a/ironic/api/controllers/v1/utils.py
+++ b/ironic/api/controllers/v1/utils.py
@@ -226,7 +226,7 @@ def object_to_dict(obj, created_at=True, updated_at=True, uuid=True,
return to_dict
-def populate_node_uuid(obj, to_dict, raise_notfound=True):
+def populate_node_uuid(obj, to_dict):
"""Look up the node referenced in the object and populate a dict.
The node is fetched with the object ``node_id`` attribute and the
@@ -236,23 +236,15 @@ def populate_node_uuid(obj, to_dict, raise_notfound=True):
object to get the node_id attribute
:param to_dict:
dict to populate with a ``node_uuid`` value
- :param raise_notfound:
- If ``True`` raise a NodeNotFound exception if the node doesn't exist
- otherwise set the dict ``node_uuid`` value to None.
:raises:
- exception.NodeNotFound if raise_notfound and the node is not found
+ exception.NodeNotFound if the node is not found
"""
if not obj.node_id:
to_dict['node_uuid'] = None
return
- try:
- to_dict['node_uuid'] = objects.Node.get_by_id(
- api.request.context,
- obj.node_id).uuid
- except exception.NodeNotFound:
- if raise_notfound:
- raise
- to_dict['node_uuid'] = None
+ to_dict['node_uuid'] = objects.Node.get_by_id(
+ api.request.context,
+ obj.node_id).uuid
def replace_node_uuid_with_id(to_dict):
@@ -343,7 +335,7 @@ def patched_validate_with_schema(patched_dict, schema, validator=None):
:raises: exception.Invalid if validation fails
"""
schema_fields = schema['properties']
- for field in set(patched_dict.keys()):
+ for field in set(patched_dict):
if field not in schema_fields:
patched_dict.pop(field, None)
if not validator:
@@ -385,7 +377,7 @@ def sanitize_dict(to_sanitize, fields):
if fields is None:
return
- for key in set(to_sanitize.keys()):
+ for key in set(to_sanitize):
if key not in fields and key != 'links':
to_sanitize.pop(key, None)