Dynamically set the number of Ansible forks.
Because our usage of Ansible is CPU-bound, the recommended
value is 10 x CPU_CORES.
Change-Id: If6d2b22e20c66e5ebdef952746c8aba7c2d54537
Signed-off-by: Luke Short <ekultails@gmail.com>
(cherry picked from commit 87d45ac42c
)
This commit is contained in:
parent
b1b4b06aad
commit
40b9c183cc
|
@ -15,6 +15,7 @@
|
|||
from datetime import datetime
|
||||
import json
|
||||
import logging
|
||||
import multiprocessing
|
||||
import os
|
||||
import shutil
|
||||
import six
|
||||
|
@ -100,7 +101,7 @@ def write_default_ansible_cfg(work_dir,
|
|||
datetime.now().strftime("%Y-%m-%dT%H:%M:%S"))
|
||||
os.rename(log_path, new_path)
|
||||
|
||||
config.set('defaults', 'forks', '50')
|
||||
config.set('defaults', 'forks', str(multiprocessing.cpu_count() * 10))
|
||||
config.set('defaults', 'timeout', '30')
|
||||
config.set('defaults', 'gather_timeout', '30')
|
||||
|
||||
|
|
|
@ -285,7 +285,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')
|
||||
|
@ -293,7 +294,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(
|
||||
|
@ -303,4 +304,4 @@ class CopyConfigFileTest(base.TestCase):
|
|||
ansible_cfg = configparser.ConfigParser()
|
||||
ansible_cfg.read(resulting_ansible_config)
|
||||
|
||||
self.assertEqual('50', ansible_cfg.get('defaults', 'forks'))
|
||||
self.assertEqual('40', ansible_cfg.get('defaults', 'forks'))
|
||||
|
|
Loading…
Reference in New Issue