From 7046ec810cd88b3c466e0b36a19ea32d8f82f0d9 Mon Sep 17 00:00:00 2001 From: Paul Farault Date: Wed, 20 Nov 2024 11:38:27 +0100 Subject: [PATCH] style: improve from_stale_hosted_entities --- tdp/core/models/deployment_model.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tdp/core/models/deployment_model.py b/tdp/core/models/deployment_model.py index 707d9526..325f1879 100644 --- a/tdp/core/models/deployment_model.py +++ b/tdp/core/models/deployment_model.py @@ -360,18 +360,15 @@ def from_stale_hosted_entities( ) if len(operation_hosts) == 0: raise NothingToReconfigureError("No component needs to be reconfigured.") - # Sort by hosts to improve readability operation_hosts_sorted = sorted( operation_hosts, key=lambda x: f"{x.operation_name}_{x.host_name}" ) - # Sort operations using DAG topological sort. - reconfigure_operations_sorted = Dag(collections).topological_sort_key( + operation_hosts_sorted = Dag(collections).topological_sort_key( operation_hosts_sorted, key=lambda x: x.operation_name.replace("_restart", "_start"), ) - # Generate deployment deployment = DeploymentModel( deployment_type=DeploymentTypeEnum.RECONFIGURE, @@ -385,7 +382,7 @@ def from_stale_hosted_entities( state=DeploymentStateEnum.PLANNED, ) operation_order = 1 - for operation, host in reconfigure_operations_sorted: + for operation, host in operation_hosts_sorted: deployment.operations.append( OperationModel( operation=operation, @@ -410,7 +407,6 @@ def from_stale_hosted_entities( state=OperationStateEnum.PLANNED, ) ) - operation_order += 1 return deployment