diff --git a/ironic/drivers/modules/ilo/firmware_processor.py b/ironic/drivers/modules/ilo/firmware_processor.py index 52838ed374..53e159a95a 100644 --- a/ironic/drivers/modules/ilo/firmware_processor.py +++ b/ironic/drivers/modules/ilo/firmware_processor.py @@ -259,9 +259,13 @@ def _download_swift_based_fw_to(self, target_file): :raises: SwiftOperationError, on failure to download from swift. :raises: ImageDownloadFailed, on failure to download the original file. """ - # Extract container name and object name + # Extract container name container = self.parsed_url.netloc - objectname = os.path.basename(self.parsed_url.path) + # Extract the object name from the path of the form: + # ``/objectname`` OR + # ``/pseudo-folder/objectname`` + # stripping the leading '/' character. + objectname = self.parsed_url.path.lstrip('/') timeout = CONF.ilo.swift_object_expiry_timeout # Generate temp url using swift API tempurl = swift.SwiftAPI().get_temp_url(container, objectname, timeout) diff --git a/ironic/tests/unit/drivers/modules/ilo/test_firmware_processor.py b/ironic/tests/unit/drivers/modules/ilo/test_firmware_processor.py index d5f0f6f146..a041376310 100644 --- a/ironic/tests/unit/drivers/modules/ilo/test_firmware_processor.py +++ b/ironic/tests/unit/drivers/modules/ilo/test_firmware_processor.py @@ -363,16 +363,25 @@ class FirmwareProcessorTestCase(base.TestCase): def test__download_swift_based_fw_to_creates_temp_url( self, swift_mock, _download_http_based_fw_to_mock, urlparse_mock): # | GIVEN | - any_swift_based_firmware_file = 'swift://containername/objectname' - any_target_file = 'any_target_file' - self.fw_processor_fake.parsed_url = urlparse.urlparse( - any_swift_based_firmware_file) - # | WHEN | - ilo_fw_processor._download_swift_based_fw_to(self.fw_processor_fake, - any_target_file) + swift_based_firmware_files = [ + 'swift://containername/objectname', + 'swift://containername/pseudo-folder/objectname' + ] + for swift_firmware_file in swift_based_firmware_files: + # | WHEN | + self.fw_processor_fake.parsed_url = (urlparse. + urlparse(swift_firmware_file)) + ilo_fw_processor._download_swift_based_fw_to( + self.fw_processor_fake, 'any_target_file') # | THEN | - swift_mock.SwiftAPI().get_temp_url.assert_called_once_with( - 'containername', 'objectname', mock.ANY) + expected_temp_url_call_args_list = [ + mock.call('containername', 'objectname', mock.ANY), + mock.call('containername', 'pseudo-folder/objectname', mock.ANY) + ] + actual_temp_url_call_args_list = ( + swift_mock.SwiftAPI().get_temp_url.call_args_list) + self.assertEqual(expected_temp_url_call_args_list, + actual_temp_url_call_args_list) @mock.patch.object(urlparse, 'urlparse', autospec=True) @mock.patch.object( diff --git a/releasenotes/notes/fix-ilo-firmware-update-swift-path-with-pseudo-folder-0660345510ec0bb4.yaml b/releasenotes/notes/fix-ilo-firmware-update-swift-path-with-pseudo-folder-0660345510ec0bb4.yaml new file mode 100644 index 0000000000..64257c87f6 --- /dev/null +++ b/releasenotes/notes/fix-ilo-firmware-update-swift-path-with-pseudo-folder-0660345510ec0bb4.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - Fixes an issue where iLO drivers fail to download the + firmware file from swift when the swift file path + includes swift pseudo folder.