Browse Source

Merge "Dynamically set the number of Ansible forks." into stable/train

changes/96/703996/1
Zuul Gerrit Code Review 1 month ago
parent
commit
a4ca9327b2
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

@@ -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')



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

@@ -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…
Cancel
Save