Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/SAT-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1367136 - Hostgroup environment isn't inherited by Host via model API
Summary: Hostgroup environment isn't inherited by Host via model API
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Hosts
Version: 6.2.0
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: Unspecified
Assignee: Ondřej Pražák
QA Contact: Jitendra Yejare
URL:
Whiteboard:
: 1393449 (view as bug list)
Depends On:
Blocks: 1319283 1394363 1394364
TreeView+ depends on / blocked
 
Reported: 2016-08-15 16:54 UTC by Shimon Shtein
Modified: 2019-09-25 21:29 UTC (History)
9 users (show)

Fixed In Version: foreman-1.11.0.55-1
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1394364 (view as bug list)
Environment:
Last Closed: 2016-12-12 17:12:44 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
puppet Master/CA fileds are inherited for discovered host via auto-prov (48.66 KB, image/png)
2016-12-02 13:38 UTC, Sachin Ghai
no flags Details
on reviewing provisioning template of provisioned discovered host, it correctly renders the puppet (50.95 KB, image/png)
2016-12-02 13:39 UTC, Sachin Ghai
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 12936 0 Normal Closed Hostgroup environment isn't inherited by Host via model API 2020-10-15 16:05:30 UTC
Red Hat Product Errata RHBA-2016:2940 0 normal SHIPPED_LIVE Satellite 6.2.5 Async Bug Release 2016-12-12 22:08:21 UTC

Description Shimon Shtein 2016-08-15 16:54:05 UTC
*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 

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

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:

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


*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.

Comment 1 Shimon Shtein 2016-08-15 16:54:10 UTC
Created from redmine issue http://projects.theforeman.org/issues/12936

Comment 2 Shimon Shtein 2016-08-15 16:54:16 UTC
Upstream bug assigned to oprazak

Comment 4 Bryan Kearney 2016-08-15 18:16:53 UTC
Moving to POST since upstream bug http://projects.theforeman.org/issues/12936 has been closed

Comment 9 Lukas Zapletal 2016-11-03 09:23:29 UTC
QA notes: To test this, make sure that discovery auto provisioning sets Puppet Master/CA flags from hostgroup, symptoms of this bug was that it was left blank.

Comment 12 Lukas Zapletal 2016-11-03 13:08:12 UTC
HOTFIX FOR 6.2.2 AVAILABLE AT:

http://people.redhat.com/~lzapleta/hotfix/hostgroup-autoprovisioning-satellite-6.2.2-1367136/

Customers should not upgrade to 6.2.3-6.2.4 as the official fix is scheduled for 6.2.5.

Comment 13 Lukas Zapletal 2016-11-09 15:26:32 UTC
*** Bug 1393449 has been marked as a duplicate of this bug. ***

Comment 14 Mike McCune 2016-11-18 22:17:01 UTC
HOTFIX FOR 6.2.4 AVAILABLE AT:

http://people.redhat.com/~mmccune/hotfix/1367136/foreman-BZ1367136.tar

This is still on track to be delivered in 6.2.5

Comment 15 Jitendra Yejare 2016-12-02 12:07:00 UTC
So What would be the steps for QE to verify this:

I assume Steps as below:

1. Create Hostgroup(using API, CLI or UI modules) and select some puppet environment. 
2. From API attempt to create a host without passing puppet environment and choose step 1 hostgroup.


Assert:

1. Host should fetch puppet environment from Hostgroup.
2. Host should be created successfully.

Please Confirm !!

Comment 16 Sachin Ghai 2016-12-02 13:34:27 UTC
As per comment3 followed steps to validate the fix with sat6.2.5 snap1:


1 created a hostgroup with Puppet Master/CA fields associated to hostgroup
2 later defined a discovery rule and associated the hg created in above step1
3. Enabled auto-provisioning
4. discovered a host and auto-provisioning started.


Once host is provisioned, I see that both fields are correctly associated to provisioned host (checked from edit host page). Please see the attachment.

Also, I can see puppet correctly installed when I reviewed the provisioning template.  Please see the attachment.


