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
This commit is contained in:
Debayan Ray 2016-04-17 23:59:05 -07:00
parent 98de09ebbd
commit 6bc735c534
3 changed files with 29 additions and 11 deletions

View File

@ -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)

View File

@ -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(

View File

@ -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.