Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
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 1484102

Summary: hammer host creation should handle non-existant os id instead of PG:Error
Product: Red Hat Satellite Reporter: Kedar Bidarkar <kbidarka>
Component: APIAssignee: satellite6-bugs <satellite6-bugs>
Status: CLOSED WONTFIX QA Contact: Katello QA List <katello-qa-list>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.3.0CC: akarsale, bkearney, dhlavacd, inecas, mhulan, tstrachota
Target Milestone: UnspecifiedKeywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-09-04 17:44:09 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1354568    
Bug Blocks:    

Description Kedar Bidarkar 2017-08-22 17:02:56 UTC
Description of problem:

hammer -u admin -p changeme  host create --name='rhel-7-libvirt12' --root-password='changeme' --organization-id="1" --location-id="2" --hostgroup="RHEL 7 Server 64-bit HG" --compute-resource="libvirt" --compute-attributes="cpus=1, memory=1073741824, start=1" --interface="primary=true, compute_type=bridge, compute_bridge=katello_latest, compute_model=virtio" --volume="capacity=10G,format_type=qcow2" --operatingsystem-id 3 --pxe-loader 'PXELinux BIOS'
Could not create the host:
  ERROR:  insert or update on table "hosts" violates foreign key constraint "hosts_operatingsystem_id_fk"
  DETAIL:  Key (operatingsystem_id)=(3) is not present in table "operatingsystems".




2017-08-22 09:07:24 8d37cb27 [app] [I] Started POST "/api/hosts" for 127.0.0.1 at 2017-08-22 09:07:24 -0400
2017-08-22 09:07:24 8d37cb27 [app] [I] Processing by Api::V2::HostsController#create as JSON
2017-08-22 09:07:24 8d37cb27 [app] [I]   Parameters: {"host"=>{"name"=>"rhel-7-libvirt12", "location_id"=>2, "organization_id"=>1, "operatingsystem_id"=>3, "pxe_loader"=>"PXELinux BIOS", "compute_resource_id"=>1, "hostgroup_id"=>2, "build"=>true, "enabled"=>true, "managed"=>true, "compute_attributes"=>{"cpus"=>"1", "memory"=>"1073741824", "start"=>"1", "volumes_attributes"=>{"0"=>{"capacity"=>"10G", "format_type"=>"qcow2"}}}, "content_facet_attributes"=>{}, "subscription_facet_attributes"=>{}, "overwrite"=>true, "host_parameters_attributes"=>[], "interfaces_attributes"=>[{"primary"=>"true", "compute_attributes"=>{"type"=>"bridge", "bridge"=>"katello_latest", "model"=>"virtio"}}], "root_pass"=>"[FILTERED]"}, "apiv"=>"v2"}
2017-08-22 09:07:24 8d37cb27 [app] [I] Current user: foreman_admin (administrator)
2017-08-22 09:07:24 8d37cb27 [app] [I] Current user: foreman_admin (administrator)
2017-08-22 09:07:24 8d37cb27 [app] [I] Current user: admin (administrator)
2017-08-22 09:07:24 8d37cb27 [app] [I] Authorized user admin(Admin User)
2017-08-22 09:07:24 8d37cb27 [app] [I] Current user: admin (administrator)
2017-08-22 09:07:28 8d37cb27 [app] [I] Add DNS A record for rhel-7-lhost1-name.redhat.com/10.x.x.x
2017-08-22 09:07:28 8d37cb27 [app] [I] Add DNS PTR record for rhel-7-lhost1-name.redhat.com
2017-08-22 09:07:29 8d37cb27 [app] [W] Rolling back due to exception during save
 | ActiveRecord::InvalidForeignKey: PG::Error: ERROR:  insert or update on table "hosts" violates foreign key constraint "hosts_operatingsystem_id_fk"
 | DETAIL:  Key (operatingsystem_id)=(3) is not present in table "operatingsystems".
 | : INSERT INTO "hosts" ("type", "build", "compute_resource_id", "managed", "root_pass", "pxe_loader", "hostgroup_id", "location_id", "operatingsystem_id", "organization_id", "puppet_proxy_id", "puppet_ca_proxy_id", "environment_id", "name", "owner_id", "owner_type", "architecture_id", "ptable_id", "grub_pass", "lookup_value_matcher", "uuid", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23) RETURNING "id"
 | /opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:602:in `exec_prepared'
 | /opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:602:in `block in exec_cache'
 | /opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:472:in `block in log'



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

Sat6.3.0-snap12.0

How reproducible:


Steps to Reproduce:
1. Create a host with non-existant --operatingsystem-id
2.
3.

Actual results:

Could not create the host:
  ERROR:  insert or update on table "hosts" violates foreign key constraint "hosts_operatingsystem_id_fk"
  DETAIL:  Key (operatingsystem_id)=(3) is not present in table "operatingsystems".


Expected results:

Should throw an error at an early stage, with a message something like,
"operatingsystem not found by id '3' "



Additional info:

Comment 6 Bryan Kearney 2018-09-04 17:44:09 UTC
Thank you for your interest in Satellite 6. We have evaluated this request, and we do not expect this to be implemented in the product in the foreseeable future. We are therefore closing this out as WONTFIX. If you have any concerns about this, please feel free to contact Rich Jerrido or Bryan Kearney. Thank you.