Skip to content

Commit c1f50b2

Browse files
author
Jeny Sadadia
committed
api.main: translate node version fields
API expects `int` values for Node version information. Translate version fields received in the `POST` and `PUT` node handlers until we can use it in the pipeline service directly. Due to python version conflicts between core tools and pipeline, we are not able to use the helper function in the pipeline atm. Signed-off-by: Jeny Sadadia <[email protected]>
1 parent eb358a4 commit c1f50b2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

api/main.py

+19
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
Hierarchy,
3333
PublishEvent,
3434
parse_node_obj,
35+
KernelVersion,
3536
)
3637
from .auth import Authentication
3738
from .db import Database
@@ -535,10 +536,24 @@ async def _verify_user_group_existence(user_groups: List[str]):
535536
detail=f"User group does not exist with name: {group_name}")
536537

537538

539+
def _translate_version_fields(node: Node):
540+
"""Translate Node version fields"""
541+
data = node.data
542+
if data:
543+
version = data.get('kernel_revision', {}).get('version')
544+
if version:
545+
version = KernelVersion.translate_version_fields(version)
546+
node.data['kernel_revision']['version'] = version
547+
return node
548+
549+
538550
@app.post('/node', response_model=Node, response_model_by_alias=False)
539551
async def post_node(node: Node,
540552
current_user: User = Depends(get_current_user)):
541553
"""Create a new node"""
554+
# [TODO] Remove translation below once we can use it in the pipeline
555+
node = _translate_version_fields(node)
556+
542557
# Explicit pydantic model validation
543558
parse_node_obj(node)
544559

@@ -576,6 +591,10 @@ async def put_node(node_id: str, node: Node,
576591
status_code=status.HTTP_404_NOT_FOUND,
577592
detail=f"Node not found with id: {node.id}"
578593
)
594+
595+
# [TODO] Remove translation below once we can use it in the pipeline
596+
node = _translate_version_fields(node)
597+
579598
# Sanity checks
580599
# Note: do not update node ownership fields, don't update 'state'
581600
# until we've checked the state transition is valid.

0 commit comments

Comments
 (0)