Browse Source

Dynamically set the number of Ansible forks.

Because our usage of Ansible is CPU-bound, the recommended
value is 10 x CPU_CORES.

Conflicts:
   tripleo_common/actions/ansible.py

Change-Id: If6d2b22e20c66e5ebdef952746c8aba7c2d54537
Signed-off-by: Luke Short <ekultails@gmail.com>
(cherry picked from commit 87d45ac42c)
(cherry picked from commit 40b9c183cc)
(cherry picked from commit ca863c590d)
changes/45/706145/1
Luke Short 1 month ago
parent
commit
16d0418333
2 changed files with 6 additions and 4 deletions
  1. +2
    -1
      tripleo_common/actions/ansible.py
  2. +4
    -3
      tripleo_common/tests/actions/test_ansible.py

+ 2
- 1
tripleo_common/actions/ansible.py View File

@@ -14,6 +14,7 @@
# under the License.
import json
import logging
import multiprocessing
import os
import shutil
import six
@@ -52,7 +53,7 @@ def write_default_ansible_cfg(work_dir,
# suppress tasks if all hosts skip, was previously full_skip callback
config.set('defaults', 'display_skipped_hosts', 'no')
config.set('defaults', 'callback_whitelist', callbacks_whitelist)
config.set('defaults', 'forks', '25')
config.set('defaults', 'forks', str(multiprocessing.cpu_count() * 10))
config.set('defaults', 'timeout', '30')
config.set('defaults', 'gather_timeout', '30')


+ 4
- 3
tripleo_common/tests/actions/test_ansible.py View File

@@ -237,7 +237,8 @@ class CopyConfigFileTest(base.TestCase):
ansible_cfg.get('ssh_connection',
'custom_option'))

def test_override_ansible_cfg_empty(self):
@mock.patch("multiprocessing.cpu_count")
def test_override_ansible_cfg_empty(self, cpu_count):
with tempfile.NamedTemporaryFile() as ansible_cfg_file:
ansible_cfg_path = ansible_cfg_file.name
work_dir = tempfile.mkdtemp(prefix='ansible-mistral-action-test')
@@ -245,7 +246,7 @@ class CopyConfigFileTest(base.TestCase):
ansible_cfg_file.write(b'[defaults]\n')
ansible_cfg_file.write(b'[ssh_connection]\n')
ansible_cfg_file.flush()
cpu_count.return_value = 4
override_ansible_cfg = ""

resulting_ansible_config = ansible.write_default_ansible_cfg(
@@ -255,4 +256,4 @@ class CopyConfigFileTest(base.TestCase):
ansible_cfg = configparser.ConfigParser()
ansible_cfg.read(resulting_ansible_config)

self.assertEqual('25', ansible_cfg.get('defaults', 'forks'))
self.assertEqual('40', ansible_cfg.get('defaults', 'forks'))

Loading…
Cancel
Save