Strip whitespace from cookie in firmware update

When updating firmware, some devices return a cookie with a newline in.
This can result in the following error:

Invalid return character or leading space in header: Cookie

This is due to the header validation in the requests library, which
requires no newlines in headers.

This change fixes the issue by stripping whitespace from the cookie.

Change-Id: Ib2dab7beef0da415e8f2358b459ec1205bf688b4
Closes-Bug: #1859616
This commit is contained in:
Mark Goddard 2020-01-14 13:37:33 +00:00
parent 086b3485c2
commit 37afea2bbc
2 changed files with 7 additions and 1 deletions

View File

@ -1109,6 +1109,10 @@ class RIBCLOperations(operations.IloOperations):
LOG.debug(self._('Uploading firmware file: %s ...'), filename)
cookie = fw_img_processor.upload_file_to((self.host, self.port),
self.timeout)
# NOTE(mgoddard): Some devices return a cookie with a newline. This
# breaks header validation in the requests library, which causes the
# update to fail.
cookie = cookie.strip()
LOG.debug(self._('Uploading firmware file: %s ... done'), filename)
root = self._get_firmware_update_xml_for_file_and_component(

View File

@ -818,7 +818,9 @@ class IloRibclTestCase(unittest.TestCase):
def test_update_ilo_firmware(self, _parse_output_mock, _request_ilo_mock,
os_mock, upload_file_to_mock):
# | GIVEN |
upload_file_to_mock.return_value = 'hickory-dickory-dock'
# NOTE(mgoddard): Whitespace should be stripped from the cookie.
# https://launchpad.net/bugs/1859616.
upload_file_to_mock.return_value = ' hickory-dickory-dock'
os_mock.path.getsize.return_value = 12345
# | WHEN |
self.ilo.update_firmware('raw_fw_file.bin', 'ilo')