Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 1514014 - Create new host via API does not override content_source_id from hostgroup
Summary: Create new host via API does not override content_source_id from hostgroup
Keywords:
Status: NEW
Alias: None
Product: Red Hat Satellite 6
Classification: Red Hat
Component: Hosts
Version: 6.2.12
Hardware: x86_64
OS: Linux
medium
medium vote
Target Milestone: Unspecified
Assignee: satellite6-bugs
QA Contact: Jan Hutař
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-11-16 13:48 UTC by Kenny Tordeurs
Modified: 2019-04-11 03:29 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:


Attachments (Terms of Use)

Description Kenny Tordeurs 2017-11-16 13:48:08 UTC
Description of problem:
The content_source_id specified in API call does not overwrite the content_source_id that is specified in the hostgroup which results in the host getting the wrong content source.

Create host with following API call:
~~~
# curl -H "Accept:application/json,version=2" -H "Content-Type:application/json" -X POST -u admin:password -k -d '{ "name":"testvm","organization_id":"1","location_id":"3","hostgroup_id":"8","lifecycle-environment_id":"2","content-view_id":"4","content_source_id":"2","mac":"00:55:ff:ab:ff:vc","domain_id":"1","subnet_id":"3","ptable_id":"93","root-password":"password01","model_id":"1","build":"true","puppet_ca_proxy_id":"2","puppet_proxy_id":"2","managed":"true"}' https://satellite.example.com/api/hosts
~~~

Results in usage of content_source_id 1 instead of 2:
~~~
{"ip":"192.168.1.2","environment_id":3,"environment_name":"Development","last_report":null,"mac":"00:55:ff:ab:ff:vc","realm_id":null,"realm_name":null,"sp_mac":null,"sp_ip":null,"sp_name":null,"domain_id":1,"domain_name":"domain.example.com","architecture_id":1,"architecture_name":"x86_64","operatingsystem_id":9,"operatingsystem_name":"RedHat 7.0","subnet_id":3,"subnet_name":"Subnet_Name","sp_subnet_id":null,"ptable_id":93,"ptable_name":"PTable","medium_id":null,"medium_name":null,"build":true,"comment":null,"disk":null,"installed_at":null,"model_id":1,"hostgroup_id":8,"owner_id":3,"owner_type":"User","enabled":true,"puppet_ca_proxy_id":2,"managed":true,"use_image":null,"image_file":"","uuid":null,"compute_resource_id":null,"compute_resource_name":null,"compute_profile_id":null,"compute_profile_name":null,"capabilities":["build"],"provision_method":"build","puppet_proxy_id":2,"certname":"testvm.domain.example.com","image_id":null,"image_name":null,"created_at":"2017-11-06 09:39:24 UTC","updated_at":"2017-11-06 09:39:24 UTC","last_compile":null,"global_status":0,"global_status_label":"Warning","organization_id":1,"organization_name":"OrgName","location_id":3,"location_name":"LocationName","puppet_status":0,"model_name":"VMware Virtual Platform","configuration_status":0,"configuration_status_label":"No reports","build_status":1,"build_status_label":"Pending installation","name":"testvm.domain.example.com","id":1563,"hostgroup_name":"7.0","hostgroup_title":"Development/7.0","content_facet_attributes":{"id":1376,"uuid":null,"content_view_id":4,"content_view_name":"cv-os-rhel-7.0","lifecycle_environment_id":2,"lifecycle_environment_name":"Development","content_view":{"id":4,"name":"cv-os-rhel-7.0"},"lifecycle_environment":{"id":2,"name":"Development"},"errata_counts":null,"content_view_version":"8.0","content_view_version_id":81,"content_view_default?":false,"lifecycle_environment_library?":false,"katello_agent_installed":false},"parameters":[],"interfaces":[{"id":3541,"name":"testvm.domain.example.com","ip":"192.168.1.2","mac":"00:55:ff:ab:ff:vc","identifier":null,"primary":true,"provision":true,"type":"interface"}],"puppetclasses":[],"config_groups":[],"all_parameters":[{"id":7,"name":"kt_activation_keys","value":"ak-os-rhel-7.0-dev"},{"id":32,"name":"cpd","value":"LocationName"},{"id":26,"name":"ntp-server","value":"ntp_server.domain.example.com"},{"id":25,"name":"encrypt_pass","value":"Somepassword"}],"all_puppetclasses":[],"facts":{},"content_source_id":1,"host_collections":[],"permissions":{"view_hosts":true,"create_hosts":true,"edit_hosts":true,"destroy_hosts":true,"build_hosts":true,"power_hosts":true,"console_hosts":true,"ipmi_boot":true,"puppetrun_hosts":true,"view_discovered_hosts":true,"submit_discovered_hosts":true,"auto_provision_discovered_hosts":true,"provision_discovered_hosts":true,"edit_discovered_hosts":true,"destroy_discovered_hosts":true}}
~~~

