summaryrefslogtreecommitdiff
path: root/ironic/tests/unit/drivers/modules/test_image_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'ironic/tests/unit/drivers/modules/test_image_utils.py')
-rw-r--r--ironic/tests/unit/drivers/modules/test_image_utils.py89
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"})