From e0c4cb3463886b952b3cfe8216b20b713704f239 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 | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tdp/core/models/deployment_model.py b/tdp/core/models/deployment_model.py index 07f9f897..3df00a9d 100644 --- a/tdp/core/models/deployment_model.py +++ b/tdp/core/models/deployment_model.py @@ -360,17 +360,14 @@ 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( + # Sort operations using DAG topological sort + operation_hosts_sorted = Dag(collections).topological_sort_key( operation_hosts_sorted, key=lambda x: x.operation.name ) - # Generate deployment deployment = DeploymentModel( deployment_type=DeploymentTypeEnum.RECONFIGURE, @@ -384,7 +381,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.name, @@ -406,7 +403,6 @@ def from_stale_hosted_entities( state=OperationStateEnum.PLANNED, ) ) - operation_order += 1 return deployment