From ee82c45bb5860fe656c4d40fb67b96672945d07b Mon Sep 17 00:00:00 2001 From: Julia Kreger Date: Mon, 24 Apr 2023 17:16:04 -0700 Subject: [PATCH] Fix nvidia hardware manager url parser to permit https Change-Id: I9a10e543d3256ceaa78c6fbdb01fc0d88c0ee6e6 --- .../nvidia/nvidia_fw_update.py | 6 ++-- .../nvidia/test_nvidia_fw_update.py | 34 +++++++++++++++++++ ...-nvidia-hw-mgr-https-38825a4161a8561b.yaml | 5 +++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/fix-nvidia-hw-mgr-https-38825a4161a8561b.yaml diff --git a/ironic_python_agent/hardware_managers/nvidia/nvidia_fw_update.py b/ironic_python_agent/hardware_managers/nvidia/nvidia_fw_update.py index 73cefe5e9..044313784 100644 --- a/ironic_python_agent/hardware_managers/nvidia/nvidia_fw_update.py +++ b/ironic_python_agent/hardware_managers/nvidia/nvidia_fw_update.py @@ -429,7 +429,7 @@ class NvidiaNicFirmwareBinary(object): """Process the firmware url and download the image to a temporary destination in the system. - The supported firmware URL schemes are (file://, http://) + The supported firmware URL schemes are (file://, http://, https://) :returns: None :raises: InvalidURLScheme, for unsupported firmware url """ @@ -441,12 +441,12 @@ class NvidiaNicFirmwareBinary(object): url_scheme = parsed_url.scheme if url_scheme == 'file': self._download_file_based_fw() - elif url_scheme == 'http': + elif url_scheme == 'http' or url_scheme == 'https': self._download_http_based_fw() else: err = 'Firmware URL scheme %s is not supported.' \ 'The supported firmware URL schemes are' \ - '(http://, file://)' % url_scheme + '(http://, https://, file://)' % url_scheme raise InvalidURLScheme(error_msg=_(err)) def _get_info(self): diff --git a/ironic_python_agent/tests/unit/hardware_managers/nvidia/test_nvidia_fw_update.py b/ironic_python_agent/tests/unit/hardware_managers/nvidia/test_nvidia_fw_update.py index cde061195..5d329fd15 100644 --- a/ironic_python_agent/tests/unit/hardware_managers/nvidia/test_nvidia_fw_update.py +++ b/ironic_python_agent/tests/unit/hardware_managers/nvidia/test_nvidia_fw_update.py @@ -365,6 +365,40 @@ PSID: MT_0000000228 self.assertEqual(nvidia_nic_fw_binary.dest_file_path, '/tmp/nvidia_firmware123/fw1.bin') + @mock.patch.object(nvidia_fw_update.request, 'urlopen', autospec=True) + @mock.patch.object(builtins, 'open', autospec=True) + @mock.patch.object(utils, 'execute', autospec=True) + @mock.patch.object(fileutils, 'compute_file_checksum', autospec=True) + @mock.patch.object(tempfile, 'mkdtemp', autospec=True) + def test_nvidia_nic_firmware_binray_https( + self, mocked_mkdtemp, mocked_compute_file_checksum, + mocked_execute, open_mock, mocked_url_open): + mocked_mkdtemp.return_value = '/tmp/nvidia_firmware123/' + a = mock.Mock() + a.read.return_value = 'dummy data' + mocked_url_open.return_value = a + mocked_execute.return_value = ("""Image type: FS4 +FW Version: 20.35.1012 +PSID: MT_0000000228 +""", '') + mocked_compute_file_checksum.return_value = \ + 'a94e683ea16d9ae44768f0a65942234c' + fd_mock = mock.MagicMock(spec=io.BytesIO) + open_mock.return_value = fd_mock + nvidia_nic_fw_binary = nvidia_fw_update.NvidiaNicFirmwareBinary( + 'https://10.10.10.10/firmware_images/fw1.bin', + 'a94e683ea16d9ae44768f0a65942234c', + 'sha512', + 'MT_0000000228', + '20.35.1012') + mocked_execute.assert_called_once() + mocked_compute_file_checksum.assert_called_once() + open_mock.assert_called_once() + mocked_url_open.assert_called_once() + mocked_mkdtemp.assert_called_once() + self.assertEqual(nvidia_nic_fw_binary.dest_file_path, + '/tmp/nvidia_firmware123/fw1.bin') + def test_nvidia_nic_firmware_binray_invalid_url_scheme(self): self.assertRaises(nvidia_fw_update.InvalidURLScheme, nvidia_fw_update.NvidiaNicFirmwareBinary, diff --git a/releasenotes/notes/fix-nvidia-hw-mgr-https-38825a4161a8561b.yaml b/releasenotes/notes/fix-nvidia-hw-mgr-https-38825a4161a8561b.yaml new file mode 100644 index 000000000..f5d6b2bc4 --- /dev/null +++ b/releasenotes/notes/fix-nvidia-hw-mgr-https-38825a4161a8561b.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixes the nvidia hardware manager firmware upgrade support to permit + URLs with an "https" schema.