Skip to content

Commit

Permalink
More changes. ci_complete
Browse files Browse the repository at this point in the history
  • Loading branch information
sivel committed Mar 3, 2021
1 parent b25f51d commit c79e69a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
6 changes: 6 additions & 0 deletions lib/ansible/executor/task_queue_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import threading
import time
import multiprocessing.queues
import warnings

from ansible import constants as C
from ansible import context
Expand Down Expand Up @@ -75,6 +76,11 @@ def send_task_result(self, *args, **kwargs):
tr = args[0]
else:
tr = TaskResult(*args, **kwargs)
if tr._task._parent:
warnings.warn(
'TaskResult objects should not include full Task objects, ensure to exclude the parent and tasks',
category=RuntimeWarning
)
self.put(
tr,
block=False
Expand Down
10 changes: 10 additions & 0 deletions lib/ansible/playbook/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,16 @@ def deserialize(self, data):
self._finalized = data.get('finalized', False)
self._squashed = data.get('squashed', False)

def __getstate__(self):
data = self.__dict__.copy()
# The loader and variable_manager are problems for performance in pickling
# objects, and aren't needed on the otherside of a queue
# Ultimately if they become necessary, call `set_loader`, etc on
# the object on the other side of the queue
data.pop('_loader', None)
data.pop('_variable_manager', None)
return data


class Base(FieldAttributeBase):

Expand Down
10 changes: 0 additions & 10 deletions lib/ansible/playbook/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,16 +416,6 @@ def copy(self, exclude_parent=False, exclude_tasks=False):

return new_me

def __getstate__(self):
data = self.__dict__.copy()
# The loader and variable_manager are problems for performance in pickling
# the task object, and aren't needed on the otherside of a queue
# Ultimately if the become necessary, call `task.set_loader`, etc on
# the object on the other side of the queue
data.pop('_loader', None)
data.pop('_variable_manager', None)
return data

def serialize(self):
data = super(Task, self).serialize()

Expand Down
14 changes: 7 additions & 7 deletions test/units/plugins/strategy/test_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def _has_dead_workers():
results = strategy_base._wait_on_pending_results(iterator=mock_iterator)
self.assertEqual(len(results), 0)

task_result = TaskResult(host=mock_host.name, task=mock_task._uuid, return_data=dict(changed=True))
task_result = TaskResult(host=mock_host.name, task=mock_task, return_data=dict(changed=True))
queue_items.append(task_result)
strategy_base._blocked_hosts['test01'] = True
strategy_base._pending_results = 1
Expand All @@ -335,7 +335,7 @@ def _has_dead_workers():
self.assertEqual(strategy_base._pending_results, 0)
self.assertNotIn('test01', strategy_base._blocked_hosts)

task_result = TaskResult(host=mock_host.name, task=mock_task._uuid, return_data='{"failed":true}')
task_result = TaskResult(host=mock_host.name, task=mock_task, return_data='{"failed":true}')
queue_items.append(task_result)
strategy_base._blocked_hosts['test01'] = True
strategy_base._pending_results = 1
Expand All @@ -350,7 +350,7 @@ def _has_dead_workers():
# del mock_tqm._failed_hosts['test01']
mock_iterator.is_failed.return_value = False

task_result = TaskResult(host=mock_host.name, task=mock_task._uuid, return_data='{"unreachable": true}')
task_result = TaskResult(host=mock_host.name, task=mock_task, return_data='{"unreachable": true}')
queue_items.append(task_result)
strategy_base._blocked_hosts['test01'] = True
strategy_base._pending_results = 1
Expand All @@ -363,7 +363,7 @@ def _has_dead_workers():
self.assertIn('test01', mock_tqm._unreachable_hosts)
del mock_tqm._unreachable_hosts['test01']

task_result = TaskResult(host=mock_host.name, task=mock_task._uuid, return_data='{"skipped": true}')
task_result = TaskResult(host=mock_host.name, task=mock_task, return_data='{"skipped": true}')
queue_items.append(task_result)
strategy_base._blocked_hosts['test01'] = True
strategy_base._pending_results = 1
Expand All @@ -374,7 +374,7 @@ def _has_dead_workers():
self.assertEqual(strategy_base._pending_results, 0)
self.assertNotIn('test01', strategy_base._blocked_hosts)

queue_items.append(TaskResult(host=mock_host.name, task=mock_task._uuid, return_data=dict(add_host=dict(host_name='newhost01', new_groups=['foo']))))
queue_items.append(TaskResult(host=mock_host.name, task=mock_task, return_data=dict(add_host=dict(host_name='newhost01', new_groups=['foo']))))
strategy_base._blocked_hosts['test01'] = True
strategy_base._pending_results = 1
strategy_base._queued_task_cache = deepcopy(mock_queued_task_cache)
Expand All @@ -383,7 +383,7 @@ def _has_dead_workers():
self.assertEqual(strategy_base._pending_results, 0)
self.assertNotIn('test01', strategy_base._blocked_hosts)

queue_items.append(TaskResult(host=mock_host.name, task=mock_task._uuid, return_data=dict(add_group=dict(group_name='foo'))))
queue_items.append(TaskResult(host=mock_host.name, task=mock_task, return_data=dict(add_group=dict(group_name='foo'))))
strategy_base._blocked_hosts['test01'] = True
strategy_base._pending_results = 1
strategy_base._queued_task_cache = deepcopy(mock_queued_task_cache)
Expand All @@ -392,7 +392,7 @@ def _has_dead_workers():
self.assertEqual(strategy_base._pending_results, 0)
self.assertNotIn('test01', strategy_base._blocked_hosts)

queue_items.append(TaskResult(host=mock_host.name, task=mock_task._uuid, return_data=dict(changed=True, _ansible_notify=['test handler'])))
queue_items.append(TaskResult(host=mock_host.name, task=mock_task, return_data=dict(changed=True, _ansible_notify=['test handler'])))
strategy_base._blocked_hosts['test01'] = True
strategy_base._pending_results = 1
strategy_base._queued_task_cache = deepcopy(mock_queued_task_cache)
Expand Down

0 comments on commit c79e69a

Please sign in to comment.