Merge "Expose --ansible-forks"

This commit is contained in:
Zuul 2020-10-02 09:06:40 +00:00 committed by Gerrit Code Review
commit 0aded9ecb1
11 changed files with 77 additions and 11 deletions

View File

@ -0,0 +1,6 @@
---
features:
- |
A new `--ansible-forks` argument has been added to the TripleO and Overcloud
commands. The default value for forks has also been adjusted to no longer
exceed 100 forks.

View File

@ -1540,7 +1540,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
deployment_options={}, deployment_options={},
deployment_timeout=448, # 451 - 3, total time left deployment_timeout=448, # 451 - 3, total time left
in_flight_validations=False, limit_hosts=None, in_flight_validations=False, limit_hosts=None,
skip_tags=None, tags=None, timeout=42, verbosity=3)], skip_tags=None, tags=None, timeout=42, verbosity=3,
forks=None)],
fixture.mock_config_download.mock_calls) fixture.mock_config_download.mock_calls)
fixture.mock_config_download.assert_called() fixture.mock_config_download.assert_called()
mock_copy.assert_called_once() mock_copy.assert_called_once()
@ -1593,7 +1594,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
reproduce_command=True, skip_tags='opendev-validation', reproduce_command=True, skip_tags='opendev-validation',
ssh_user='tripleo-admin', tags=None, ssh_user='tripleo-admin', tags=None,
timeout=240, timeout=240,
verbosity=3, workdir=mock.ANY)], verbosity=3, workdir=mock.ANY, forks=None)],
utils_fixture2.mock_run_ansible_playbook.mock_calls) utils_fixture2.mock_run_ansible_playbook.mock_calls)
def test_download_missing_files_from_plan(self): def test_download_missing_files_from_plan(self):

View File

@ -261,7 +261,8 @@ class TestDeleteNode(fakes.TestDeleteNode):
extra_env_variables={'ANSIBLE_BECOME': True}, extra_env_variables={'ANSIBLE_BECOME': True},
extra_vars=None, extra_vars=None,
tags=None, tags=None,
timeout=90 timeout=90,
forks=None
), ),
mock.call( mock.call(
inventory='localhost,', inventory='localhost,',

View File

@ -247,7 +247,7 @@ def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None,
callback_whitelist=constants.ANSIBLE_CWL, callback_whitelist=constants.ANSIBLE_CWL,
ansible_cfg=None, ansible_timeout=30, ansible_cfg=None, ansible_timeout=30,
reproduce_command=False, reproduce_command=False,
timeout=None): timeout=None, forks=None):
"""Simple wrapper for ansible-playbook. """Simple wrapper for ansible-playbook.
:param playbook: Playbook filename. :param playbook: Playbook filename.
@ -450,6 +450,9 @@ def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None,
if output_callback not in callback_whitelist.split(','): if output_callback not in callback_whitelist.split(','):
callback_whitelist = ','.join([callback_whitelist, output_callback]) callback_whitelist = ','.join([callback_whitelist, output_callback])
if not forks:
forks = min(multiprocessing.cpu_count() * 4, 100)
env = dict() env = dict()
env['ANSIBLE_SSH_ARGS'] = ( env['ANSIBLE_SSH_ARGS'] = (
'-o UserKnownHostsFile={} ' '-o UserKnownHostsFile={} '
@ -467,7 +470,7 @@ def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None,
'-T' '-T'
).format(os.devnull) ).format(os.devnull)
env['ANSIBLE_DISPLAY_FAILED_STDERR'] = True env['ANSIBLE_DISPLAY_FAILED_STDERR'] = True
env['ANSIBLE_FORKS'] = multiprocessing.cpu_count() * 4 env['ANSIBLE_FORKS'] = forks
env['ANSIBLE_TIMEOUT'] = ansible_timeout env['ANSIBLE_TIMEOUT'] = ansible_timeout
env['ANSIBLE_GATHER_TIMEOUT'] = 45 env['ANSIBLE_GATHER_TIMEOUT'] = 45
env['ANSIBLE_SSH_RETRIES'] = 3 env['ANSIBLE_SSH_RETRIES'] = 3

View File

@ -1023,6 +1023,14 @@ class DeployOvercloud(command.Command):
help=_('A list of tags to skip when running the the' help=_('A list of tags to skip when running the the'
' config-download ansible-playbook command.') ' config-download ansible-playbook command.')
) )
parser.add_argument(
'--ansible-forks',
action='store',
default=None,
type=int,
help=_('The number of Ansible forks to use for the'
' config-download ansible-playbook command.')
)
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
@ -1137,7 +1145,8 @@ class DeployOvercloud(command.Command):
skip_tags=parsed_args.skip_tags, skip_tags=parsed_args.skip_tags,
limit_hosts=utils.playbook_limit_parse( limit_hosts=utils.playbook_limit_parse(
limit_nodes=parsed_args.limit limit_nodes=parsed_args.limit
) ),
forks=parsed_args.ansible_forks
) )
deployment.set_deployment_status( deployment.set_deployment_status(
clients=self.clients, clients=self.clients,

View File

@ -106,6 +106,14 @@ class ExternalUpdateRun(command.Command):
"execution will be limited to. For example: --limit" "execution will be limited to. For example: --limit"
" \"compute-0,compute-1,compute-5\".") " \"compute-0,compute-1,compute-5\".")
) )
parser.add_argument(
'--ansible-forks',
action='store',
default=None,
type=int,
help=_('The number of Ansible forks to use for the'
' config-download ansible-playbook command.')
)
return parser return parser
@ -148,6 +156,7 @@ class ExternalUpdateRun(command.Command):
skip_tags=parsed_args.skip_tags, skip_tags=parsed_args.skip_tags,
limit_hosts=oooutils.playbook_limit_parse( limit_hosts=oooutils.playbook_limit_parse(
limit_nodes=parsed_args.limit limit_nodes=parsed_args.limit
) ),
forks=parsed_args.ansible_forks
) )
self.log.info("Completed Overcloud External Update Run.") self.log.info("Completed Overcloud External Update Run.")

