diff options
author | Iury Gregory Melo Ferreira <imelofer@redhat.com> | 2022-08-05 02:44:03 -0300 |
---|---|---|
committer | Iury Gregory Melo Ferreira <imelofer@redhat.com> | 2022-08-10 19:28:55 -0300 |
commit | c197a2d8b24e2fa4c5e7901e448da1b0c93fcd26 (patch) | |
tree | 0bcff1ba6f183a3c4e72db17d1ef1924a70ea93b /ironic/tests/unit/drivers/modules/test_image_utils.py | |
parent | 45c9c3029f5363b6e24e578648c09213a7338db1 (diff) | |
download | ironic-c197a2d8b24e2fa4c5e7901e448da1b0c93fcd26.tar.gz |
Override external_http_url at node level
This patch adds support to specify the URL to be used to publish
the node image when using virtual media.
The option is available under `driver_info['external_http_url']`,
if set this value has priority over the values in the configuration
file ([deploy]/external_http_url and [deploy]/http_url)
Story: 2010221
Task: 45970
Change-Id: If6a117a756b7d2a04251792f88c2ee412a040b28
Diffstat (limited to 'ironic/tests/unit/drivers/modules/test_image_utils.py')
-rw-r--r-- | ironic/tests/unit/drivers/modules/test_image_utils.py | 89 |
1 files changed, 85 insertions, 4 deletions
diff --git a/ironic/tests/unit/drivers/modules/test_image_utils.py b/ironic/tests/unit/drivers/modules/test_image_utils.py index 6d79629d9..753452f5d 100644 --- a/ironic/tests/unit/drivers/modules/test_image_utils.py +++ b/ironic/tests/unit/drivers/modules/test_image_utils.py @@ -151,6 +151,32 @@ class RedfishImageHandlerTestCase(db_base.DbTestCase): @mock.patch.object(image_utils, 'shutil', autospec=True) @mock.patch.object(os, 'link', autospec=True) @mock.patch.object(os, 'mkdir', autospec=True) + def test_publish_image_external_ip_node_override( + self, mock_mkdir, mock_link, mock_shutil, mock_chmod): + self.config(use_swift=False, group='redfish') + self.config(http_url='http://localhost', + external_http_url='http://non-local.host', + group='deploy') + img_handler_obj = image_utils.ImageHandler(self.node.driver) + self.node.driver_info["external_http_url"] = "http://node.override.url" + + override_url = self.node.driver_info.get("external_http_url") + + url = img_handler_obj.publish_image('file.iso', 'boot.iso', + override_url) + + self.assertEqual( + 'http://node.override.url/redfish/boot.iso', url) + + mock_mkdir.assert_called_once_with('/httpboot/redfish', 0o755) + mock_link.assert_called_once_with( + 'file.iso', '/httpboot/redfish/boot.iso') + mock_chmod.assert_called_once_with('file.iso', 0o644) + + @mock.patch.object(os, 'chmod', autospec=True) + @mock.patch.object(image_utils, 'shutil', autospec=True) + @mock.patch.object(os, 'link', autospec=True) + @mock.patch.object(os, 'mkdir', autospec=True) def test_publish_image_local_copy(self, mock_mkdir, mock_link, mock_shutil, mock_chmod): self.config(use_swift=False, group='redfish') @@ -271,8 +297,8 @@ class RedfishImageUtilsTestCase(db_base.DbTestCase): object_name = 'image-%s' % task.node.uuid - mock_publish_image.assert_called_once_with(mock.ANY, - mock.ANY, object_name) + mock_publish_image.assert_called_once_with(mock.ANY, mock.ANY, + object_name, None) mock_create_vfat_image.assert_called_once_with( mock.ANY, parameters=None) @@ -295,8 +321,63 @@ class RedfishImageUtilsTestCase(db_base.DbTestCase): object_name = 'image-%s' % task.node.uuid - mock_publish_image.assert_called_once_with(mock.ANY, - mock.ANY, object_name) + mock_publish_image.assert_called_once_with(mock.ANY, mock.ANY, + object_name, None) + + mock_create_vfat_image.assert_called_once_with( + mock.ANY, parameters={"ipa-api-url": "http://callback"}) + + self.assertEqual(expected_url, url) + + @mock.patch.object(image_utils.ImageHandler, 'publish_image', + autospec=True) + @mock.patch.object(images, 'create_vfat_image', autospec=True) + def test_prepare_floppy_image_publish_with_config_external_http_url( + self, mock_create_vfat_image, mock_publish_image): + self.config(external_callback_url='http://callback/', + external_http_url='http://config.external.url', + group='deploy') + with task_manager.acquire(self.context, self.node.uuid, + shared=True) as task: + expected_url = 'https://config.external.url/c.f?e=f' + + mock_publish_image.return_value = expected_url + + url = image_utils.prepare_floppy_image(task) + + object_name = 'image-%s' % task.node.uuid + + mock_publish_image.assert_called_once_with(mock.ANY, mock.ANY, + object_name, None) + + mock_create_vfat_image.assert_called_once_with( + mock.ANY, parameters={"ipa-api-url": "http://callback"}) + + self.assertEqual(expected_url, url) + + @mock.patch.object(image_utils.ImageHandler, 'publish_image', + autospec=True) + @mock.patch.object(images, 'create_vfat_image', autospec=True) + def test_prepare_floppy_image_publish_with_node_external_http_url( + self, mock_create_vfat_image, mock_publish_image): + self.config(external_callback_url='http://callback/', + external_http_url='http://config.external.url', + group='deploy') + with task_manager.acquire(self.context, self.node.uuid, + shared=True) as task: + task.node.driver_info["external_http_url"] = \ + "https://node.external" + override_url = task.node.driver_info.get("external_http_url") + expected_url = '"https://node.external/c.f?e=f' + + mock_publish_image.return_value = expected_url + + url = image_utils.prepare_floppy_image(task) + + object_name = 'image-%s' % task.node.uuid + + mock_publish_image.assert_called_once_with( + mock.ANY, mock.ANY, object_name, override_url) mock_create_vfat_image.assert_called_once_with( mock.ANY, parameters={"ipa-api-url": "http://callback"}) |