From 6bc735c534fb8ef7234734be37a11a10c7b5ad15 Mon Sep 17 00:00:00 2001 From: Debayan Ray Date: Sun, 17 Apr 2016 23:59:05 -0700 Subject: [PATCH] File download fails with swift pseudo folder As part of manual cleaning step of firmware update the download of firmware file fails if the firmware file is associated with swift pseudo folder. Currently only basename of the parsed swift url path is taken into consideration while retrieving the object name from swift. This is to fix that by now taking the complete path of the swift object to include the pseudo folder as well, if included. Closes-Bug: #1571496 Change-Id: Ib71692e191501701a92cd7acacb172d0d7fce922 --- .../drivers/modules/ilo/firmware_processor.py | 8 ++++-- .../modules/ilo/test_firmware_processor.py | 27 ++++++++++++------- ...h-with-pseudo-folder-0660345510ec0bb4.yaml | 5 ++++ 3 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 releasenotes/notes/fix-ilo-firmware-update-swift-path-with-pseudo-folder-0660345510ec0bb4.yaml diff --git a/ironic/drivers/modules/ilo/firmware_processor.py b/ironic/drivers/modules/ilo/firmware_processor.py index 52838ed3742..53e159a95a6 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 d5f0f6f1469..a041376310b 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 00000000000..64257c87f63 --- /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.