From 1e5daa018a3efc1c8068dca7e7b8bbb308c66757 Mon Sep 17 00:00:00 2001 From: SteBaum Date: Wed, 31 Jul 2024 14:26:43 +0200 Subject: [PATCH 1/3] feat: added a get_hosts function for Collections --- tdp/core/collections.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tdp/core/collections.py b/tdp/core/collections.py index cde442d9..0d88b484 100644 --- a/tdp/core/collections.py +++ b/tdp/core/collections.py @@ -48,6 +48,17 @@ def __iter__(self): def __len__(self): return self._collections.__len__() + def get_collections_hosts(self): + host_operation_list = [ + self.operations.__getitem__(operation).host_names + for operation in self.operations + ] + hosts_set = set() + for operation_hosts in host_operation_list: + hosts_set.update(operation_hosts) + + return {host for host in hosts_set if host != "localhost"} + @staticmethod def from_collection_list(collections: Sequence[Collection]) -> Collections: """Factory method to build Collections from a sequence of Collection. From 321f838097fc9baa4056c9c86f04598b6da41ad3 Mon Sep 17 00:00:00 2001 From: SteBaum Date: Wed, 31 Jul 2024 14:29:22 +0200 Subject: [PATCH 2/3] feat: added function check_collections_hosts for Collections --- tdp/core/collections.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tdp/core/collections.py b/tdp/core/collections.py index 0d88b484..3f1370c4 100644 --- a/tdp/core/collections.py +++ b/tdp/core/collections.py @@ -19,6 +19,7 @@ from tdp.core.collection import Collection from tdp.core.entities.hostable_entity_name import ServiceComponentName from tdp.core.entities.operation import Operations +from tdp.core.inventory_reader import InventoryReader from tdp.core.operation import Operation from tdp.core.variables.schema.service_schema import ServiceSchema @@ -242,3 +243,13 @@ def get_components_from_service( if operation.service_name == service_name and not operation.is_service_operation() } + + def check_collections_hosts(self): + """Checks if hosts has not been removed from the inventory.ini file""" + inventory = InventoryReader().inventory + inventory.refresh_inventory() + + inventory_list = [str(name) for name in inventory.get_hosts()] + for host in self.get_collections_hosts(): + if host not in inventory_list: + return host From 4083892490b37c7c1403cefefe12480d5fda627e Mon Sep 17 00:00:00 2001 From: SteBaum Date: Thu, 1 Aug 2024 13:55:18 +0200 Subject: [PATCH 3/3] feat: check the hosts in the collections during deployment iteration --- tdp/core/deployment/deployment_iterator.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tdp/core/deployment/deployment_iterator.py b/tdp/core/deployment/deployment_iterator.py index 241bd018..bf2ad852 100644 --- a/tdp/core/deployment/deployment_iterator.py +++ b/tdp/core/deployment/deployment_iterator.py @@ -125,6 +125,18 @@ def __next__( operation_rec.state = OperationStateEnum.RUNNING + if host := self._collections.check_collections_hosts(): + message = f"{host} has been removed from the inventory file." + logger.error(message) + operation_rec.logs = message.encode("utf-8") + operation_rec.start_time = operation_rec.end_time = ( + datetime.utcnow() + ) + operation_rec.state = OperationStateEnum.FAILURE + self.deployment.end_time = datetime.utcnow() + self.deployment.state = DeploymentStateEnum.FAILURE + return operation_rec, None + return operation_rec, partial(self._process_operation_fn, operation_rec) # StopIteration is a "normal" exception raised when the iteration has stopped except StopIteration as e: