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 operation availability on host before execution #491

Merged
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
15 changes: 15 additions & 0 deletions tdp/core/deployment/deployment_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ def _run_operation(self, operation_log: OperationLog) -> None:
operation_log.start_time = datetime.utcnow()

operation = self._collections.get_operation(operation_log.operation)

# Check if the operation is available for the given host
if operation_log.host and operation_log.host not in operation.host_names:
logs = (
f"Operation '{operation_log.operation}' not available for host "
+ f"'{operation_log.host}'"
)
logger.error(logs)
operation_log.state = OperationStateEnum.FAILURE
operation_log.logs = logs.encode("utf-8")
operation_log.end_time = datetime.utcnow()
return

# Execute the operation
playbook_file = self._collections[operation.collection_name].playbooks[
operation.name
]
Expand All @@ -62,6 +76,7 @@ def _run_operation(self, operation_log: OperationLog) -> None:
)
operation_log.end_time = datetime.utcnow()

# ? This case shouldn't happen as the executor should return a valid state
if state not in OperationStateEnum:
logger.error(
f"Invalid state ({state}) returned by {self._executor.__class__.__name__}.run('{playbook_file}'))"
Expand Down