Project

General

Profile

Bug #12936

Hostgroup environment isn't inherited by Host via model API

Added by Daniel Lobato Garcia about 4 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Category:
Host creation
Target version:
Difficulty:
Triaged:
Bugzilla link:
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.

Associated revisions

Revision d7110d54 (diff)
Added by Ondřej Pražák almost 4 years ago

Fixes #12936 - Host inherits attributes when hostgroup is AR object

Revision 647b971f (diff)
Added by Ondřej Pražák almost 4 years ago

Fixes #12936 - Host inherits attributes when hostgroup is AR object

(cherry picked from commit d7110d54ad51a85eadde8283606e88cf01de8b19)

History

#1 Updated by Dominic Cleal about 4 years ago

  • Subject changed from Hostgroup environment isn't inherited by Host to Hostgroup environment isn't inherited by Host via model API
  • Category set to Host creation

#2 Updated by The Foreman Bot almost 4 years ago

  • Status changed from New to Ready For Testing
  • Assignee set to Ondřej Pražák
  • Pull request https://github.com/theforeman/foreman/pull/3243 added

#3 Updated by Ondřej Pražák almost 4 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#4 Updated by Dominic Cleal almost 4 years ago

  • Legacy Backlogs Release (now unused) set to 141

#5 Updated by Shimon Shtein over 3 years ago

  • Bugzilla link set to 1367136

Also available in: Atom PDF