From 37ec7906d778428c4df37b1fd51b047b8d52fa95 Mon Sep 17 00:00:00 2001 From: Quique Llorente Date: Thu, 8 Nov 2018 16:07:22 +0100 Subject: [PATCH] Use corrent ansible-playbook cmd for py3 Use ansible-playbook-3 for from tripleo client when we are at python3 environment. Change-Id: I572d735b00bde1a0c58f352803f870d7faa74567 --- tripleoclient/tests/test_utils.py | 12 ++++++++---- .../tests/v1/tripleo/test_tripleo_deploy.py | 6 +++++- .../tests/v1/tripleo/test_tripleo_upgrade.py | 8 ++++++-- tripleoclient/utils.py | 2 +- tripleoclient/v1/tripleo_deploy.py | 8 +++++--- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/tripleoclient/tests/test_utils.py b/tripleoclient/tests/test_utils.py index a00c70b6a..7fb488483 100644 --- a/tripleoclient/tests/test_utils.py +++ b/tripleoclient/tests/test_utils.py @@ -23,6 +23,8 @@ import os.path import subprocess import tempfile +import sys + from heatclient import exc as hc_exc from uuid import uuid4 @@ -41,6 +43,8 @@ class TestRunAnsiblePlaybook(TestCase): self.addCleanup(self.unlink_patch.stop) self.unlink_patch.start() self.mock_log = mock.Mock('logging.getLogger') + python_version = sys.version_info[0] + self.ansible_playbook_cmd = "ansible-playbook-%s" % (python_version) @mock.patch('os.path.exists', return_value=False) @mock.patch('tripleoclient.utils.run_command_and_log') @@ -74,7 +78,7 @@ class TestRunAnsiblePlaybook(TestCase): 'localhost,' ) mock_run.assert_called_once_with(self.mock_log, - ['ansible-playbook', '-i', + [self.ansible_playbook_cmd, '-i', 'localhost,', '-c', 'smart', '/tmp/existing.yaml'], env=env, retcode_only=False) @@ -110,7 +114,7 @@ class TestRunAnsiblePlaybook(TestCase): env = os.environ.copy() env['ANSIBLE_CONFIG'] = '/tmp/fooBar.cfg' mock_run.assert_called_once_with(self.mock_log, - ['ansible-playbook', '-i', + [self.ansible_playbook_cmd, '-i', 'localhost,', '-c', 'smart', '/tmp/existing.yaml'], env=env, retcode_only=False) @@ -137,7 +141,7 @@ class TestRunAnsiblePlaybook(TestCase): env = os.environ.copy() env['ANSIBLE_CONFIG'] = '/tmp/foo.cfg' mock_run.assert_called_once_with(self.mock_log, - ['ansible-playbook', '-i', + [self.ansible_playbook_cmd, '-i', 'localhost,', '-c', 'smart', '/tmp/existing.yaml'], env=env, retcode_only=False) @@ -160,7 +164,7 @@ class TestRunAnsiblePlaybook(TestCase): env = os.environ.copy() env['ANSIBLE_CONFIG'] = '/tmp/fooBar.cfg' mock_run.assert_called_once_with(self.mock_log, - ['ansible-playbook', '-i', + [self.ansible_playbook_cmd, '-i', 'localhost,', '-c', 'local', '/tmp/existing.yaml'], env=env, retcode_only=False) diff --git a/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py b/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py index a7c42ee6e..fbf9b44b3 100644 --- a/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py +++ b/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py @@ -16,6 +16,7 @@ import fixtures import mock import os +import sys import tempfile import yaml @@ -58,6 +59,9 @@ class TestDeployUndercloud(TestPluginV1): self.orc.stacks.create = mock.MagicMock( return_value={'stack': {'id': 'foo'}}) + python_version = sys.version_info[0] + self.ansible_playbook_cmd = "ansible-playbook-%s" % (python_version) + def test_get_roles_file_path(self): parsed_args = self.check_parser(self.cmd, ['--local-ip', '127.0.0.1/8'], []) @@ -685,7 +689,7 @@ class TestDeployUndercloud(TestPluginV1): self.cmd._launch_ansible_deploy('/tmp') mock_chdir.assert_called_once() mock_run.assert_called_once_with(self.cmd.log, [ - 'ansible-playbook', '-i', '/tmp/inventory.yaml', + self.ansible_playbook_cmd, '-i', '/tmp/inventory.yaml', 'deploy_steps_playbook.yaml']) @mock.patch('tripleoclient.utils.fetch_roles_file') diff --git a/tripleoclient/tests/v1/tripleo/test_tripleo_upgrade.py b/tripleoclient/tests/v1/tripleo/test_tripleo_upgrade.py index 7f344ebd3..ddf9d41ef 100644 --- a/tripleoclient/tests/v1/tripleo/test_tripleo_upgrade.py +++ b/tripleoclient/tests/v1/tripleo/test_tripleo_upgrade.py @@ -14,6 +14,7 @@ # import mock +import sys from osc_lib.tests import utils import six @@ -31,6 +32,9 @@ class TestUpgrade(utils.TestCommand): # Get the command object to test self.cmd = tripleo_upgrade.Upgrade(self.app, None) + python_version = sys.version_info[0] + self.ansible_playbook_cmd = "ansible-playbook-%s" % (python_version) + @mock.patch('tripleoclient.utils.' 'run_command_and_log', autospec=True) @mock.patch('os.chdir') @@ -40,7 +44,7 @@ class TestUpgrade(utils.TestCommand): self.cmd._launch_ansible_upgrade('/tmp') mock_chdir.assert_called_once() mock_run.assert_called_once_with(self.cmd.log, [ - 'ansible-playbook', '-i', '/tmp/inventory.yaml', + self.ansible_playbook_cmd, '-i', '/tmp/inventory.yaml', 'upgrade_steps_playbook.yaml', '--skip-tags', 'validation']) @@ -54,7 +58,7 @@ class TestUpgrade(utils.TestCommand): self.cmd._launch_ansible_post_upgrade('/tmp') mock_chdir.assert_called_once() mock_run.assert_called_once_with(self.cmd.log, [ - 'ansible-playbook', '-i', '/tmp/inventory.yaml', + self.ansible_playbook_cmd, '-i', '/tmp/inventory.yaml', 'post_upgrade_steps_playbook.yaml', '--skip-tags', 'validation']) diff --git a/tripleoclient/utils.py b/tripleoclient/utils.py index 204d430a5..383726790 100644 --- a/tripleoclient/utils.py +++ b/tripleoclient/utils.py @@ -108,7 +108,7 @@ def run_ansible_playbook(logger, play = os.path.join(workdir, playbook) if os.path.exists(play): - cmd = ['ansible-playbook', + cmd = ["ansible-playbook-{}".format(sys.version_info[0]), '-i', inventory, '-c', connection, play ] diff --git a/tripleoclient/v1/tripleo_deploy.py b/tripleoclient/v1/tripleo_deploy.py index 4a163ed8d..79919e646 100644 --- a/tripleoclient/v1/tripleo_deploy.py +++ b/tripleoclient/v1/tripleo_deploy.py @@ -102,6 +102,8 @@ class Deploy(command.Command): stack_action = 'CREATE' deployment_user = None ansible_dir = None + python_version = sys.version_info[0] + ansible_playbook_cmd = "ansible-playbook-{}".format(python_version) def _is_undercloud_deploy(self, parsed_args): return parsed_args.standalone_role == 'Undercloud' and \ @@ -789,7 +791,7 @@ class Deploy(command.Command): self.log.warning(_('** Running ansible deploy tasks **')) os.chdir(ansible_dir) playbook_inventory = os.path.join(ansible_dir, 'inventory.yaml') - cmd = ['ansible-playbook', '-i', playbook_inventory, + cmd = [self.ansible_playbook_cmd, '-i', playbook_inventory, 'deploy_steps_playbook.yaml'] self.log.debug('Running Ansible Deploy tasks: %s' % (' '.join(cmd))) return utils.run_command_and_log(self.log, cmd) @@ -798,7 +800,7 @@ class Deploy(command.Command): self.log.warning('** Running ansible upgrade tasks **') os.chdir(ansible_dir) playbook_inventory = os.path.join(ansible_dir, 'inventory.yaml') - cmd = ['ansible-playbook', '-i', playbook_inventory, + cmd = [self.ansible_playbook_cmd, '-i', playbook_inventory, 'upgrade_steps_playbook.yaml', '--skip-tags', 'validation'] self.log.debug('Running Ansible Upgrade tasks: %s' % (' '.join(cmd))) return utils.run_command_and_log(self.log, cmd) @@ -807,7 +809,7 @@ class Deploy(command.Command): self.log.warning('** Running ansible post-upgrade tasks **') os.chdir(ansible_dir) playbook_inventory = os.path.join(ansible_dir, 'inventory.yaml') - cmd = ['ansible-playbook', '-i', playbook_inventory, + cmd = [self.ansible_playbook_cmd, '-i', playbook_inventory, 'post_upgrade_steps_playbook.yaml', '--skip-tags', 'validation'] self.log.debug('Running Ansible Post Upgrade ' 'tasks: %s' % (' '.join(cmd)))