From 4cf79c5c3af67b5327366faed09e9ebb333d7739 Mon Sep 17 00:00:00 2001 From: James Slagle Date: Tue, 15 Jun 2021 16:24:44 -0400 Subject: [PATCH] Copy the deployment archive to /var/lib/tripleo Save a copy of the deployment archive to /var/lib/tripleo to avoid accidental deletion by a normal user. Change-Id: I9f5dc697dd1cd7895723d4c23ce89a00631b310f Signed-off-by: James Slagle --- tripleoclient/constants.py | 1 + .../v1/overcloud_deploy/test_overcloud_deploy.py | 9 ++++++++- tripleoclient/utils.py | 13 +++++++++++++ tripleoclient/v1/overcloud_deploy.py | 7 +++++-- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/tripleoclient/constants.py b/tripleoclient/constants.py index 40d24c13f..35afcfe64 100644 --- a/tripleoclient/constants.py +++ b/tripleoclient/constants.py @@ -19,6 +19,7 @@ import sys from osc_lib.i18n import _ from six.moves import configparser +TRIPLEO_ARCHIVE_DIR = "/var/lib/tripleo/archive" TRIPLEO_HEAT_TEMPLATES = "/usr/share/openstack-tripleo-heat-templates/" OVERCLOUD_YAML_NAME = "overcloud.yaml" OVERCLOUD_ROLES_FILE = "roles_data.yaml" diff --git a/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py b/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py index dbe2a8541..43ea7b4dd 100644 --- a/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py +++ b/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py @@ -81,10 +81,17 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): mock_sleep.start() self.addCleanup(mock_sleep.stop) - mock_run_command = mock.patch( + mock_run_command_and_log = mock.patch( 'tripleoclient.utils.run_command_and_log', autospec=True, return_value=0) + mock_run_command_and_log.start() + self.addCleanup(mock_run_command_and_log.stop) + + mock_run_command = mock.patch( + 'tripleoclient.utils.run_command', + autospec=True, + return_value=0) mock_run_command.start() self.addCleanup(mock_run_command.stop) diff --git a/tripleoclient/utils.py b/tripleoclient/utils.py index 4640ddc92..2084ee26c 100644 --- a/tripleoclient/utils.py +++ b/tripleoclient/utils.py @@ -2875,3 +2875,16 @@ def run_role_playbooks(self, working_dir, roles_file_dir, roles): # Network Config run_role_playbook(self, inventory, constants.ANSIBLE_TRIPLEO_PLAYBOOKS, 'cli-overcloud-node-network-config.yaml') + + +def create_archive_dir(self, archive_dir=constants.TRIPLEO_ARCHIVE_DIR): + """Create the TripleO archive directory as root. The directory is created + in a location typically owned by root (/var/lib), and remains owned as root + to decrease the chance it is accidentally deleted by a normal user. + + :param archive_dir: The archive directory to create + :type archive_dir: string + + :return: None + """ + return run_command(['sudo', 'mkdir', '-p', archive_dir]) diff --git a/tripleoclient/v1/overcloud_deploy.py b/tripleoclient/v1/overcloud_deploy.py index d300c7c37..60d8c05c7 100644 --- a/tripleoclient/v1/overcloud_deploy.py +++ b/tripleoclient/v1/overcloud_deploy.py @@ -1238,8 +1238,11 @@ class DeployOvercloud(command.Command): ansible_dir = config_download_dir else: ansible_dir = None - utils.archive_deploy_artifacts(self.log, parsed_args.stack, - self.working_dir, ansible_dir) + archive_filename = utils.archive_deploy_artifacts( + self.log, parsed_args.stack, self.working_dir, ansible_dir) + utils.run_command( + ['sudo', 'cp', archive_filename, + constants.TRIPLEO_ARCHIVE_DIR]) except Exception as e: self.log.error('Exception archiving deploy artifacts') self.log.error(e)