diff --git a/tripleoclient/tests/test_utils.py b/tripleoclient/tests/test_utils.py index 834646189..903fa13ca 100644 --- a/tripleoclient/tests/test_utils.py +++ b/tripleoclient/tests/test_utils.py @@ -269,6 +269,55 @@ class TestRunAnsiblePlaybook(TestCase): '/tmp/existing.yaml'], env=env, retcode_only=False) + @mock.patch('tempfile.mkstemp', return_value=('foo', '/tmp/fooBar.cfg')) + @mock.patch('os.path.exists', return_value=True) + @mock.patch('tripleoclient.utils.run_command_and_log') + def test_run_success_gathering_policy(self, mock_run, mock_exists, + mok_mkstemp): + mock_process = mock.Mock() + mock_process.returncode = 0 + mock_run.return_value = mock_process + + retcode, output = utils.run_ansible_playbook( + self.mock_log, + '/tmp', + 'existing.yaml', + 'localhost,', + gathering_policy='explicit') + self.assertEqual(retcode, 0) + mock_exists.assert_called_once_with('/tmp/existing.yaml') + env = os.environ.copy() + env['ANSIBLE_LIBRARY'] = \ + ('/root/.ansible/plugins/modules:' + '/usr/share/ansible/plugins/modules:' + '/usr/share/openstack-tripleo-validations/library') + env['ANSIBLE_LOOKUP_PLUGINS'] = \ + ('root/.ansible/plugins/lookup:' + '/usr/share/ansible/plugins/lookup:' + '/usr/share/openstack-tripleo-validations/lookup_plugins') + env['ANSIBLE_CALLBACK_PLUGINS'] = \ + ('~/.ansible/plugins/callback:' + '/usr/share/ansible/plugins/callback:' + '/usr/share/openstack-tripleo-validations/callback_plugins') + env['ANSIBLE_ROLES_PATH'] = \ + ('/root/.ansible/roles:' + '/usr/share/ansible/roles:' + '/etc/ansible/roles:' + '/usr/share/openstack-tripleo-validations/roles') + env['ANSIBLE_CONFIG'] = '/tmp/fooBar.cfg' + env['ANSIBLE_HOST_KEY_CHECKING'] = 'False' + env['ANSIBLE_LOG_PATH'] = '/tmp/ansible.log' + env['TRIPLEO_PLAN_NAME'] = 'overcloud' + env['ANSIBLE_GATHERING'] = 'explicit' + + mock_run.assert_called_once_with(self.mock_log, + [self.ansible_playbook_cmd, + '-u', 'root', + '-i', 'localhost,', '-v', + '-c', 'smart', + '/tmp/existing.yaml'], + env=env, retcode_only=False) + @mock.patch('tempfile.mkstemp', return_value=('foo', '/tmp/fooBar.cfg')) @mock.patch('os.path.exists', return_value=True) @mock.patch('tripleoclient.utils.run_command_and_log') diff --git a/tripleoclient/tests/v1/tripleo/test_tripleo_validator.py b/tripleoclient/tests/v1/tripleo/test_tripleo_validator.py index 3f58ffc2c..33a3a7b17 100644 --- a/tripleoclient/tests/v1/tripleo/test_tripleo_validator.py +++ b/tripleoclient/tests/v1/tripleo/test_tripleo_validator.py @@ -111,7 +111,8 @@ class TestValidatorRun(utils.TestCommand): retries=False, output_callback='validation_output', extra_vars={}, - python_interpreter='/usr/bin/python{}'.format(sys.version_info[0]) + python_interpreter='/usr/bin/python{}'.format(sys.version_info[0]), + gathering_policy='explicit' ) assert mock_sysexit.called diff --git a/tripleoclient/utils.py b/tripleoclient/utils.py index d9007f9f2..6a7952171 100644 --- a/tripleoclient/utils.py +++ b/tripleoclient/utils.py @@ -84,7 +84,8 @@ def run_ansible_playbook(logger, skip_tags=None, verbosity=1, extra_vars=None, - plan='overcloud'): + plan='overcloud', + gathering_policy=None): """Simple wrapper for ansible-playbook :param logger: logger instance @@ -147,6 +148,12 @@ def run_ansible_playbook(logger, :param extra_vars: set additional variables as a Dict or the absolute path of a JSON or YAML file type :type extra_vars: Either a Dict or the absolute path of JSON or YAML + + :param gathering_policy: This setting controls the default policy of + fact gathering ('smart', 'implicit', 'explicit'). Defaults to None. + When not specified, the policy will be the default Ansible one, ie. + 'implicit'. + :type gathering_facts: String """ env = os.environ.copy() @@ -177,6 +184,9 @@ def run_ansible_playbook(logger, env['ANSIBLE_HOST_KEY_CHECKING'] = 'False' + if gathering_policy in ['smart', 'explicit', 'implicit']: + env['ANSIBLE_GATHERING'] = gathering_policy + if extra_vars is None: extra_vars = {} diff --git a/tripleoclient/v1/tripleo_validator.py b/tripleoclient/v1/tripleo_validator.py index 073128083..763274fe7 100644 --- a/tripleoclient/v1/tripleo_validator.py +++ b/tripleoclient/v1/tripleo_validator.py @@ -356,7 +356,8 @@ class TripleOValidatorRun(command.Command): retries=False, output_callback='validation_output', extra_vars=extra_vars_input, - python_interpreter=python_interpreter) + python_interpreter=python_interpreter, + gathering_policy='explicit') print('[SUCCESS] - {}\n{}'.format(playbook, oooutils.indent(output))) except Exception as e: