Add --cleanup argument for image uploads
This exposes the new cleanup behavior from change Id844aa2fa5ee20ad264b2fada75fa6cffdc1e307. When this lands it can be used in CI to make undercloud deploys faster with --cleanup partial. Change-Id: Id75d5288c308e58143662703da3dddbdbcb0cdd9 Blueprint: container-prepare-workflow
This commit is contained in:
parent
df93f7f804
commit
cffe1ad2a7
6
releasenotes/notes/upload-cleanup-511b915c83db8a82.yaml
Normal file
6
releasenotes/notes/upload-cleanup-511b915c83db8a82.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
The commands `openstack tripleo container image prepare` and `openstack
|
||||
overcloud container image upload` now have a --cleanup option to control
|
||||
what local images are removed after the image upload is complete.
|
@ -23,10 +23,23 @@ import sys
|
||||
import tempfile
|
||||
import yaml
|
||||
|
||||
from tripleo_common.image import image_uploader
|
||||
from tripleo_common.image import kolla_builder
|
||||
from tripleoclient.tests.v1.test_plugin import TestPluginV1
|
||||
from tripleoclient.v1 import container_image
|
||||
|
||||
# TODO(sbaker) Remove after a tripleo-common release contains this attribute
|
||||
CLEANUP = (
|
||||
CLEANUP_FULL, CLEANUP_PARTIAL, CLEANUP_NONE
|
||||
) = (
|
||||
'full', 'partial', 'none'
|
||||
)
|
||||
if not hasattr(image_uploader, 'CLEANUP'):
|
||||
setattr(image_uploader, 'CLEANUP', CLEANUP)
|
||||
setattr(image_uploader, 'CLEANUP_FULL', CLEANUP_FULL)
|
||||
setattr(image_uploader, 'CLEANUP_PARTIAL', CLEANUP_PARTIAL)
|
||||
setattr(image_uploader, 'CLEANUP_NONE', CLEANUP_NONE)
|
||||
|
||||
|
||||
class TestContainerImageUpload(TestPluginV1):
|
||||
|
||||
@ -37,8 +50,7 @@ class TestContainerImageUpload(TestPluginV1):
|
||||
self.cmd = container_image.UploadImage(self.app, None)
|
||||
|
||||
@mock.patch('sys.exit')
|
||||
@mock.patch('tripleo_common.image.image_uploader.ImageUploadManager',
|
||||
autospec=True)
|
||||
@mock.patch('tripleo_common.image.image_uploader.ImageUploadManager')
|
||||
def test_container_image_upload_noargs(self, mock_manager, exit_mock):
|
||||
arglist = []
|
||||
verifylist = []
|
||||
@ -49,8 +61,7 @@ class TestContainerImageUpload(TestPluginV1):
|
||||
# argparse will complain that --config-file is missing and exit with 2
|
||||
exit_mock.assert_called_with(2)
|
||||
|
||||
@mock.patch('tripleo_common.image.image_uploader.ImageUploadManager',
|
||||
autospec=True)
|
||||
@mock.patch('tripleo_common.image.image_uploader.ImageUploadManager')
|
||||
def test_container_image_upload_conf_files(self, mock_manager):
|
||||
arglist = [
|
||||
'--config-file',
|
||||
@ -65,7 +76,7 @@ class TestContainerImageUpload(TestPluginV1):
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
mock_manager.assert_called_once_with(
|
||||
['/tmp/foo.yaml', '/tmp/bar.yaml'])
|
||||
['/tmp/foo.yaml', '/tmp/bar.yaml'], cleanup='full')
|
||||
mock_manager.return_value.upload.assert_called_once_with()
|
||||
|
||||
|
||||
@ -352,7 +363,10 @@ class TestTripleoImagePrepare(TestPluginV1):
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
prepare_multi.assert_called_once_with(
|
||||
self.default_env, yaml.safe_load(self.roles_yaml), dry_run=False)
|
||||
self.default_env,
|
||||
yaml.safe_load(self.roles_yaml),
|
||||
dry_run=False,
|
||||
cleanup='full')
|
||||
|
||||
with open(env_file) as f:
|
||||
result = yaml.safe_load(f)
|
||||
|
@ -68,12 +68,26 @@ class UploadImage(command.Command):
|
||||
"files will override some options in previous files. "
|
||||
"Other options will append."),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--cleanup",
|
||||
dest="cleanup",
|
||||
metavar='<full, partial, none>',
|
||||
default=image_uploader.CLEANUP_FULL,
|
||||
help=_("Cleanup behavior for local images left after upload. "
|
||||
"The default 'full' will attempt to delete all local "
|
||||
"images. 'partial' will leave images required for "
|
||||
"deployment on this host. 'none' will do no cleanup.")
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)" % parsed_args)
|
||||
if parsed_args.cleanup not in image_uploader.CLEANUP:
|
||||
raise oscexc.CommandError('--cleanup must be one of: %s' %
|
||||
', '.join(image_uploader.CLEANUP))
|
||||
uploader = image_uploader.ImageUploadManager(
|
||||
parsed_args.config_files)
|
||||
parsed_args.config_files, cleanup=parsed_args.cleanup)
|
||||
try:
|
||||
uploader.upload()
|
||||
except KeyboardInterrupt: # ctrl-c
|
||||
@ -577,11 +591,25 @@ class TripleOImagePrepare(command.Command):
|
||||
'The environment file will still be populated as if these '
|
||||
'operations were performed.')
|
||||
)
|
||||
parser.add_argument(
|
||||
"--cleanup",
|
||||
dest="cleanup",
|
||||
metavar='<full, partial, none>',
|
||||
default=image_uploader.CLEANUP_FULL,
|
||||
help=_("Cleanup behavior for local images left after upload. "
|
||||
"The default 'full' will attempt to delete all local "
|
||||
"images. 'partial' will leave images required for "
|
||||
"deployment on this host. 'none' will do no cleanup.")
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)" % parsed_args)
|
||||
|
||||
if parsed_args.cleanup not in image_uploader.CLEANUP:
|
||||
raise oscexc.CommandError('--cleanup must be one of: %s' %
|
||||
', '.join(image_uploader.CLEANUP))
|
||||
|
||||
if parsed_args.roles_file:
|
||||
roles_data = yaml.safe_load(open(parsed_args.roles_file).read())
|
||||
else:
|
||||
@ -593,7 +621,8 @@ class TripleOImagePrepare(command.Command):
|
||||
)
|
||||
|
||||
params = kolla_builder.container_images_prepare_multi(
|
||||
env, roles_data, dry_run=parsed_args.dry_run)
|
||||
env, roles_data, dry_run=parsed_args.dry_run,
|
||||
cleanup=parsed_args.cleanup)
|
||||
env_data = build_env_file(params, self.app.command_options)
|
||||
if parsed_args.output_env_file:
|
||||
with os.fdopen(os.open(parsed_args.output_env_file,
|
||||
|
Loading…
Reference in New Issue
Block a user