Browse Source

Add locks to container image commands

Ie5ef4045b7e22c06551e886f9f9b6f22c8d4bd21 added some additional
processing when uploading images. This unfortunately broke the
'openstack tripleo container image push' command because it assumes a
lock is always available. This change adds a process lock to the
ImageManagers used by the cli to ensure we are locking correctly when
doing any multiprocessing

Change-Id: I2d661682b3ee4d82d9f445a04e930c2fb328ef80
Closes-Bug: #1855184
(cherry picked from commit 94f8ef1df8)
changes/68/701568/2
Alex Schultz 2 months ago
parent
commit
fe332308f0
2 changed files with 19 additions and 5 deletions
  1. +15
    -3
      tripleoclient/tests/v1/test_container_image.py
  2. +4
    -2
      tripleoclient/v1/container_image.py

+ 15
- 3
tripleoclient/tests/v1/test_container_image.py View File

@@ -49,20 +49,28 @@ class TestContainerImageUpload(TestPluginV1):
# Get the command object to test
self.cmd = container_image.UploadImage(self.app, None)

@mock.patch('tripleo_common.utils.locks.processlock.'
'ProcessLock')
@mock.patch('sys.exit')
@mock.patch('tripleo_common.image.image_uploader.ImageUploadManager')
def test_container_image_upload_noargs(self, mock_manager, exit_mock):
def test_container_image_upload_noargs(self, mock_manager, exit_mock,
mock_lock):
arglist = []
verifylist = []

mock_lockobj = mock.MagicMock()
mock_lock.return_value = mock_lockobj

parsed_args = self.check_parser(self.cmd, arglist, verifylist)

self.cmd.take_action(parsed_args)
# argparse will complain that --config-file is missing and exit with 2
exit_mock.assert_called_with(2)

@mock.patch('tripleo_common.utils.locks.processlock.'
'ProcessLock')
@mock.patch('tripleo_common.image.image_uploader.ImageUploadManager')
def test_container_image_upload_conf_files(self, mock_manager):
def test_container_image_upload_conf_files(self, mock_manager, mock_lock):
arglist = [
'--config-file',
'/tmp/foo.yaml',
@@ -71,12 +79,16 @@ class TestContainerImageUpload(TestPluginV1):
]
verifylist = []

mock_lockobj = mock.MagicMock()
mock_lock.return_value = mock_lockobj

parsed_args = self.check_parser(self.cmd, arglist, verifylist)

self.cmd.take_action(parsed_args)

mock_manager.assert_called_once_with(
['/tmp/foo.yaml', '/tmp/bar.yaml'], cleanup='full')
['/tmp/foo.yaml', '/tmp/bar.yaml'], cleanup='full',
lock=mock_lockobj)
mock_manager.return_value.upload.assert_called_once_with()



+ 4
- 2
tripleoclient/v1/container_image.py View File

@@ -90,8 +90,9 @@ class UploadImage(command.Command):
if parsed_args.cleanup not in image_uploader.CLEANUP:
raise oscexc.CommandError('--cleanup must be one of: %s' %
', '.join(image_uploader.CLEANUP))
lock = processlock.ProcessLock()
uploader = image_uploader.ImageUploadManager(
parsed_args.config_files, cleanup=parsed_args.cleanup)
parsed_args.config_files, cleanup=parsed_args.cleanup, lock=lock)
try:
uploader.upload()
except KeyboardInterrupt: # ctrl-c
@@ -515,7 +516,8 @@ class DiscoverImageTag(command.Command):
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)

uploader = image_uploader.ImageUploadManager([])
lock = processlock.ProcessLock()
uploader = image_uploader.ImageUploadManager([], lock=lock)
print(uploader.discover_image_tag(
image=parsed_args.image,
tag_from_label=parsed_args.tag_from_label

Loading…
Cancel
Save