update grub2 file name

Some higher versions of grub2 (e.g. 2.05 or 2.06-rc1) use
grub.cfg-01-MAC, while another lower versions of
grub2 (e.g. 2.04) use MAC.conf, so we generate both paths
in order to be compatible with both.

For more information we can see:
https://docs.oracle.com/en/operating-systems/oracle-linux/7/install/ol7-install-prepare.html#ol7-install-pxe-boot-uefi

Change-Id: Icbdd284de38b8e54c52cdbba709bba0e644c35cd
Signed-off-by: Armstrong Liu <vpbvmw651078@gmail.com>
(cherry picked from commit 8f474bfe59)
This commit is contained in:
Armstrong Liu 2021-03-15 15:58:40 +08:00 committed by liuzhuangzhuang
parent 4df73e47e1
commit 54376836ee
3 changed files with 48 additions and 5 deletions

View File

@ -112,8 +112,9 @@ def _link_mac_pxe_configs(task, ipxe_enabled=False):
create_link(_get_pxe_mac_path(port.address, client_id=client_id, create_link(_get_pxe_mac_path(port.address, client_id=client_id,
ipxe_enabled=ipxe_enabled)) ipxe_enabled=ipxe_enabled))
# Grub2 MAC address only # Grub2 MAC address only
create_link(_get_pxe_grub_mac_path(port.address, for path in _get_pxe_grub_mac_path(port.address,
ipxe_enabled=ipxe_enabled)) ipxe_enabled=ipxe_enabled):
create_link(path)
def _link_ip_address_pxe_configs(task, ipxe_enabled=False): def _link_ip_address_pxe_configs(task, ipxe_enabled=False):
@ -156,7 +157,9 @@ def _link_ip_address_pxe_configs(task, ipxe_enabled=False):
def _get_pxe_grub_mac_path(mac, ipxe_enabled=False): def _get_pxe_grub_mac_path(mac, ipxe_enabled=False):
root_dir = get_ipxe_root_dir() if ipxe_enabled else get_root_dir() root_dir = get_ipxe_root_dir() if ipxe_enabled else get_root_dir()
return os.path.join(root_dir, mac + '.conf') yield os.path.join(root_dir, "%s-%s-%s" %
("grub.cfg", "01", mac.replace(':', "-").lower()))
yield os.path.join(root_dir, mac + '.conf')
def _get_pxe_mac_path(mac, delimiter='-', client_id=None, def _get_pxe_mac_path(mac, delimiter='-', client_id=None,
@ -361,8 +364,9 @@ def clean_up_pxe_config(task, ipxe_enabled=False):
_get_pxe_mac_path(port.address, client_id=client_id, _get_pxe_mac_path(port.address, client_id=client_id,
ipxe_enabled=ipxe_enabled)) ipxe_enabled=ipxe_enabled))
# Grub2 MAC address based confiuration # Grub2 MAC address based confiuration
ironic_utils.unlink_without_raise( for path in _get_pxe_grub_mac_path(port.address,
_get_pxe_grub_mac_path(port.address, ipxe_enabled=ipxe_enabled)) ipxe_enabled=ipxe_enabled):
ironic_utils.unlink_without_raise(path)
if ipxe_enabled: if ipxe_enabled:
utils.rmtree_without_raise(os.path.join(get_ipxe_root_dir(), utils.rmtree_without_raise(os.path.join(get_ipxe_root_dir(),
task.node.uuid)) task.node.uuid))

View File

