From 41f15dba65559a7132cb6e407ae169a2447d50e9 Mon Sep 17 00:00:00 2001 From: Armstrong Liu Date: Wed, 9 Sep 2020 09:47:27 +0800 Subject: [PATCH] clean up mac address with the pxe configuration files In pxe_utils.py/create_pxe_config function, mac pxe configs will always be created, so when we clear pxe configs, no matter whether the ip address is None or not, we need to clear them. Change-Id: I5cee9c4465630b162baf911ef9efef5f471671c0 Signed-off-by: Armstrong Liu --- ironic/common/pxe_utils.py | 2 -- ironic/tests/unit/common/test_pxe_utils.py | 27 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ironic/common/pxe_utils.py b/ironic/common/pxe_utils.py index 9f2ed500cb..2a78f0c3db 100644 --- a/ironic/common/pxe_utils.py +++ b/ironic/common/pxe_utils.py @@ -345,8 +345,6 @@ def clean_up_pxe_config(task, ipxe_enabled=False): if is_uefi_boot_mode and not ipxe_enabled: api = dhcp_factory.DHCPFactory().provider ip_addresses = api.get_ip_addresses(task) - if not ip_addresses: - return for port_ip_address in ip_addresses: try: diff --git a/ironic/tests/unit/common/test_pxe_utils.py b/ironic/tests/unit/common/test_pxe_utils.py index 987afb928e..76f7439161 100644 --- a/ironic/tests/unit/common/test_pxe_utils.py +++ b/ironic/tests/unit/common/test_pxe_utils.py @@ -874,6 +874,33 @@ class TestPXEUtils(db_base.DbTestCase): relpath = pxe_utils.get_path_relative_to_tftp_root(test_file_path) self.assertEqual(relpath, 'pxelinux.cfg/test') + @mock.patch('ironic.common.utils.rmtree_without_raise', autospec=True) + @mock.patch('ironic_lib.utils.unlink_without_raise', autospec=True) + @mock.patch('ironic.common.dhcp_factory.DHCPFactory.provider', + autospec=True) + def test_clean_up_pxe_config_uefi_no_ipaddress(self, provider_mock, + unlink_mock, + rmtree_mock): + address = "aa:aa:aa:aa:aa:aa" + properties = {'capabilities': 'boot_mode:uefi'} + object_utils.create_test_port(self.context, node_id=self.node.id, + address=address) + + provider_mock.get_ip_addresses.return_value = [] + + with task_manager.acquire(self.context, self.node.uuid) as task: + task.node.properties = properties + pxe_utils.clean_up_pxe_config(task) + + unlink_calls = [ + mock.call('/tftpboot/pxelinux.cfg/01-%s' % + address.replace(':', '-')), + mock.call('/tftpboot/aa:aa:aa:aa:aa:aa.conf') + ] + unlink_mock.assert_has_calls(unlink_calls) + rmtree_mock.assert_called_once_with( + os.path.join(CONF.pxe.tftp_root, self.node.uuid)) + @mock.patch.object(ipxe.iPXEBoot, '__init__', lambda self: None) @mock.patch.object(pxe.PXEBoot, '__init__', lambda self: None)