Please advice if above steps are correct to validate the bz or something else needs to be validated.

Comment 17 Sachin Ghai 2016-12-02 13:38:26 UTC
Created attachment 1227343 [details]
puppet Master/CA fileds are inherited for discovered host via auto-prov

Comment 18 Sachin Ghai 2016-12-02 13:39:25 UTC
Created attachment 1227344 [details]
on reviewing provisioning template of provisioned discovered host, it correctly renders the puppet

Comment 19 Ondřej Pražák 2016-12-05 07:14:25 UTC
Steps in comment #15 should verify this fix works.

Comment 20 Jitendra Yejare 2016-12-05 12:05:38 UTC
While verifying this bug,

I have found an error as below:

Steps:
1. I created a hostgroup with all the fields required for libvirt provisioning.
2. I was attempting to create a Host using this above Hostgroup as follows:
Command: 
#curl -X POST -d '{"host":{"name":"host1","organization_ids":[1],"location_ids":[2],"ptable_id":[61],"compute_resource_id":[1],"root_pass":"somepass","hostgroup_id":[1],"build":true,"enabled":true}}' --header "Content-Type:application/json" https://qeblade36.rhq.lab.eng.bos.redhat.com/api/hosts/ --insecure

Executing this, the error message has been thrown:

{
  "error": {"message":"undefined method `inherited_puppet_proxy_id' for #<Array:0x007fddee7d3ad8>"
}

May I know If any parameter is missing or is it a real Bug ?

Please help.

Comment 21 Ondřej Pražák 2016-12-07 11:13:09 UTC
This one is on me, I did not notice you were passing an array in "hostgroup_id".
Try changing it to "hostgroup_id": "1". There will be additional validation requirements on host, but it will not fail with error. This verifies the inheritance works, however the issue refers to how objects inherit the attributes internally. If you want to be thorough, you could do something like the following in the console (tfm-rake console):
hg = Hostgroup.find 1
h = Host.new(:name => "myhost", :hostgroup => hg)
h.environment # should be environment inherited from hg

see the corresponding test for reference:
https://github.com/theforeman/foreman/pull/3243/files#diff-88c8d0302188366e58cfd358acf05756R2645

Comment 22 Jitendra Yejare 2016-12-07 13:12:30 UTC
Thanks for the reply Ondrej,

I tried your suggestion of passing hostgroup_id as string and that works perfectly. I am not getting error mentioned in comment 20 at all.

But, I am facing something new now,

I am creating host on libvirt compute resource which id is '1' in my case. And so I am passing that parameter 'compute_resource_id':"1". Following is the curl command:
# curl -X POST -d '{"host":{"name":"host1","organization_id":"1","location_id":"2","ptable_id":"61","compute_resource_id":1,"root_pass":"somepass","hostgroup_id":"1","build":true,"enabled":true}}' --header "Content-Type:application/json" https://hostname.domain.com/api/hosts/ --insecure

But I am getting the following error:

{
  "error": {"id":null,"errors":{"interfaces.mac":["can't be blank"]},"full_messages":["Mac can't be blank"]}
}

I believe this error message should appear only when provisioning on bare metal without providing the mac address. But this message is appearing for libvirt compute resource which is strange.

Is this a bug or am I missing any parameters ?

Comment 23 Ondřej Pražák 2016-12-09 13:27:22 UTC
I found a solution:

-d '{"host":{"name":"host1","organization_id":"1", "location_id":"2", "ptable_id":"61", "compute_resource_id": "1", "root_pass": "changeme", "hostgroup_id": "4", "build": "true","enabled": "true","interfaces_attributes": [{"primary": "true", "network": "default", "provision": "true", "compute_attributes": {"type": "network", "network": "default", "bridge": "virbr1", "model": "virtio"} }], "medium_id":"9"}}'

passed the validations and created a host record on libvirt for me. 'interface_attributes' may need a little tweaking based on your actual setup.

Comment 25 errata-xmlrpc 2016-12-12 17:12:44 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2016:2940


Note You need to log in before you can comment on or make changes to this bug.