@ -246,17 +246,23 @@ class TestPXEUtils(db_base.DbTestCase):
create_link_calls = [ create_link_calls = [
mock.call(u'../1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config', mock.call(u'../1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config',
'/tftpboot/pxelinux.cfg/01-11-22-33-44-55-66'), '/tftpboot/pxelinux.cfg/01-11-22-33-44-55-66'),
mock.call(u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config',
'/tftpboot/grub.cfg-01-11-22-33-44-55-66'),
mock.call(u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config', mock.call(u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config',
'/tftpboot/11:22:33:44:55:66.conf'), '/tftpboot/11:22:33:44:55:66.conf'),
mock.call(u'../1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config', mock.call(u'../1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config',
'/tftpboot/pxelinux.cfg/01-11-22-33-44-55-67'), '/tftpboot/pxelinux.cfg/01-11-22-33-44-55-67'),
mock.call(u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config',
'/tftpboot/grub.cfg-01-11-22-33-44-55-67'),
mock.call(u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config', mock.call(u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config',
'/tftpboot/11:22:33:44:55:67.conf') '/tftpboot/11:22:33:44:55:67.conf')
] ]
unlink_calls = [ unlink_calls = [
mock.call('/tftpboot/pxelinux.cfg/01-11-22-33-44-55-66'), mock.call('/tftpboot/pxelinux.cfg/01-11-22-33-44-55-66'),
mock.call('/tftpboot/grub.cfg-01-11-22-33-44-55-66'),
mock.call('/tftpboot/11:22:33:44:55:66.conf'), mock.call('/tftpboot/11:22:33:44:55:66.conf'),
mock.call('/tftpboot/pxelinux.cfg/01-11-22-33-44-55-67'), mock.call('/tftpboot/pxelinux.cfg/01-11-22-33-44-55-67'),
mock.call('/tftpboot/grub.cfg-01-11-22-33-44-55-67'),
mock.call('/tftpboot/11:22:33:44:55:67.conf') mock.call('/tftpboot/11:22:33:44:55:67.conf')
] ]
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
@ -285,17 +291,23 @@ class TestPXEUtils(db_base.DbTestCase):
create_link_calls = [ create_link_calls = [
mock.call(u'../1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config', mock.call(u'../1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config',
'/tftpboot/pxelinux.cfg/20-11-22-33-44-55-66'), '/tftpboot/pxelinux.cfg/20-11-22-33-44-55-66'),
mock.call(u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config',
'/tftpboot/grub.cfg-01-11-22-33-44-55-66'),
mock.call(u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config', mock.call(u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config',
'/tftpboot/11:22:33:44:55:66.conf'), '/tftpboot/11:22:33:44:55:66.conf'),
mock.call(u'../1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config', mock.call(u'../1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config',
'/tftpboot/pxelinux.cfg/20-11-22-33-44-55-67'), '/tftpboot/pxelinux.cfg/20-11-22-33-44-55-67'),
mock.call(u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config',
'/tftpboot/grub.cfg-01-11-22-33-44-55-67'),
mock.call(u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config', mock.call(u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config',
'/tftpboot/11:22:33:44:55:67.conf') '/tftpboot/11:22:33:44:55:67.conf')
] ]
unlink_calls = [ unlink_calls = [
mock.call('/tftpboot/pxelinux.cfg/20-11-22-33-44-55-66'), mock.call('/tftpboot/pxelinux.cfg/20-11-22-33-44-55-66'),
mock.call('/tftpboot/grub.cfg-01-11-22-33-44-55-66'),
mock.call('/tftpboot/11:22:33:44:55:66.conf'), mock.call('/tftpboot/11:22:33:44:55:66.conf'),
mock.call('/tftpboot/pxelinux.cfg/20-11-22-33-44-55-67'), mock.call('/tftpboot/pxelinux.cfg/20-11-22-33-44-55-67'),
mock.call('/tftpboot/grub.cfg-01-11-22-33-44-55-67'),
mock.call('/tftpboot/11:22:33:44:55:67.conf') mock.call('/tftpboot/11:22:33:44:55:67.conf')
] ]
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
@ -317,17 +329,23 @@ class TestPXEUtils(db_base.DbTestCase):
create_link_calls = [ create_link_calls = [
mock.call(u'../1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config', mock.call(u'../1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config',
'/httpboot/pxelinux.cfg/11-22-33-44-55-66'), '/httpboot/pxelinux.cfg/11-22-33-44-55-66'),
mock.call(u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config',
'/httpboot/grub.cfg-01-11-22-33-44-55-66'),
mock.call(u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config', mock.call(u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config',
'/httpboot/11:22:33:44:55:66.conf'), '/httpboot/11:22:33:44:55:66.conf'),
mock.call(u'../1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config', mock.call(u'../1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config',
'/httpboot/pxelinux.cfg/11-22-33-44-55-67'), '/httpboot/pxelinux.cfg/11-22-33-44-55-67'),
mock.call(u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config',
'/httpboot/grub.cfg-01-11-22-33-44-55-67'),
mock.call(u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config', mock.call(u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123/config',
'/httpboot/11:22:33:44:55:67.conf') '/httpboot/11:22:33:44:55:67.conf')
] ]
unlink_calls = [ unlink_calls = [
mock.call('/httpboot/pxelinux.cfg/11-22-33-44-55-66'), mock.call('/httpboot/pxelinux.cfg/11-22-33-44-55-66'),
mock.call('/httpboot/grub.cfg-01-11-22-33-44-55-66'),
mock.call('/httpboot/11:22:33:44:55:66.conf'), mock.call('/httpboot/11:22:33:44:55:66.conf'),
mock.call('/httpboot/pxelinux.cfg/11-22-33-44-55-67'), mock.call('/httpboot/pxelinux.cfg/11-22-33-44-55-67'),
mock.call('/httpboot/grub.cfg-01-11-22-33-44-55-67'),
mock.call('/httpboot/11:22:33:44:55:67.conf'), mock.call('/httpboot/11:22:33:44:55:67.conf'),
] ]
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
@ -562,6 +580,7 @@ class TestPXEUtils(db_base.DbTestCase):
ensure_calls = [ ensure_calls = [
mock.call("/tftpboot/pxelinux.cfg/01-%s" mock.call("/tftpboot/pxelinux.cfg/01-%s"
% address.replace(':', '-')), % address.replace(':', '-')),
mock.call("/tftpboot/grub.cfg-01-aa-aa-aa-aa-aa-aa"),
mock.call("/tftpboot/%s.conf" % address) mock.call("/tftpboot/%s.conf" % address)
] ]
@ -759,6 +778,7 @@ class TestPXEUtils(db_base.DbTestCase):
unlink_calls = [ unlink_calls = [
mock.call('/tftpboot/10.10.0.1.conf'), mock.call('/tftpboot/10.10.0.1.conf'),
mock.call('/tftpboot/pxelinux.cfg/01-aa-aa-aa-aa-aa-aa'), mock.call('/tftpboot/pxelinux.cfg/01-aa-aa-aa-aa-aa-aa'),
mock.call('/tftpboot/grub.cfg-01-aa-aa-aa-aa-aa-aa'),
mock.call('/tftpboot/' + address + '.conf') mock.call('/tftpboot/' + address + '.conf')
] ]
unlink_mock.assert_has_calls(unlink_calls) unlink_mock.assert_has_calls(unlink_calls)
@ -787,6 +807,7 @@ class TestPXEUtils(db_base.DbTestCase):
mock.call('/tftpboot/10.10.0.1.conf'), mock.call('/tftpboot/10.10.0.1.conf'),
mock.call('/tftpboot/pxelinux.cfg/01-%s' % mock.call('/tftpboot/pxelinux.cfg/01-%s' %
address.replace(':', '-')), address.replace(':', '-')),
mock.call('/tftpboot/grub.cfg-01-aa-aa-aa-aa-aa-aa'),
mock.call('/tftpboot/' + address + '.conf') mock.call('/tftpboot/' + address + '.conf')
] ]
@ -815,6 +836,7 @@ class TestPXEUtils(db_base.DbTestCase):
unlink_calls = [ unlink_calls = [
mock.call('/tftpboot/10.10.0.1.conf'), mock.call('/tftpboot/10.10.0.1.conf'),
mock.call('/tftpboot/pxelinux.cfg/01-aa-aa-aa-aa-aa-aa'), mock.call('/tftpboot/pxelinux.cfg/01-aa-aa-aa-aa-aa-aa'),
mock.call('/tftpboot/grub.cfg-01-aa-aa-aa-aa-aa-aa'),
mock.call('/tftpboot/' + address + ".conf") mock.call('/tftpboot/' + address + ".conf")
] ]
unlink_mock.assert_has_calls(unlink_calls) unlink_mock.assert_has_calls(unlink_calls)
@ -864,12 +886,21 @@ class TestPXEUtils(db_base.DbTestCase):
unlink_calls = [ unlink_calls = [
mock.call('/tftpboot/pxelinux.cfg/01-%s' % mock.call('/tftpboot/pxelinux.cfg/01-%s' %
address.replace(':', '-')), address.replace(':', '-')),
mock.call('/tftpboot/grub.cfg-01-aa-aa-aa-aa-aa-aa'),
mock.call('/tftpboot/aa:aa:aa:aa:aa:aa.conf') mock.call('/tftpboot/aa:aa:aa:aa:aa:aa.conf')
] ]
unlink_mock.assert_has_calls(unlink_calls) unlink_mock.assert_has_calls(unlink_calls)
rmtree_mock.assert_called_once_with( rmtree_mock.assert_called_once_with(
os.path.join(CONF.pxe.tftp_root, self.node.uuid)) os.path.join(CONF.pxe.tftp_root, self.node.uuid))
def test__get_pxe_grub_mac_path(self):
self.config(tftp_root='/tftpboot-path/', group='pxe')
address = "aa:aa:aa:aa:aa:aa"
actual = pxe_utils._get_pxe_grub_mac_path(address)
self.assertEqual('/tftpboot-path/grub.cfg-01-aa-aa-aa-aa-aa-aa',
next(actual))
self.assertEqual('/tftpboot-path/' + address + '.conf', next(actual))
@mock.patch.object(ipxe.iPXEBoot, '__init__', lambda self: None) @mock.patch.object(ipxe.iPXEBoot, '__init__', lambda self: None)
@mock.patch.object(pxe.PXEBoot, '__init__', lambda self: None) @mock.patch.object(pxe.PXEBoot, '__init__', lambda self: None)
@ -1751,6 +1782,7 @@ class iPXEBuildConfigOptionsTestCase(db_base.DbTestCase):
ensure_calls = [ ensure_calls = [
mock.call("/httpboot/pxelinux.cfg/%s" mock.call("/httpboot/pxelinux.cfg/%s"
% address.replace(':', '-')), % address.replace(':', '-')),
mock.call("/httpboot/grub.cfg-01-aa-aa-aa-aa-aa-aa"),
mock.call("/httpboot/%s.conf" % address) mock.call("/httpboot/%s.conf" % address)
] ]

View File

@ -0,0 +1,7 @@
---
fixes:
- |
Fixes the problem about grub2 config file. Some higher versions of
grub2 (e.g. 2.05 or 2.06-rc1) use grub.cfg-01-MAC, while another
lower versions of grub2 (e.g. 2.04) use MAC.conf, so we generate
both paths in order to be compatible with both.