Version-Release number of selected component (if applicable):
6.2.12

How reproducible:
100%

Steps to Reproduce:
1. Create hostgroup with different content source
2. Create new host via API and specify created hostgroup and different content source
3.

Actual results:
content source of hostgroup is used

Expected results:
content source of API call to be used 

Additional info:

Comment 4 Kenny Tordeurs 2018-02-28 13:12:08 UTC
Testing API call on Satellite 6.3:
~~~
# curl -H "Accept:application/json,version=2" -H "Content-Type:application/json" -X POST -u admin:password -k -d '{ "name":"testvm","organization_id":"1","location_id":"2","hostgroup_id":"7","lifecycle-environment_id":"21","content-view_id":"65","content_source_id":"2","domain_id":"1","subnet_id":"1","ptable_id":"63","root-password":"password01","model_id":"1","build":"true","puppet_ca_proxy_id":"2","puppet_proxy_id":"2","managed":"true","environment_id":"1","medium_id":"32","mac":"52:54:00:1c:95:60"}' https://provisioning.sysmgmt.lan/api/hosts
~~~

Above I specified "content_source_id":"2" but result contains "content_source_id":1 which was specified in the hostgroup so I believe it's still inheriting from the hostgroup instead of overwriting with the parameter specified in the API call.

~~~
{"ip":"192.168.111.115","ip6":null,"environment_id":1,"environment_name":"production","last_report":null,"mac":"52:54:00:1c:95:60","realm_id":null,"realm_name":null,"sp_mac":null,"sp_ip":null,"sp_name":null,"domain_id":1,"domain_name":"sysmgmt.lan","architecture_id":1,"architecture_name":"x86_64","operatingsystem_id":5,"operatingsystem_name":"CentOS 7","subnet_id":1,"subnet_name":"sysmgmt.lan","subnet6_id":null,"subnet6_name":null,"sp_subnet_id":null,"ptable_id":63,"ptable_name":"Kickstart default","medium_id":32,"medium_name":null,"pxe_loader":null,"build":true,"comment":null,"disk":null,"installed_at":null,"model_id":1,"hostgroup_id":7,"owner_id":3,"owner_type":"User","enabled":true,"managed":true,"use_image":null,"image_file":"","uuid":null,"compute_resource_id":null,"compute_resource_name":null,"compute_profile_id":1,"compute_profile_name":"1-Small","capabilities":["build"],"provision_method":"build","certname":"testvm.sysmgmt.lan","image_id":null,"image_name":null,"created_at":"2018-02-28 13:04:50 UTC","updated_at":"2018-02-28 13:04:50 UTC","last_compile":null,"global_status":0,"global_status_label":"Warning","organization_id":1,"organization_name":"Default Organization","location_id":2,"location_name":"Default Location","puppet_status":0,"model_name":"KVM","configuration_status":0,"configuration_status_label":"No reports","build_status":1,"build_status_label":"Pending installation","name":"testvm.sysmgmt.lan","id":403,"puppet_proxy_id":2,"puppet_proxy_name":"ktordeur-capsule-provisioning.pipopopo.lan","puppet_ca_proxy_id":2,"puppet_ca_proxy_name":"ktordeur-capsule-provisioning.pipopopo.lan","openscap_proxy_id":null,"openscap_proxy_name":null,"puppet_proxy":{"name":"ktordeur-capsule-provisioning.pipopopo.lan","id":2,"url":"https://ktordeur-capsule-provisioning.pipopopo.lan:9090"},"puppet_ca_proxy":{"name":"ktordeur-capsule-provisioning.pipopopo.lan","id":2,"url":"https://ktordeur-capsule-provisioning.pipopopo.lan:9090"},"openscap_proxy":null,"hostgroup_name":"CentOS 7","hostgroup_title":"CentOS 7","parameters":[],"all_parameters":[{"priority":0,"created_at":"2017-07-26 07:35:57 UTC","updated_at":"2017-07-26 07:35:57 UTC","id":32,"name":"user","value":"snemeth"}],"content_facet_attributes":{"id":255,"uuid":null,"content_view_id":1,"content_view_name":"Default Organization View","lifecycle_environment_id":1,"lifecycle_environment_name":"Library","content_source_id":1,"content_source_name":"provisioning.sysmgmt.lan","kickstart_repository_id":null,"errata_counts":{"security":0,"bugfix":0,"enhancement":0,"total":0},"applicable_package_count":0,"upgradable_package_count":0,"content_view":{"id":1,"name":"Default Organization View"},"lifecycle_environment":{"id":1,"name":"Library"},"content_source":{"id":1,"name":"provisioning.sysmgmt.lan","url":"https://provisioning.sysmgmt.lan:9090"},"content_view_version":"1.0","content_view_version_id":1,"content_view_default?":true,"lifecycle_environment_library?":true,"katello_agent_installed":false},"interfaces":[{"id":419,"name":"testvm.sysmgmt.lan","ip":"192.168.111.115","ip6":null,"mac":"52:54:00:1c:95:60","identifier":null,"primary":true,"provision":true,"type":"interface"}],"puppetclasses":[],"config_groups":[],"all_puppetclasses":[{"id":15,"name":"foreman_scap_client","module_name":"foreman_scap_client"}],"facts":{},"host_collections":[],"permissions":{"view_hosts":true,"create_hosts":true,"edit_hosts":true,"destroy_hosts":true,"build_hosts":true,"power_hosts":true,"console_hosts":true,"puppetrun_hosts":true,"ipmi_boot_hosts":true,"view_discovered_hosts":true,"submit_discovered_hosts":true,"auto_provision_discovered_hosts":true,"provision_discovered_hosts":true,"edit_discovered_hosts":true,"destroy_discovered_hosts":true}}
~~~

