Nic managed hooks not all queued

Problem:
When the host has multiple managed nics, it is expected that the data given to the nic/managed/destroy script would be an array or be called multiple times (once for each managed interface)

Based on some initial testing, only one (last?) managed nic is passed to the hook. this prevents actions from being taken on each managed nic.

Expected outcome:

either an array or multiple hook events would be queued

Foreman and Proxy versions:
3.9.1
alma 8
puppet 7


looking at possible work arounds using a before destroy event on the host where the nics can be iterated.

Adding some logs

2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on mac 52:54:00:76:1a:c8
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on ip 10.255.201.216
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on type Nic::Managed
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on name 
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on host_id 2156
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on subnet_id 
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on domain_id 
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on attrs {"bindings"=>[{"address"=>"10.255.201.216", "netmask"=>"255.255.255.0", "network"=>"10.255.201.0"}], "bindings6"=>[{"address"=>"fe80::39e9:6c93:54ba:c3ad", "netmask"=>"ffff:ffff:ffff:ffff::", "network"=>"fe80::", "scope6"=>"link", "flags"=>["permanent"]}], "dhcp"=>"10.255.201.1", "duplex"=>"full", "mtu"=>1500, "netmask"=>"255.255.255.0", "netmask6"=>"ffff:ffff:ffff:ffff::", "network"=>"10.255.201.0", "network6"=>"fe80::", "operational_state"=>"up", "physical"=>true, "scope6"=>"link", "speed"=>100}
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on provider 
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on username 
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on password [redacted]
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on virtual false
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on link true
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on identifier ens1
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on tag 
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on attached_to 
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on managed false
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on mode balance-rr
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on attached_devices 
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on bond_options 
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on primary false
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on provision false
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on compute_attributes {}
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on ip6 
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on subnet6_id 
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18947) destroy event on execution false
2024-01-13T03:24:52 [D|app|08e79479] Observed destroy hook on 
2024-01-13T03:24:52 [D|app|08e79479] Queuing 1 hooks for Nic::Managed#destroy
2024-01-13T03:24:52 [D|app|08e79479] Queuing hook /usr/share/foreman/config/hooks/nic/managed/destroy/0010_dhcp_reservation.py for Nic::Managed#destroy at priority 0010
2024-01-13T03:24:52 [D|app|08e79479] Enqueued task 'Hook: /usr/share/foreman/config/hooks/nic/managed/destroy/0010_dhcp_reservation.py' to 'Host::Managed Main' queue
2024-01-13T03:24:52 [D|app|08e79479] Processing task 'Hook: /usr/share/foreman/config/hooks/nic/managed/destroy/0010_dhcp_reservation.py' from 'Host::Managed Main'
2024-01-13T03:24:52 [D|app|08e79479] Running hook: /usr/share/foreman/config/hooks/nic/managed/destroy/0010_dhcp_reservation.py destroy 
2024-01-13T03:24:52 [W|app|08e79479] Unable to render  (Nic::Managed) using RABL: Cannot find rabl template 'api/v2/nic/manageds/show' within registered (["/usr/share/foreman/app/views", "/usr/share/gems/gems/foreman_puppet-6.1.1/app/views", "/usr/share/gems/gems/foreman_setup-8.0.1/app/views", "/usr/share/gems/gems/foreman_remote_execution-12.0.2/app/views", "/usr/share/gems/gems/foreman_discovery-23.0.0/app/views", "/usr/share/gems/gems/foreman-tasks-9.0.0/app/views", "/usr/share/gems/gems/foreman_templates-9.4.0/app/views", "/usr/share/gems/gems/apipie-dsl-2.6.1/app/views", "/usr/share/gems/gems/apipie-rails-1.2.3/app/views", "/usr/share/foreman/app/views", "/usr/share/gems/gems/foreman_templates-9.4.0/app/views", "/usr/share/gems/gems/foreman_discovery-23.0.0/app/views"]) view paths!
...
2024-01-13T03:24:52 [D|app|08e79479] Hook output: running usr/share/foreman/config/hooks/nic/managed/destroy/0010_dhcp_reservation.py destroy
 08e79479 | checking host None interface ens1 with ip 10.255.201.216 for reservation
 08e79479 | {'id': 18947, 'mac': '52:54:00:76:1a:c8', 'ip': '10.255.201.216', 'name': None, 'host_id': 2156, 'subnet_id': None, 'domain_id': None, 'attrs': {'bindings': [{'address': '10.255.201.216', 'netmask': '255.255.255.0', 'network': '10.255.201.0'}], 'bindings6': [{'address': 'fe80::39e9:6c93:54ba:c3ad', 'netmask': 'ffff:ffff:ffff:ffff::', 'network': 'fe80::', 'scope6': 'link', 'flags': ['permanent']}], 'dhcp': '10.255.201.1', 'duplex': 'full', 'mtu': 1500, 'netmask': '255.255.255.0', 'netmask6': 'ffff:ffff:ffff:ffff::', 'network': '10.255.201.0', 'network6': 'fe80::', 'operational_state': 'up', 'physical': True, 'scope6': 'link', 'speed': 100}, 'created_at': '2024-01-12T22:24:26.922-05:00', 'updated_at': '2024-01-12T22:24:26.922-05:00', 'provider': None, 'username': None, 'password': None, 'virtual': False, 'link': True, 'identifier': 'ens1', 'tag': '', 'attached_to': '', 'managed': False, 'mode': 'balance-rr', 'attached_devices': '', 'bond_options': '', 'primary': False, 'provision': False, 'compute_attributes': {}, 'ip6': None, 'subnet6_id': None, 'execution': False}
 08e79479 | completed usr/share/foreman/config/hooks/nic/managed/destroy/0010_dhcp_reservation.py
 08e79479 | 
