Archive overcloud deploy artifacts
This also refactors archiving method to utils. Change-Id: I1e8fc089de503cf96ea3812972e574add43ff631
This commit is contained in:
parent
0c669f61ec
commit
2bd39e61dc
|
@ -891,8 +891,8 @@ class TestDeployUndercloud(TestPluginV1):
|
|||
@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.utils.archive_deploy_artifacts',
|
||||
return_value='/tmp/foo.tar.bzip2')
|
||||
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
|
||||
'_cleanup_working_dirs')
|
||||
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
|
||||
|
@ -989,8 +989,8 @@ class TestDeployUndercloud(TestPluginV1):
|
|||
@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.utils.archive_deploy_artifacts',
|
||||
return_value='/tmp/foo.tar.bzip2')
|
||||
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
|
||||
'_cleanup_working_dirs')
|
||||
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
|
||||
|
@ -1077,8 +1077,8 @@ class TestDeployUndercloud(TestPluginV1):
|
|||
@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.utils.archive_deploy_artifacts',
|
||||
return_value='/tmp/foo.tar.bzip2')
|
||||
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
|
||||
'_cleanup_working_dirs')
|
||||
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
|
||||
|
@ -1236,8 +1236,8 @@ class TestDeployUndercloud(TestPluginV1):
|
|||
@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.utils.archive_deploy_artifacts',
|
||||
return_value='/tmp/foo.tar.bzip2')
|
||||
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
|
||||
'_cleanup_working_dirs')
|
||||
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
|
||||
|
@ -1298,8 +1298,8 @@ class TestDeployUndercloud(TestPluginV1):
|
|||
@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.utils.archive_deploy_artifacts',
|
||||
return_value='/tmp/foo.tar.bzip2')
|
||||
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
|
||||
'_cleanup_working_dirs')
|
||||
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
|
||||
|
|
|
@ -40,6 +40,7 @@ import six
|
|||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
import tempfile
|
||||
import time
|
||||
import yaml
|
||||
|
@ -1651,6 +1652,39 @@ def build_stack_data(clients, stack_name, template,
|
|||
return stack_data
|
||||
|
||||
|
||||
def archive_deploy_artifacts(log, stack_name, tht_dir,
|
||||
ansible_dir=None, output_dir=None):
|
||||
"""Create a tarball of the temporary folders used"""
|
||||
log.debug(_("Preserving deployment artifacts"))
|
||||
|
||||
if not output_dir:
|
||||
output_dir = tht_dir
|
||||
|
||||
def get_tar_filename():
|
||||
return '%s/%s-install-%s.tar.bzip2' % \
|
||||
(constants.CLOUD_HOME_DIR, stack_name,
|
||||
datetime.datetime.utcnow().strftime('%Y%m%d%H%M%S'))
|
||||
|
||||
def remove_leading_path(info):
|
||||
"""Tar filter to remove output dir from path"""
|
||||
leading_path = output_dir[1:] + '/'
|
||||
info.name = info.name.replace(leading_path, '')
|
||||
return info
|
||||
|
||||
tar_filename = get_tar_filename()
|
||||
try:
|
||||
tf = tarfile.open(tar_filename, 'w:bz2')
|
||||
tf.add(tht_dir, recursive=True, filter=remove_leading_path)
|
||||
if ansible_dir:
|
||||
tf.add(ansible_dir, recursive=True,
|
||||
filter=remove_leading_path)
|
||||
tf.close()
|
||||
except Exception as ex:
|
||||
msg = _("Unable to create artifact tarball, %s") % str(ex)
|
||||
log.warning(msg)
|
||||
return tar_filename
|
||||
|
||||
|
||||
def jinja_render_files(log, templates, working_dir,
|
||||
roles_file=None, networks_file=None,
|
||||
base_path=None, output_dir=None):
|
||||
|
|
|
@ -301,6 +301,8 @@ class DeployOvercloud(command.Command):
|
|||
self._deploy_tripleo_heat_templates(stack, parsed_args,
|
||||
new_tht_root, tht_root)
|
||||
finally:
|
||||
utils.archive_deploy_artifacts(self.log, parsed_args.stack,
|
||||
new_tht_root)
|
||||
if parsed_args.no_cleanup:
|
||||
self.log.warning("Not cleaning temporary directory %s"
|
||||
% tht_tmp)
|
||||
|
|
|
@ -24,14 +24,12 @@ import shutil
|
|||
import six
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
import tempfile
|
||||
import time
|
||||
import traceback
|
||||
import yaml
|
||||
|
||||
from cliff import command
|
||||
from datetime import datetime
|
||||
from heatclient.common import template_utils
|
||||
from osc_lib.i18n import _
|
||||
from six.moves import configparser
|
||||
|
@ -218,41 +216,6 @@ class Deploy(command.Command):
|
|||
'first defined role')
|
||||
return roles_data[0]['name']
|
||||
|
||||
def _get_tar_filename(self, stack_name='undercloud'):
|
||||
"""Return tarball name for the install artifacts"""
|
||||
return '%s/%s-install-%s.tar.bzip2' % \
|
||||
(self.output_dir, stack_name,
|
||||
datetime.utcnow().strftime('%Y%m%d%H%M%S'))
|
||||
|
||||
def _create_install_artifact(self, user, stack_name='undercloud'):
|
||||
"""Create a tarball of the temporary folders used"""
|
||||
self.log.debug(_("Preserving deployment artifacts"))
|
||||
|
||||
def remove_output_dir(info):
|
||||
"""Tar filter to remove output dir from path"""
|
||||
# leading path to tar is home/stack/ rather than /home/stack
|
||||
leading_path = self.output_dir[1:] + '/'
|
||||
info.name = info.name.replace(leading_path, '')
|
||||
return info
|
||||
|
||||
# tar up working data and put in
|
||||
# output_dir/undercloud-install-TS.tar.bzip2
|
||||
# if the stack name is "undercloud".
|
||||
tar_filename = self._get_tar_filename(stack_name)
|
||||
try:
|
||||
tf = tarfile.open(tar_filename, 'w:bz2')
|
||||
tf.add(self.tht_render, recursive=True, filter=remove_output_dir)
|
||||
tf.add(self.tmp_ansible_dir, recursive=True,
|
||||
filter=remove_output_dir)
|
||||
tf.close()
|
||||
except Exception as ex:
|
||||
msg = _("Unable to create artifact tarball, %s") % ex.message
|
||||
self.log.error(msg)
|
||||
raise exceptions.DeploymentError(msg)
|
||||
# TODO(cjeanner) drop that once using oslo.privsep
|
||||
self._set_data_rights(tar_filename, user=user)
|
||||
return tar_filename
|
||||
|
||||
def _create_persistent_dirs(self):
|
||||
"""Creates temporary working directories"""
|
||||
utils.makedirs(constants.STANDALONE_EPHEMERAL_STACK_VSTATE)
|
||||
|
@ -1389,8 +1352,13 @@ class Deploy(command.Command):
|
|||
if not parsed_args.keep_running:
|
||||
self._kill_heat(parsed_args)
|
||||
tar_filename = \
|
||||
self._create_install_artifact(parsed_args.deployment_user,
|
||||
parsed_args.stack.lower())
|
||||
utils.archive_deploy_artifacts(
|
||||
self.log,
|
||||
parsed_args.stack.lower(),
|
||||
self.tht_render,
|
||||
self.tmp_ansible_dir,
|
||||
self.output_dir)
|
||||
|
||||
if self.ansible_dir:
|
||||
self._dump_ansible_errors(
|
||||
os.path.join(self.ansible_dir,
|
||||
|
|
Loading…
Reference in New Issue