Project

General

Profile

Actions

Bug #12936

closed

Hostgroup environment isn't inherited by Host via model API

Added by Daniel Lobato Garcia over 8 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Normal
Category:
Host creation
Target version:
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

Problem:

Since [[hostgroup_inherited_attributes](https://github.com/theforeman/foreman/blob/develop/app/models/host/managed.rb#L577)] uses association IDs instead of AR objects, creating hosts like

 hg.environment = Environment.first
 sample_host = Host.new(:name => 'hostname', :hostgroup => hg).environment
 sample_host.environment == nil #=> true

will not work.

The method to inherit these attributes relies on string attributes so Host must be created using 'hostgroup_id' or 'hostgroup_name' to inherit hostgroup attributes, like:

 sample_host = Host.new(:name => 'hostname', 'hostgroup_id' => hg.id)

Solution:

Make apply_inherited_attributes capable of inheriting regular AR relations, and not just attributes when passed as strings. That's why inheritance only works from the UI.

Actions

Also available in: Atom PDF