View File

@ -106,6 +106,14 @@ class ExternalUpgradeRun(command.Command):
"execution will be limited to. For example: --limit" "execution will be limited to. For example: --limit"
" \"compute-0,compute-1,compute-5\".") " \"compute-0,compute-1,compute-5\".")
) )
parser.add_argument(
'--ansible-forks',
action='store',
default=None,
type=int,
help=_('The number of Ansible forks to use for the'
' config-download ansible-playbook command.')
)
return parser return parser
@ -144,6 +152,7 @@ class ExternalUpgradeRun(command.Command):
tags=parsed_args.tags, tags=parsed_args.tags,
skip_tags=parsed_args.skip_tags, skip_tags=parsed_args.skip_tags,
limit_hosts=oooutils.playbook_limit_parse( limit_hosts=oooutils.playbook_limit_parse(
limit_nodes=parsed_args.limit) limit_nodes=parsed_args.limit),
forks=parsed_args.ansible_forks
) )
self.log.info("Completed Overcloud External Upgrade Run.") self.log.info("Completed Overcloud External Upgrade Run.")

View File

@ -169,6 +169,14 @@ class UpdateRun(command.Command):
help=_("Use -y or --yes to skip the confirmation required before " help=_("Use -y or --yes to skip the confirmation required before "
"any update operation. Use this with caution! "), "any update operation. Use this with caution! "),
) )
parser.add_argument(
'--ansible-forks',
action='store',
default=None,
type=int,
help=_('The number of Ansible forks to use for the'
' config-download ansible-playbook command.')
)
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
@ -214,7 +222,8 @@ class UpdateRun(command.Command):
limit_nodes=parsed_args.limit limit_nodes=parsed_args.limit
), ),
skip_tags=parsed_args.skip_tags, skip_tags=parsed_args.skip_tags,
tags=parsed_args.tags tags=parsed_args.tags,
forks=parsed_args.ansible_forks
) )
self.log.info("Completed Overcloud Minor Update Run.") self.log.info("Completed Overcloud Minor Update Run.")

View File

@ -204,6 +204,14 @@ class UpgradeRun(command.Command):
"required before any upgrade " "required before any upgrade "
"operation. Use this with caution! ") "operation. Use this with caution! ")
) )
parser.add_argument(
'--ansible-forks',
action='store',
default=None,
type=int,
help=_('The number of Ansible forks to use for the'
' config-download ansible-playbook command.')
)
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
@ -250,7 +258,8 @@ class UpgradeRun(command.Command):
skip_tags=parsed_args.skip_tags, skip_tags=parsed_args.skip_tags,
limit_hosts=oooutils.playbook_limit_parse( limit_hosts=oooutils.playbook_limit_parse(
limit_nodes=parsed_args.limit limit_nodes=parsed_args.limit
) ),
forks=parsed_args.ansible_forks
) )
self.log.info("Completed Overcloud Major Upgrade Run.") self.log.info("Completed Overcloud Major Upgrade Run.")

View File

@ -1106,6 +1106,14 @@ class Deploy(command.Command):
'Use "local" for standalone deployments. ' 'Use "local" for standalone deployments. '
'Defaults to "local".') 'Defaults to "local".')
) )
parser.add_argument(
'--ansible-forks',
action='store',
default=None,
type=int,
help=_('The number of Ansible forks to use for the'
' config-download ansible-playbook command.')
)
stack_action_group = parser.add_mutually_exclusive_group() stack_action_group = parser.add_mutually_exclusive_group()
@ -1348,6 +1356,7 @@ class Deploy(command.Command):
workdir=self.ansible_dir, workdir=self.ansible_dir,
verbosity=utils.playbook_verbosity(self=self), verbosity=utils.playbook_verbosity(self=self),
extra_env_variables=extra_env_var, extra_env_variables=extra_env_var,
forks=parsed_args.ansible_forks,
**operation) **operation)
is_complete = True is_complete = True
finally: finally:

View File

@ -275,7 +275,7 @@ def config_download(log, clients, stack, ssh_network='ctlplane',
ansible_playbook_name='deploy_steps_playbook.yaml', ansible_playbook_name='deploy_steps_playbook.yaml',
limit_hosts=None, extra_vars=None, inventory_path=None, limit_hosts=None, extra_vars=None, inventory_path=None,
ssh_user='tripleo-admin', tags=None, skip_tags=None, ssh_user='tripleo-admin', tags=None, skip_tags=None,
deployment_timeout=None): deployment_timeout=None, forks=None):
"""Run config download. """Run config download.
:param log: Logging object :param log: Logging object
@ -460,6 +460,7 @@ def config_download(log, clients, stack, ssh_network='ctlplane',
}, },
extra_vars=extra_vars, extra_vars=extra_vars,
timeout=deployment_timeout, timeout=deployment_timeout,
forks=forks
) )
_log_and_print( _log_and_print(