Foreman 1.20 / Host creation fails to provision dhcp entry

Much nicer.
How about this function ?
def generate_id(interface,action)
return “dhcp_#{action}_#{[interface.mac, self.ip, interface.identifier,interface.id].find{|x| x&.present?}}”
end

Better but what do you need interface for? This is executed in NIC context, so you just use self.identifier or simply identifier.

I tried to make something like that:
def generate_id(action) return "dhcp_#{action}_#{[self.mac, self.ip, self.identifier, self.id].find{|x| x&.present?}}" end
Foremans barfs about the method generate_id not defined for Object Managed::Nic

Maybe what I can do is create a method for managed::nic that returns the correct ID and use it in Orchestration::DHCP

In app/models/nic add:

def unique_id
[self.mac, self.ip, self.identifier, self.id].find{|x| x&.present?}
end

And use it in dhcp.rd:

queue.create(id: "dhcp_create_#{self.unique_id))…

Or

def generate_unique_id(interface,action)
return “dhcp_#{action}_#{interface.unique_id}”
end
queue.create(id: generate_unique_id(self,“create”)…

Either way, the generate unique id belongs to ochestration:dhcp not nic:managed

Let me do the patch for you.

https://github.com/theforeman/foreman/pull/6498

1 Like

host deletetion does not work:
La tâche Suppression des paramètres DHCP pour sadie-hages-svg0.domain.local a échoué avec l'erreur suivante : undefined methoddhcp_record_type’ for #Redhat:0x0000000006d84d60
| NoMethodError: undefined method dhcp_record_type' for #<Redhat:0x0000000006d84d60> | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activemodel-5.2.1/lib/active_model/attribute_methods.rb:430:inmethod_missing’
| /usr/share/foreman/app/models/concerns/orchestration/dhcp.rb:104:in build_dhcp_record'

Same error for host creation:
2019-02-21T14:51:47 [W|app|2296d] La tâche Créer des paramètres DHCP pour tyler-adebisi.domain.local a échoué avec l'erreur suivante : undefined method 'dhcp_record_type' for #<Redhat:0x000000000c76b338> | NoMethodError: undefined method 'dhcp_record_type' for #<Redhat:0x000000000c76b338> | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activemodel-5.2.1/lib/active_model/attribute_methods.rb:430:inmethod_missing’`

Second try fix : [https://gist.github.com/sbskas/b13e702cee2592d28b864f603d5b76c4]

I just gave your patch a try and it worked flawlessly. Create, update and delete of multihomed host all worked fine, for both VMWare and bare metal hosts. Bare metal had MAC set of course, VMWare only had the fildes described above.

@sebbernard are you sure you applied the patch correctly and to the vanilla file without leftovers from former tries to fix this? I’m not a good ruby dev (like, at all), but the patch does not even look like it’s touching a method called dhcp_record_type.

1 Like

My bad, I took more modification than the patch. The patch indeed works.
Sorry for the noise.
I removing the PR.

1 Like

Glad I helped, please drop a line in the PR if you didn’t do so the reviewer gets more confidence :slight_smile: Cheers.

@lzap the fix is not included in any 1.21 version.
When will it be included ?

You can see in redmine (our issue tracker) that Bug #26104: Multiple NIC orchestrations are not orchestrated - Foreman is marked as fixed in 1.22. I’m currently checking if it is possible to backport it to 1.21.3 which will be coming out soon.

I’ve added it to 1.21.3 release, which you can expect to be released in the next few days.

1 Like

Thanks for the schedule. This patch would be welcomed in the 1.20 also.

I’ve cherry-picked it to 1.20-stable branch as well, but we do not have a timeline for 1.20.3 yet.