2024-01-13T03:24:52 [I|app|08e79479] Processed 1 tasks from queue 'Host::Managed Main', completed 1/1
2024-01-13T03:24:52 [D|app|08e79479] Task 'Hook: /usr/share/foreman/config/hooks/nic/managed/destroy/0010_dhcp_reservation.py' *completed*
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on mac 52:54:00:93:ff:5c
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on ip 10.255.201.206
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on type Nic::Managed
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on name validate-0016.<validate>
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on host_id 2156
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on subnet_id 127
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on domain_id 51
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on attrs {"bindings"=>[{"address"=>"10.255.201.206", "netmask"=>"255.255.255.0", "network"=>"10.255.201.0"}], "bindings6"=>[{"address"=>"fe80::5054:ff:fe93:ff5c", "netmask"=>"ffff:ffff:ffff:ffff::", "network"=>"fe80::", "scope6"=>"link", "flags"=>["permanent"]}], "dhcp"=>"10.255.201.1", "mtu"=>1500, "netmask"=>"255.255.255.0", "netmask6"=>"ffff:ffff:ffff:ffff::", "network"=>"10.255.201.0", "network6"=>"fe80::", "operational_state"=>"up", "physical"=>true, "scope6"=>"link"}
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on provider 
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on username 
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on password [redacted]
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on virtual false
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on link true
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on identifier eth0
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on tag 
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on attached_to 
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on managed true
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on mode balance-rr
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on attached_devices 
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on bond_options 
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on primary true
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on provision true
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on compute_attributes {"type"=>"bridge", "bridge"=>"br-vm-mgmt", "model"=>"virtio"}
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on ip6 
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on subnet6_id 
2024-01-13T03:24:52 [I|aud|08e79479] Nic::Managed (18944) destroy event on execution true
2024-01-13T03:24:52 [D|app|08e79479] Observed destroy hook on validate-0016.<redacted>
2024-01-13T03:24:52 [D|app|08e79479] Queuing 1 hooks for Nic::Managed#destroy
2024-01-13T03:24:52 [D|app|08e79479] Queuing hook /usr/share/foreman/config/hooks/nic/managed/destroy/0010_dhcp_reservation.py for Nic::Managed#destroy at priority 0010
2024-01-13T03:24:52 [D|app|08e79479] Task 'Hook: /usr/share/foreman/config/hooks/nic/managed/destroy/0010_dhcp_reservation.py' already in 'Host::Managed Main' queue

@ofedoren

Hi @bmagistro,

Sorry I didn’t respond earlier.

It seems you have pretty up-to-date Foreman instance. Could you please consider switching to foreman_webhooks instead of foreman_hooks? If you need to run local scripts, you can use shellhooks plugin for smart-proxy to integrate with webhooks.

foreman_hooks plugin is considered obsolete and we’re going to fully drop support for it anyway.

I don’t think we ever noticed a deprecation notice for hooks. As for migrating, everything would be shellhooks as its running powershell to interact with AD services so would take some effort. Is there a timeline for deprecating and removing the hooks?

While I am aware of both plugins from other sources, they are not listed on either of these pages while hooks are still listed. If they should not be used I would expect it to be harder to find and the suggested replacements more prominent.

https://theforeman.org/plugins/

Regarding the list of plugins, there is 1.2 entry on the page, which has a link to up-to-date list of plugins.

cc @aruzicka, can have more inputs regarding the timeline.

The bad news is, all the packaging, installer and puppet PRs have been merged so they’ll be gone in 3.11.

However, considering how little the plugin changed in the last years, chances are that you would be able to install it from rubygems and it should continue working. In general I’d suggest migrating to the new way if possible, but this could give you some extra breathing space.

I don’t think we ever noticed a deprecation notice for hooks.
If they should not be used I would expect it to be harder to find and the suggested replacements more prominent.

I’m afraid we might have dropped the ball on this one and I’m sorry about it. We’ve been trying to get rid of it since around Foreman 2.1, but kept running into things which were possible with hooks but not with webhooks+shellhooks.

Around Foreman 2.5 we added a “Migrating to webhooks” section in the docs that describes how to migrate from the old plugin to the new one. This section calls the old plugin “legacy”, which is not a proper deprecation, but at least it hints towards it.

Now, we finally concluded that we resolved all the blockers that were known to us and went ahead with the removal of the old plugin.

I can’t really speak to the state of these, in general I’d trust the new documentation living on docs.theforeman.org, which doesn’t mention hooks in any other context than migrating away from them.

1 Like

Appreciate the detailed reply and will start tracking it as a blocker for us. I do know we are eagerly awaiting 3.11 so we can shift off alma 8 here and have a consistent OS with the majority of our systems.

1 Like