diff options
Diffstat (limited to 'ironic/tests/unit/drivers/modules')
4 files changed, 148 insertions, 85 deletions
diff --git a/ironic/tests/unit/drivers/modules/ilo/test_boot.py b/ironic/tests/unit/drivers/modules/ilo/test_boot.py index 8aa6f78da..8ebaa14fa 100644 --- a/ironic/tests/unit/drivers/modules/ilo/test_boot.py +++ b/ironic/tests/unit/drivers/modules/ilo/test_boot.py @@ -1132,6 +1132,45 @@ class IloPXEBootTestCase(test_common.BaseIloTest): self.assertIsNone(task.node.driver_internal_info.get( 'ilo_uefi_iscsi_boot')) + @mock.patch.object(ilo_boot, 'prepare_node_for_deploy', spec_set=True, + autospec=True) + @mock.patch.object(deploy_utils, 'get_boot_option', autospec=True) + @mock.patch.object(deploy_utils, 'is_iscsi_boot', + spec_set=True, autospec=True) + @mock.patch.object(boot_mode_utils, 'get_boot_mode_for_deploy', + spec_set=True, autospec=True) + @mock.patch.object(ilo_common, 'update_boot_mode', spec_set=True, + autospec=True) + @mock.patch.object(pxe.PXEBoot, 'prepare_instance', spec_set=True, + autospec=True) + def _test_prepare_instance_anaconda(self, pxe_prepare_instance_mock, + update_boot_mode_mock, + get_boot_mode_mock, + is_iscsi_boot_mock, + mock_get_boot_opt, + mock_prep_node_fr_deploy, prov_state): + with task_manager.acquire(self.context, self.node.uuid, + shared=False) as task: + task.node.provision_state = prov_state + mock_get_boot_opt.return_value = 'kickstart' + is_iscsi_boot_mock.return_value = False + get_boot_mode_mock.return_value = 'uefi' + task.driver.boot.prepare_instance(task) + update_boot_mode_mock.assert_called_once_with(task) + pxe_prepare_instance_mock.assert_called_once_with(mock.ANY, task) + self.assertIsNone(task.node.driver_internal_info.get( + 'ilo_uefi_iscsi_boot')) + mock_prep_node_fr_deploy.assert_called_once_with(task) + + def test_prepare_instance_anaconda_deploying(self): + self._test_prepare_instance_anaconda(prov_state=states.DEPLOYING) + + def test_prepare_instance_anaconda_rescuing(self): + self._test_prepare_instance_anaconda(prov_state=states.RESCUING) + + def test_prepare_instance_anaconda_cleaning(self): + self._test_prepare_instance_anaconda(prov_state=states.CLEANING) + @mock.patch.object(deploy_utils, 'is_iscsi_boot', spec_set=True, autospec=True) @mock.patch.object(boot_mode_utils, 'get_boot_mode_for_deploy', @@ -1299,6 +1338,45 @@ class IloiPXEBootTestCase(test_common.BaseIloTest): self.assertIsNone(task.node.driver_internal_info.get( 'ilo_uefi_iscsi_boot')) + @mock.patch.object(ilo_boot, 'prepare_node_for_deploy', spec_set=True, + autospec=True) + @mock.patch.object(deploy_utils, 'get_boot_option', autospec=True) + @mock.patch.object(deploy_utils, 'is_iscsi_boot', + spec_set=True, autospec=True) + @mock.patch.object(boot_mode_utils, 'get_boot_mode_for_deploy', + spec_set=True, autospec=True) + @mock.patch.object(ilo_common, 'update_boot_mode', spec_set=True, + autospec=True) + @mock.patch.object(ipxe.iPXEBoot, 'prepare_instance', spec_set=True, + autospec=True) + def _test_prepare_instance_anaconda(self, pxe_prepare_instance_mock, + update_boot_mode_mock, + get_boot_mode_mock, + is_iscsi_boot_mock, + mock_get_boot_opt, + mock_prep_node_fr_deploy, prov_state): + with task_manager.acquire(self.context, self.node.uuid, + shared=False) as task: + task.node.provision_state = prov_state + mock_get_boot_opt.return_value = 'kickstart' + is_iscsi_boot_mock.return_value = False + get_boot_mode_mock.return_value = 'uefi' + task.driver.boot.prepare_instance(task) + update_boot_mode_mock.assert_called_once_with(task) + pxe_prepare_instance_mock.assert_called_once_with(mock.ANY, task) + self.assertIsNone(task.node.driver_internal_info.get( + 'ilo_uefi_iscsi_boot')) + mock_prep_node_fr_deploy.assert_called_once_with(task) + + def test_prepare_instance_anaconda_deploying(self): + self._test_prepare_instance_anaconda(prov_state=states.DEPLOYING) + + def test_prepare_instance_anaconda_rescuing(self): + self._test_prepare_instance_anaconda(prov_state=states.RESCUING) + + def test_prepare_instance_anaconda_cleaning(self): + self._test_prepare_instance_anaconda(prov_state=states.CLEANING) + @mock.patch.object(deploy_utils, 'is_iscsi_boot', spec_set=True, autospec=True) @mock.patch.object(boot_mode_utils, 'get_boot_mode_for_deploy', diff --git a/ironic/tests/unit/drivers/modules/inspector/test_interface.py b/ironic/tests/unit/drivers/modules/inspector/test_interface.py index f4dbdd4b0..42bb55f2b 100644 --- a/ironic/tests/unit/drivers/modules/inspector/test_interface.py +++ b/ironic/tests/unit/drivers/modules/inspector/test_interface.py @@ -505,22 +505,24 @@ class CheckStatusTestCase(BaseTestCase): self.task) self.driver.boot.clean_up_ramdisk.assert_called_once_with(self.task) - @mock.patch.object(inspect_utils, 'store_introspection_data', - autospec=True) + @mock.patch.object(inspect_utils, 'store_inspection_data', autospec=True) def test_status_ok_store_inventory(self, mock_store_data, mock_client): mock_get = mock_client.return_value.get_introspection mock_get.return_value = mock.Mock(is_finished=True, error=None, spec=['is_finished', 'error']) - fake_introspection_data = { - "inventory": {"cpu": "amd"}, "disks": [{"name": "/dev/vda"}]} + fake_inventory = {"cpu": "amd"} + fake_plugin_data = {"disks": [{"name": "/dev/vda"}]} + fake_introspection_data = dict(fake_plugin_data, + inventory=fake_inventory) mock_get_data = mock_client.return_value.get_introspection_data mock_get_data.return_value = fake_introspection_data inspector._check_status(self.task) mock_get.assert_called_once_with(self.node.uuid) mock_get_data.assert_called_once_with(self.node.uuid, processed=True) mock_store_data.assert_called_once_with(self.node, - fake_introspection_data, + fake_inventory, + fake_plugin_data, self.task.context) def test_status_ok_store_inventory_nostore(self, mock_client): diff --git a/ironic/tests/unit/drivers/modules/test_inspect_utils.py b/ironic/tests/unit/drivers/modules/test_inspect_utils.py index 473b0ee7c..57980d5a2 100644 --- a/ironic/tests/unit/drivers/modules/test_inspect_utils.py +++ b/ironic/tests/unit/drivers/modules/test_inspect_utils.py @@ -103,7 +103,7 @@ class SwiftCleanUp(db_base.DbTestCase): @mock.patch.object(swift, 'SwiftAPI', autospec=True) def test_clean_up_swift_entries(self, swift_api_mock): CONF.set_override('data_backend', 'swift', group='inventory') - container = 'introspection_data' + container = 'inspection_data' CONF.set_override('swift_data_container', container, group='inventory') swift_obj_mock = swift_api_mock.return_value with task_manager.acquire(self.context, self.node.uuid, @@ -117,7 +117,7 @@ class SwiftCleanUp(db_base.DbTestCase): @mock.patch.object(swift, 'SwiftAPI', autospec=True) def test_clean_up_swift_entries_with_404_exception(self, swift_api_mock): CONF.set_override('data_backend', 'swift', group='inventory') - container = 'introspection_data' + container = 'inspection_data' CONF.set_override('swift_data_container', container, group='inventory') swift_obj_mock = swift_api_mock.return_value with task_manager.acquire(self.context, self.node.uuid, @@ -132,7 +132,7 @@ class SwiftCleanUp(db_base.DbTestCase): @mock.patch.object(swift, 'SwiftAPI', autospec=True) def test_clean_up_swift_entries_with_fail_exception(self, swift_api_mock): CONF.set_override('data_backend', 'swift', group='inventory') - container = 'introspection_data' + container = 'inspection_data' CONF.set_override('swift_data_container', container, group='inventory') swift_obj_mock = swift_api_mock.return_value with task_manager.acquire(self.context, self.node.uuid, @@ -148,7 +148,7 @@ class SwiftCleanUp(db_base.DbTestCase): @mock.patch.object(swift, 'SwiftAPI', autospec=True) def test_clean_up_swift_entries_with_fail_exceptions(self, swift_api_mock): CONF.set_override('data_backend', 'swift', group='inventory') - container = 'introspection_data' + container = 'inspection_data' CONF.set_override('swift_data_container', container, group='inventory') swift_obj_mock = swift_api_mock.return_value with task_manager.acquire(self.context, self.node.uuid, @@ -171,115 +171,93 @@ class IntrospectionDataStorageFunctionsTestCase(db_base.DbTestCase): super(IntrospectionDataStorageFunctionsTestCase, self).setUp() self.node = obj_utils.create_test_node(self.context) - def test_store_introspection_data_db(self): - CONF.set_override('data_backend', 'database', - group='inventory') - fake_introspection_data = {'inventory': self.fake_inventory_data, - **self.fake_plugin_data} + def test_store_inspection_data_db(self): + CONF.set_override('data_backend', 'database', group='inventory') fake_context = ironic_context.RequestContext() - utils.store_introspection_data(self.node, fake_introspection_data, - fake_context) + utils.store_inspection_data(self.node, self.fake_inventory_data, + self.fake_plugin_data, fake_context) stored = objects.NodeInventory.get_by_node_id(self.context, self.node.id) self.assertEqual(self.fake_inventory_data, stored["inventory_data"]) self.assertEqual(self.fake_plugin_data, stored["plugin_data"]) - @mock.patch.object(utils, '_store_introspection_data_in_swift', + @mock.patch.object(utils, '_store_inspection_data_in_swift', autospec=True) - def test_store_introspection_data_swift(self, mock_store_data): + def test_store_inspection_data_swift(self, mock_store_data): CONF.set_override('data_backend', 'swift', group='inventory') CONF.set_override( - 'swift_data_container', 'introspection_data', + 'swift_data_container', 'inspection_data', group='inventory') - fake_introspection_data = { - "inventory": self.fake_inventory_data, **self.fake_plugin_data} fake_context = ironic_context.RequestContext() - utils.store_introspection_data(self.node, fake_introspection_data, - fake_context) + utils.store_inspection_data(self.node, self.fake_inventory_data, + self.fake_plugin_data, fake_context) mock_store_data.assert_called_once_with( self.node.uuid, inventory_data=self.fake_inventory_data, plugin_data=self.fake_plugin_data) - def test_store_introspection_data_nostore(self): + def test_store_inspection_data_nostore(self): CONF.set_override('data_backend', 'none', group='inventory') - fake_introspection_data = { - "inventory": self.fake_inventory_data, **self.fake_plugin_data} fake_context = ironic_context.RequestContext() - ret = utils.store_introspection_data(self.node, - fake_introspection_data, - fake_context) - self.assertIsNone(ret) - - def test__node_inventory_convert(self): - required_output = {"inventory": self.fake_inventory_data, - "plugin_data": self.fake_plugin_data} - input_given = {} - input_given["inventory_data"] = self.fake_inventory_data - input_given["plugin_data"] = self.fake_plugin_data - input_given["booom"] = "boom" - ret = utils._node_inventory_convert(input_given) - self.assertEqual(required_output, ret) - - @mock.patch.object(utils, '_node_inventory_convert', autospec=True) - @mock.patch.object(objects, 'NodeInventory', spec_set=True, autospec=True) - def test_get_introspection_data_db(self, mock_inventory, mock_convert): - CONF.set_override('data_backend', 'database', - group='inventory') - fake_introspection_data = {'inventory': self.fake_inventory_data, - 'plugin_data': self.fake_plugin_data} + utils.store_inspection_data(self.node, self.fake_inventory_data, + self.fake_plugin_data, fake_context) + self.assertRaises(exception.NodeInventoryNotFound, + objects.NodeInventory.get_by_node_id, + self.context, self.node.id) + + def test_get_inspection_data_db(self): + CONF.set_override('data_backend', 'database', group='inventory') + obj_utils.create_test_inventory( + self.context, self.node, + inventory_data=self.fake_inventory_data, + plugin_data=self.fake_plugin_data) fake_context = ironic_context.RequestContext() - mock_inventory.get_by_node_id.return_value = fake_introspection_data - utils.get_introspection_data(self.node, fake_context) - mock_convert.assert_called_once_with(fake_introspection_data) - - @mock.patch.object(objects, 'NodeInventory', spec_set=True, autospec=True) - def test_get_introspection_data_db_exception(self, mock_inventory): - CONF.set_override('data_backend', 'database', - group='inventory') + ret = utils.get_inspection_data(self.node, fake_context) + fake_inspection_data = {'inventory': self.fake_inventory_data, + 'plugin_data': self.fake_plugin_data} + self.assertEqual(ret, fake_inspection_data) + + def test_get_inspection_data_db_exception(self): + CONF.set_override('data_backend', 'database', group='inventory') fake_context = ironic_context.RequestContext() - mock_inventory.get_by_node_id.side_effect = [ - exception.NodeInventoryNotFound(self.node.uuid)] self.assertRaises( - exception.NodeInventoryNotFound, utils.get_introspection_data, + exception.NodeInventoryNotFound, utils.get_inspection_data, self.node, fake_context) - @mock.patch.object(utils, '_get_introspection_data_from_swift', - autospec=True) - def test_get_introspection_data_swift(self, mock_get_data): + @mock.patch.object(utils, '_get_inspection_data_from_swift', autospec=True) + def test_get_inspection_data_swift(self, mock_get_data): CONF.set_override('data_backend', 'swift', group='inventory') CONF.set_override( - 'swift_data_container', 'introspection_data', + 'swift_data_container', 'inspection_data', group='inventory') fake_context = ironic_context.RequestContext() - utils.get_introspection_data(self.node, fake_context) - mock_get_data.assert_called_once_with( - self.node.uuid) + ret = utils.get_inspection_data(self.node, fake_context) + mock_get_data.assert_called_once_with(self.node.uuid) + self.assertEqual(mock_get_data.return_value, ret) - @mock.patch.object(utils, '_get_introspection_data_from_swift', - autospec=True) - def test_get_introspection_data_swift_exception(self, mock_get_data): + @mock.patch.object(utils, '_get_inspection_data_from_swift', autospec=True) + def test_get_inspection_data_swift_exception(self, mock_get_data): CONF.set_override('data_backend', 'swift', group='inventory') CONF.set_override( - 'swift_data_container', 'introspection_data', + 'swift_data_container', 'inspection_data', group='inventory') fake_context = ironic_context.RequestContext() mock_get_data.side_effect = exception.SwiftObjectNotFoundError() self.assertRaises( - exception.NodeInventoryNotFound, utils.get_introspection_data, + exception.NodeInventoryNotFound, utils.get_inspection_data, self.node, fake_context) - def test_get_introspection_data_nostore(self): + def test_get_inspection_data_nostore(self): CONF.set_override('data_backend', 'none', group='inventory') fake_context = ironic_context.RequestContext() self.assertRaises( - exception.NodeInventoryNotFound, utils.get_introspection_data, + exception.NodeInventoryNotFound, utils.get_inspection_data, self.node, fake_context) @mock.patch.object(swift, 'SwiftAPI', autospec=True) - def test__store_introspection_data_in_swift(self, swift_api_mock): - container = 'introspection_data' + def test__store_inspection_data_in_swift(self, swift_api_mock): + container = 'inspection_data' CONF.set_override('swift_data_container', container, group='inventory') - utils._store_introspection_data_in_swift( + utils._store_inspection_data_in_swift( self.node.uuid, self.fake_inventory_data, self.fake_plugin_data) swift_obj_mock = swift_api_mock.return_value object_name = 'inspector_data-' + str(self.node.uuid) @@ -290,23 +268,22 @@ class IntrospectionDataStorageFunctionsTestCase(db_base.DbTestCase): container)]) @mock.patch.object(swift, 'SwiftAPI', autospec=True) - def test__get_introspection_data_from_swift(self, swift_api_mock): - container = 'introspection_data' + def test__get_inspection_data_from_swift(self, swift_api_mock): + container = 'inspection_data' CONF.set_override('swift_data_container', container, group='inventory') swift_obj_mock = swift_api_mock.return_value swift_obj_mock.get_object.side_effect = [ self.fake_inventory_data, self.fake_plugin_data ] - ret = utils._get_introspection_data_from_swift(self.node.uuid) + ret = utils._get_inspection_data_from_swift(self.node.uuid) req_ret = {"inventory": self.fake_inventory_data, "plugin_data": self.fake_plugin_data} self.assertEqual(req_ret, ret) @mock.patch.object(swift, 'SwiftAPI', autospec=True) - def test__get_introspection_data_from_swift_exception(self, - swift_api_mock): - container = 'introspection_data' + def test__get_inspection_data_from_swift_exception(self, swift_api_mock): + container = 'inspection_data' CONF.set_override('swift_data_container', container, group='inventory') swift_obj_mock = swift_api_mock.return_value swift_obj_mock.get_object.side_effect = [ @@ -314,5 +291,5 @@ class IntrospectionDataStorageFunctionsTestCase(db_base.DbTestCase): self.fake_plugin_data ] self.assertRaises(exception.SwiftObjectNotFoundError, - utils._get_introspection_data_from_swift, + utils._get_inspection_data_from_swift, self.node.uuid) diff --git a/ironic/tests/unit/drivers/modules/test_pxe.py b/ironic/tests/unit/drivers/modules/test_pxe.py index e7d444104..f16366470 100644 --- a/ironic/tests/unit/drivers/modules/test_pxe.py +++ b/ironic/tests/unit/drivers/modules/test_pxe.py @@ -550,6 +550,8 @@ class PXEBootTestCase(db_base.DbTestCase): def test_prepare_instance_ramdisk_pxe_conf_exists(self): self._test_prepare_instance_ramdisk(config_file_exits=False) + @mock.patch.object(boot_mode_utils, 'configure_secure_boot_if_needed', + autospec=True) @mock.patch.object(manager_utils, 'node_set_boot_device', autospec=True) @mock.patch.object(deploy_utils, 'switch_pxe_config', autospec=True) @mock.patch.object(pxe_utils, 'create_pxe_config', autospec=True) @@ -567,7 +569,7 @@ class PXEBootTestCase(db_base.DbTestCase): self, exec_mock, write_file_mock, render_mock, api_url_mock, boot_opt_mock, get_image_info_mock, cache_mock, dhcp_factory_mock, create_pxe_config_mock, switch_pxe_config_mock, - set_boot_device_mock): + set_boot_device_mock, mock_conf_sec_boot): image_info = {'kernel': ['ins_kernel_id', '/path/to/kernel'], 'ramdisk': ['ins_ramdisk_id', '/path/to/ramdisk'], 'stage2': ['ins_stage2_id', '/path/to/stage2'], @@ -611,6 +613,7 @@ class PXEBootTestCase(db_base.DbTestCase): set_boot_device_mock.assert_called_once_with(task, boot_devices.PXE, persistent=True) + self.assertFalse(mock_conf_sec_boot.called) @mock.patch.object(manager_utils, 'node_set_boot_device', autospec=True) @mock.patch.object(deploy_utils, 'switch_pxe_config', autospec=True) @@ -786,11 +789,13 @@ class PXEAnacondaDeployTestCase(db_base.DbTestCase): task.driver.deploy.prepare(task) mock_prepare_instance.assert_called_once_with(mock.ANY, task) + @mock.patch.object(boot_mode_utils, 'configure_secure_boot_if_needed', + autospec=True) @mock.patch.object(pxe_utils, 'clean_up_pxe_env', autospec=True) @mock.patch.object(pxe_utils, 'get_instance_image_info', autospec=True) @mock.patch.object(deploy_utils, 'try_set_boot_device', autospec=True) def test_reboot_to_instance(self, mock_set_boot_dev, mock_image_info, - mock_cleanup_pxe_env): + mock_cleanup_pxe_env, mock_conf_sec_boot): image_info = {'kernel': ('', '/path/to/kernel'), 'ramdisk': ('', '/path/to/ramdisk'), 'stage2': ('', '/path/to/stage2'), @@ -802,6 +807,7 @@ class PXEAnacondaDeployTestCase(db_base.DbTestCase): with task_manager.acquire(self.context, self.node.uuid) as task: task.driver.deploy.reboot_to_instance(task) mock_set_boot_dev.assert_called_once_with(task, boot_devices.DISK) + mock_conf_sec_boot.assert_called_once_with(task) mock_cleanup_pxe_env.assert_called_once_with(task, image_info, ipxe_enabled=False) |