Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if missing hosts during the deployment #618

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tdp/core/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -48,6 +49,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.
Expand Down Expand Up @@ -231,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
12 changes: 12 additions & 0 deletions tdp/core/deployment/deployment_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading