From a56361f5ad7257b2c154c5037c1a69cd316792f5 Mon Sep 17 00:00:00 2001 From: James Slagle Date: Wed, 6 May 2020 16:11:07 -0400 Subject: [PATCH] Add --transport argument to tripleo deploy The new --transport argument allows for specifying a transport configuration to have set in the generated ansible configuration file. The default value of "local" matches the previous hardcoded value. To deploy multiple nodes with tripleo deploy, "--transport ssh" can be used. blueprint tripleo-deploy-multinode Change-Id: I75cbde83dda1a79ad65bf522e57c8ef326bbc54d Signed-off-by: James Slagle --- ...leo-deploy-transport-ccc72043ce0eb776.yaml | 6 ++ .../tests/v1/tripleo/test_tripleo_deploy.py | 80 +++++++++++++++++++ tripleoclient/v1/tripleo_deploy.py | 13 ++- 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/tripleo-deploy-transport-ccc72043ce0eb776.yaml diff --git a/releasenotes/notes/tripleo-deploy-transport-ccc72043ce0eb776.yaml b/releasenotes/notes/tripleo-deploy-transport-ccc72043ce0eb776.yaml new file mode 100644 index 000000000..46d71e450 --- /dev/null +++ b/releasenotes/notes/tripleo-deploy-transport-ccc72043ce0eb776.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + The --transport argument has been added to openstack tripleo deploy which + allows for specifying the ansible transport to use in the ansible + configuration file. diff --git a/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py b/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py index 1c5803328..1f48845d7 100644 --- a/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py +++ b/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py @@ -1097,3 +1097,83 @@ class TestDeployUndercloud(TestPluginV1): rc = self.cmd.take_action(parsed_args) self.assertEqual(None, rc) + + @mock.patch('os.path.exists', return_value=True) + @mock.patch('os.chdir') + @mock.patch('tripleoclient.utils.reset_cmdline') + @mock.patch('tripleoclient.utils.copy_clouds_yaml') + @mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.' + '_download_stack_outputs') + @mock.patch('tripleo_common.actions.ansible.' + 'write_default_ansible_cfg') + # TODO(cjeanner) drop once we have proper oslo.privsep + @mock.patch('os.chmod') + # TODO(cjeanner) drop once we have proper oslo.privsep + @mock.patch('os.mkdir') + @mock.patch('six.moves.builtins.open') + @mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.' + '_populate_templates_dir') + @mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.' + '_create_install_artifact', return_value='/tmp/foo.tar.bzip2') + @mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.' + '_cleanup_working_dirs') + @mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.' + '_create_working_dirs') + @mock.patch('tripleoclient.utils.wait_api_port_ready', + autospec=True) + @mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.' + '_deploy_tripleo_heat_templates', autospec=True, + return_value='undercloud, 0') + @mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.' + '_download_ansible_playbooks', autospec=True, + return_value='/foo') + @mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.' + '_launch_heat') + @mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.' + '_kill_heat') + @mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.' + '_configure_puppet') + @mock.patch('os.geteuid', return_value=0) + @mock.patch('os.environ', return_value='CREATE_COMPLETE') + @mock.patch('tripleoclient.utils.wait_for_stack_ready', return_value=True) + @mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.' + '_set_default_plan') + def test_standalone_deploy_transport( + self, + mock_def_plan, mock_poll, + mock_environ, mock_geteuid, mock_puppet, + mock_killheat, mock_launchheat, + mock_download, mock_tht, + mock_wait_for_port, mock_createdirs, + mock_cleanupdirs, mock_tarball, + mock_templates_dir, mock_open, mock_os, + mock_chmod, mock_ac, + mock_outputs, mock_copy, mock_cmdline, + mock_chdir, mock_file_exists): + + # Test default transport "local" + parsed_args = self.check_parser(self.cmd, + ['--local-ip', '127.0.0.1', + '--templates', '/tmp/thtroot', + '--stack', 'undercloud', + '--output-dir', '/my', + '--output-only'], []) + + self.cmd.take_action(parsed_args) + self.assertEqual(1, mock_ac.call_count) + self.assertEqual( + "local", mock_ac.call_args_list[0].kwargs["transport"]) + + # Test transport "ssh" + mock_ac.reset_mock() + parsed_args = self.check_parser(self.cmd, + ['--local-ip', '127.0.0.1', + '--templates', '/tmp/thtroot', + '--stack', 'undercloud', + '--output-dir', '/my', + '--output-only', + '--transport', 'ssh'], []) + + self.cmd.take_action(parsed_args) + self.assertEqual(1, mock_ac.call_count) + self.assertEqual("ssh", mock_ac.call_args_list[0].kwargs["transport"]) diff --git a/tripleoclient/v1/tripleo_deploy.py b/tripleoclient/v1/tripleo_deploy.py index 700217820..3d0f51a4a 100644 --- a/tripleoclient/v1/tripleo_deploy.py +++ b/tripleoclient/v1/tripleo_deploy.py @@ -1081,6 +1081,15 @@ class Deploy(command.Command): 'deployed services are running right after their ' 'activation. Defaults to False.') ) + parser.add_argument( + '--transport', + action='store', + default='local', + help=_('Transport mechanism to use for ansible.' + 'Use "ssh" for multinode deployments. ' + 'Use "local" for standalone deployments. ' + 'Defaults to "local".') + ) stack_action_group = parser.add_mutually_exclusive_group() @@ -1271,13 +1280,13 @@ class Deploy(command.Command): self.log.warning( _('Generating default ansible config file %s') % ansible_config) - # FIXME(bogdando): unhardcode key/transport for future + # FIXME(bogdando): unhardcode key for future # multi-node ansible.write_default_ansible_cfg( self.ansible_dir, parsed_args.deployment_user, ssh_private_key=None, - transport='local') + transport=parsed_args.transport) else: self.log.warning( _('Using the existing %s for deployment') % ansible_config)