Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ironic/common/image_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ def publish(self, source_path, file_name=None):
'public': published_file,
'error': exc})

shutil.copyfile(source_path, published_file)
try:
shutil.copyfile(source_path, published_file)
except shutil.SameFileError:
LOG.debug('Image %(image)s is already published at '
'%(public)s',
{'image': source_path,
'public': published_file})
os.chmod(published_file, self.file_permission)

if self.image_subdir:
Expand Down
18 changes: 18 additions & 0 deletions ironic/tests/unit/common/test_image_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,24 @@ def test_publish_local_copy(self, mock_mkdir, mock_link,
mock_chmod.assert_called_once_with('/httpboot/redfish/boot.iso',
0o644)

@mock.patch.object(os, 'chmod', autospec=True)
@mock.patch.object(shutil, 'copyfile', autospec=True)
@mock.patch.object(os, 'link', autospec=True)
@mock.patch.object(os, 'mkdir', autospec=True)
def test_publish_local_already_published(self, mock_mkdir, mock_link,
mock_copyfile, mock_chmod):
mock_link.side_effect = FileExistsError()
mock_copyfile.side_effect = shutil.SameFileError()

url = self.publisher.publish('file.iso', 'boot.iso')

self.assertEqual(
'http://localhost/redfish/boot.iso', url)
mock_copyfile.assert_called_once_with(
'file.iso', '/httpboot/redfish/boot.iso')
mock_chmod.assert_called_once_with('/httpboot/redfish/boot.iso',
0o644)

@mock.patch.object(utils, 'unlink_without_raise', autospec=True)
def test_unpublish_local(self, mock_unlink):
object_name = 'boot.iso'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
fixes:
- |
Fixes a ``SameFileError`` when publishing an image to the local HTTP
server whose destination is already a hardlink to the source, which
happens when a previous deployment published the same cached image and
did not clean it up. The image is already published in that case, so it
is no longer treated as an error. See
`bug 2150735 <https://bugs.launchpad.net/ironic/+bug/2150735>`_.