Comment 5 Shimon Shtein 2018-02-28 18:25:34 UTC
I have tested this. The system behaves differently if you set content properties directly on the host level, or inside content facet. If you do it through content facet, it behaves as expected:

~~~
# curl -H "Accept:application/json,version=2" -H "Content-Type:application/json" -X POST -u admin:password -k -d '{ "name":"testvm","organization_id":"1","location_id":"2","hostgroup_id":"7","lifecycle-environment_id":"21","content-view_id":"65","content_source_id":"2","domain_id":"1","subnet_id":"1","ptable_id":"63","root-password":"password01","model_id":"1","build":"true","puppet_ca_proxy_id":"2","puppet_proxy_id":"2","managed":"true","environment_id":"1","medium_id":"32","mac":"52:54:00:1c:95:60"}' https://provisioning.sysmgmt.lan/api/v2/hosts
~~~

Will return wrong content source (1), but:

~~~
# curl -H "Accept:application/json,version=2" -H "Content-Type:application/json" -X POST -u admin:password -k -d '{
	"name":"testvm","organization_id":"1","location_id":"2","hostgroup_id":"7","lifecycle-environment_id":"21","content-view_id":"65","domain_id":"1","subnet_id":"1","ptable_id":"63","root-password":"password01","model_id":"1","build":"true","puppet_ca_proxy_id":"2","puppet_proxy_id":"2","managed":"true","environment_id":"1","medium_id":"32","mac":"52:54:00:1c:95:60",
	"content_facet_attributes" : {
		"content_source_id":"2"
	}
}' https://provisioning.sysmgmt.lan/api/hosts
~~~

will return content_source_id = 2 as expected.

I suspect a bug in facets framework - there is a special use case to make properties available on both host level and facet level.
I need to investigate it further to see how to fix this, but as a workaround and good practice, I prefer using the content_facet_attributes.


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