From ae7760af0fc39f3cf0edf5e6852fcd5c6ef5f830 Mon Sep 17 00:00:00 2001 From: Kaifeng Wang Date: Thu, 30 Mar 2023 23:51:25 +0800 Subject: [PATCH] Remove instance image after deployment Direct deploy interface with http source never removes instance image after deployment, which makes the image in the image cache referenced and unable to be cleaned up exceeds TTL. Change-Id: I3d8ee090007dc90b8868026ba24509719f81e4d7 --- ironic/drivers/modules/agent.py | 4 ++-- .../tests/unit/drivers/modules/test_agent.py | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ironic/drivers/modules/agent.py b/ironic/drivers/modules/agent.py index 1c0f5465e4..08e5555403 100644 --- a/ironic/drivers/modules/agent.py +++ b/ironic/drivers/modules/agent.py @@ -615,8 +615,8 @@ class AgentDeploy(CustomAgentDeploy): else: manager_utils.node_set_boot_device(task, 'disk', persistent=True) - # Remove symbolic link when deploy is done. - deploy_utils.remove_http_instance_symlink(task.node.uuid) + # Remove symbolic link and image when deploy is done. + deploy_utils.destroy_http_instance_images(task.node) class AgentRAID(base.RAIDInterface): diff --git a/ironic/tests/unit/drivers/modules/test_agent.py b/ironic/tests/unit/drivers/modules/test_agent.py index 653359f33d..79b8af92f9 100644 --- a/ironic/tests/unit/drivers/modules/test_agent.py +++ b/ironic/tests/unit/drivers/modules/test_agent.py @@ -1370,7 +1370,7 @@ class TestAgentDeploy(CommonTestsMixin, db_base.DbTestCase): mock_build_configdrive.assert_called_once_with( task.node, {'meta_data': {}}) - @mock.patch.object(deploy_utils, 'remove_http_instance_symlink', + @mock.patch.object(deploy_utils, 'destroy_http_instance_images', autospec=True) @mock.patch.object(agent.LOG, 'warning', spec_set=True, autospec=True) @mock.patch.object(agent_client.AgentClient, 'get_partition_uuids', @@ -1378,7 +1378,7 @@ class TestAgentDeploy(CommonTestsMixin, db_base.DbTestCase): @mock.patch.object(agent.AgentDeploy, 'prepare_instance_to_boot', autospec=True) def test_prepare_instance_boot(self, prepare_instance_mock, - uuid_mock, log_mock, remove_symlink_mock): + uuid_mock, log_mock, destroy_image_mock): self.config(manage_agent_boot=True, group='agent') self.config(image_download_source='http', group='agent') uuid_mock.return_value = {} @@ -1397,8 +1397,9 @@ class TestAgentDeploy(CommonTestsMixin, db_base.DbTestCase): None, None, None) self.assertEqual(states.DEPLOYING, task.node.provision_state) self.assertEqual(states.ACTIVE, task.node.target_provision_state) - self.assertTrue(remove_symlink_mock.called) + destroy_image_mock.assert_called_once_with(task.node) + @mock.patch.object(deploy_utils, 'destroy_images', autospec=True) @mock.patch.object(agent.LOG, 'warning', spec_set=True, autospec=True) @mock.patch.object(manager_utils, 'node_set_boot_device', autospec=True) @mock.patch.object(agent_client.AgentClient, 'get_partition_uuids', @@ -1407,7 +1408,7 @@ class TestAgentDeploy(CommonTestsMixin, db_base.DbTestCase): autospec=True) def test_prepare_instance_boot_no_manage_agent_boot( self, prepare_instance_mock, uuid_mock, - bootdev_mock, log_mock): + bootdev_mock, log_mock, destroy_image_mock): self.config(manage_agent_boot=False, group='agent') uuid_mock.return_value = {} self.node.provision_state = states.DEPLOYING @@ -1426,6 +1427,7 @@ class TestAgentDeploy(CommonTestsMixin, db_base.DbTestCase): self.assertEqual(states.DEPLOYING, task.node.provision_state) self.assertEqual(states.ACTIVE, task.node.target_provision_state) + @mock.patch.object(deploy_utils, 'destroy_images', autospec=True) @mock.patch.object(agent.LOG, 'warning', spec_set=True, autospec=True) @mock.patch.object(boot_mode_utils, 'get_boot_mode_for_deploy', autospec=True) @@ -1435,7 +1437,8 @@ class TestAgentDeploy(CommonTestsMixin, db_base.DbTestCase): autospec=True) def test_prepare_instance_boot_partition_image(self, prepare_instance_mock, uuid_mock, boot_mode_mock, - log_mock): + log_mock, + destroy_image_mock): uuid_mock.return_value = { 'command_result': {'root uuid': 'root_uuid'} } @@ -1462,6 +1465,7 @@ class TestAgentDeploy(CommonTestsMixin, db_base.DbTestCase): self.assertEqual(states.DEPLOYING, task.node.provision_state) self.assertEqual(states.ACTIVE, task.node.target_provision_state) + @mock.patch.object(deploy_utils, 'destroy_images', autospec=True) @mock.patch.object(agent.LOG, 'warning', spec_set=True, autospec=True) @mock.patch.object(boot_mode_utils, 'get_boot_mode_for_deploy', autospec=True) @@ -1471,7 +1475,7 @@ class TestAgentDeploy(CommonTestsMixin, db_base.DbTestCase): autospec=True) def test_prepare_instance_boot_partition_localboot_ppc64( self, prepare_instance_mock, - uuid_mock, boot_mode_mock, log_mock): + uuid_mock, boot_mode_mock, log_mock, destroy_image_mock): uuid_mock.return_value = { 'command_result': { 'root uuid': 'root_uuid', @@ -1506,6 +1510,7 @@ class TestAgentDeploy(CommonTestsMixin, db_base.DbTestCase): self.assertEqual(states.DEPLOYING, task.node.provision_state) self.assertEqual(states.ACTIVE, task.node.target_provision_state) + @mock.patch.object(deploy_utils, 'destroy_images', autospec=True) @mock.patch.object(agent.LOG, 'warning', spec_set=True, autospec=True) @mock.patch.object(boot_mode_utils, 'get_boot_mode_for_deploy', autospec=True) @@ -1515,7 +1520,7 @@ class TestAgentDeploy(CommonTestsMixin, db_base.DbTestCase): autospec=True) def test_prepare_instance_boot_localboot(self, prepare_instance_mock, uuid_mock, boot_mode_mock, - log_mock): + log_mock, destroy_image_mock): uuid_mock.return_value = { 'command_result': { 'root uuid': 'root_uuid',