From 0736e447f9f8a075aaf5de0b40e4d20428e2c7ce Mon Sep 17 00:00:00 2001
From: Mathieu Bultel <mat.bultel@gmail.com>
Date: Thu, 25 Feb 2021 13:02:07 +0100
Subject: [PATCH] Copy the inventory for standalone deploy in output_dir

In order to be re-used by post deployment action, this review
copy the ansible inventory into the output_dir as:
standalone-inventory.yaml.
If file exist it will replace the old one.

Change-Id: Ied14f40cf074755225abe1e8f1c859bacbe9022f
---
 tripleoclient/constants.py                            | 5 +++--
 tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py | 4 +++-
 tripleoclient/v1/tripleo_deploy.py                    | 4 ++++
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/tripleoclient/constants.py b/tripleoclient/constants.py
index 2f0b91120..0f4a45ea9 100644
--- a/tripleoclient/constants.py
+++ b/tripleoclient/constants.py
@@ -101,9 +101,10 @@ VALIDATIONS_LOG_BASEDIR = '/var/log/validations'
 DEFAULT_WORK_DIR = os.path.join(os.environ.get('HOME', '~/'),
                                 'config-download')
 
-ANSIBLE_INVENTORY = os.path.join(DEFAULT_WORK_DIR,
-                                 '{}/tripleo-ansible-inventory.yaml')
+TRIPLEO_STATIC_INVENTORY = 'tripleo-ansible-inventory.yaml'
 
+ANSIBLE_INVENTORY = os.path.join(DEFAULT_WORK_DIR,
+                                 '{}/', TRIPLEO_STATIC_INVENTORY)
 ANSIBLE_VALIDATION_DIR = (
     os.path.join(DEFAULT_VALIDATIONS_LEGACY_BASEDIR, 'playbooks')
     if os.path.exists(os.path.join(DEFAULT_VALIDATIONS_LEGACY_BASEDIR,
diff --git a/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py b/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py
index 450a97f34..20dc1342c 100644
--- a/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py
+++ b/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py
@@ -822,7 +822,9 @@ class TestDeployUndercloud(TestPluginV1):
     @mock.patch('tripleo_common.utils.config.Config',
                 autospec=True)
     @mock.patch('os.path.join', return_value='/twd/inventory.yaml')
-    def test_download_ansible_playbooks(self, mock_join, mock_stack_config,
+    @mock.patch('shutil.copyfile')
+    def test_download_ansible_playbooks(self, mock_shutil, mock_join,
+                                        mock_stack_config,
                                         mock_launch_heat, mock_importInv,
                                         createdir_mock):
 
diff --git a/tripleoclient/v1/tripleo_deploy.py b/tripleoclient/v1/tripleo_deploy.py
index 528733468..34a75b6ee 100644
--- a/tripleoclient/v1/tripleo_deploy.py
+++ b/tripleoclient/v1/tripleo_deploy.py
@@ -853,6 +853,10 @@ class Deploy(command.Command):
             }
 
         inventory.write_static_inventory(inv_path, extra_vars)
+        # Move inventory in output_dir in order to be reusable by users:
+        shutil.copyfile(inv_path,
+                        os.path.join(self.output_dir,
+                                     constants.TRIPLEO_STATIC_INVENTORY))
 
         self.log.info(_('** Downloaded {0} ansible to {1} **').format(
                       stack_name, self.tmp_ansible_dir))