From a5620d758605296348a7a01ce6f04d1208399310 Mon Sep 17 00:00:00 2001 From: Per Hallgren Date: Tue, 30 Sep 2025 11:33:12 +0200 Subject: [PATCH 1/2] fix(debian-ip): include all mapped options as valid options As reported in https://github.com/saltstack/salt/issues/58210 and https://github.com/saltstack/salt/issues/57820, not all options get rendered in the final `interfaces` file. The valid_opts list must be a superset of the keys of the optmap map for the mappted options to get rendered. This commit adds the missing options to the valid_opts list. --- changelog/58210.fixed.md | 1 + salt/templates/debian_ip/debian_eth.jinja | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 changelog/58210.fixed.md diff --git a/changelog/58210.fixed.md b/changelog/58210.fixed.md new file mode 100644 index 000000000000..917e204d17d3 --- /dev/null +++ b/changelog/58210.fixed.md @@ -0,0 +1 @@ +Render post/pre up/down and hwaddr options for debian-ip. See #58210 and #57820. diff --git a/salt/templates/debian_ip/debian_eth.jinja b/salt/templates/debian_ip/debian_eth.jinja index 87ada95467e0..60ebce4070d6 100644 --- a/salt/templates/debian_ip/debian_eth.jinja +++ b/salt/templates/debian_ip/debian_eth.jinja @@ -12,12 +12,13 @@ } -%} {% set concat_opts = ['dns_nameservers'] -%} {% set valid_opts = [ - 'autoconf', 'privext', 'dhcp', 'hwaddress', 'vlan_raw_device', 'address', 'addresses', 'netmask', + 'autoconf', 'privext', 'dhcp', 'hwaddress', 'hwaddr', 'vlan_raw_device', 'address', 'addresses', 'netmask', 'metric', 'gateway', 'pointopoint', 'scope', 'hostname', 'media', 'leasehours', 'leasetime', 'vendor', 'client', 'bootfile', 'server', 'mode', 'endpoint', 'dstaddr', 'local', 'ttl', 'mtu', 'provider', 'unit', 'options', 'master', 'dns_nameservers', 'wireless_mode', 'wpa_ap_scan', 'wpa_conf', 'wpa_driver', 'wpa_group', 'wpa_key_mgmt', 'wpa_pairwise', 'wpa_proto', 'wpa_psk', - 'wpa_roam', 'wpa_ssid', 'accept_ra' + 'wpa_roam', 'wpa_ssid', 'accept_ra', 'up_cmds', 'down_cmds', 'pre_up_cmds', 'post_up_cmds', + 'pre_down_cmds', 'post_down_cmds' ] -%} {% if data.enabled %}auto {{ name }} {% endif %}{% if data.hotplug %}allow-hotplug {{ name }} From 8c61b054d5867c39ff1ac268ae72c572dc3d7dc3 Mon Sep 17 00:00:00 2001 From: Per Hallgren Date: Tue, 30 Sep 2025 12:17:26 +0200 Subject: [PATCH 2/2] test(debian-ip): add tests for all valid_opts Tests that all mapped options are also in valid_opts. --- tests/pytests/unit/modules/test_debian_ip.py | 55 ++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/pytests/unit/modules/test_debian_ip.py b/tests/pytests/unit/modules/test_debian_ip.py index abbc0c61d8ec..74437ccb7b54 100644 --- a/tests/pytests/unit/modules/test_debian_ip.py +++ b/tests/pytests/unit/modules/test_debian_ip.py @@ -845,6 +845,61 @@ def test_interfaces(): ' gateway 2001:db8:dead:beef::1\n', ' accept_ra 2\n', '\n']}, + + # Command hooks + {'iface_name': 'eth_optmap_test', 'iface_type': 'eth', 'enabled': True, + 'build_interface': { + 'proto': 'manual', + 'up_cmds': ['echo "interface up"'], + 'down_cmds': ['echo "interface down"'], + 'pre_up_cmds': ['echo "pre-up"'], + 'post_up_cmds': ['echo "post-up"'], + 'pre_down_cmds': ['echo "pre-down"'], + 'post_down_cmds': ['echo "post-down"'], + }, + 'get_interface': odict([('eth_optmap_test', odict([('enabled', True), ('data', odict([ + ('inet', odict([ + ('addrfam', 'inet'), + ('proto', 'manual'), + ('filename', None), + ('up_cmds', ['echo "interface up"']), + ('down_cmds', ['echo "interface down"']), + ('pre_up_cmds', ['echo "pre-up"']), + ('post_up_cmds', ['echo "post-up"']), + ('pre_down_cmds', ['echo "pre-down"']), + ('post_down_cmds', ['echo "post-down"']), + ])), + ]))]))]), + 'return': [ + 'auto eth_optmap_test\n', + 'iface eth_optmap_test inet manual\n', + ' up echo "interface up"\n', + ' down echo "interface down"\n', + ' pre-up echo "pre-up"\n', + ' post-up echo "post-up"\n', + ' pre-down echo "pre-down"\n', + ' post-down echo "post-down"\n', + '\n']}, + + # hwaddr should map to hwaddress + {'iface_name': 'eth_hwaddr_test', 'iface_type': 'eth', 'enabled': True, + 'build_interface': { + 'proto': 'manual', + 'hwaddr': '00:11:22:33:44:55', + }, + 'get_interface': odict([('eth_hwaddr_test', odict([('enabled', True), ('data', odict([ + ('inet', odict([ + ('addrfam', 'inet'), + ('proto', 'manual'), + ('filename', None), + ('hwaddress', '00:11:22:33:44:55'), + ])), + ]))]))]), + 'return': [ + 'auto eth_hwaddr_test\n', + 'iface eth_hwaddr_test inet manual\n', + ' hwaddress 00:11:22:33:44:55\n', + '\n']}, ] # fmt: on