Bug 1177145

Summary: rubygem-staypuft: Can't remove a host from staypuft: ERROR: update or delete on table "hosts" violates foreign key constraint "tokens_host_id_fk" on table "tokens" DETAIL: Key (id)=(18) is still referenced from table "tokens".
Product: Red Hat OpenStack Reporter: Alexander Chuzhoy <sasha>
Component: rubygem-staypuftAssignee: Mike Burns <mburns>
Status: CLOSED WONTFIX QA Contact: Omri Hochman <ohochman>
Severity: medium Docs Contact:
Priority: medium    
Version: unspecifiedCC: aberezin, mburns, oblaut, yeylon
Target Milestone: ---Keywords: ZStream
Target Release: Installer   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-04-29 14:49:21 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:    
Bug Blocks: 1177026    

Description Alexander Chuzhoy 2014-12-24 14:26:19 UTC
rubygem-staypuft: Can't remove a host from staypuft: ERROR: update or delete on table "hosts" violates foreign key constraint "tokens_host_id_fk" on table "tokens" DETAIL: Key (id)=(18) is still referenced from table "tokens".

Environment:
openstack-puppet-modules-2014.2.8-1.el7ost.noarch
ruby193-rubygem-foreman_openstack_simplify-0.0.6-8.el7ost.noarch
openstack-foreman-installer-3.0.8-1.el7ost.noarch
rhel-osp-installer-0.5.4-1.el7ost.noarch
ruby193-rubygem-staypuft-0.5.9-1.el7ost.noarch
rhel-osp-installer-client-0.5.4-1.el7ost.noarch

Steps to reproduce:
1. Install rhel-osp-installer.
2. Attempt to discover/deploy/delete hosts several times.

Result:
At some point the issue appears, can't delete some host from the UI. I get:
ERROR: update or delete on table "hosts" violates foreign key constraint "tokens_host_id_fk" on table "tokens" DETAIL: Key (id)=(18) is still referenced from table "tokens".

Full trace:
PGError
ERROR: update or delete on table "hosts" violates foreign key constraint "tokens_host_id_fk" on table "tokens" DETAIL: Key (id)=(18) is still referenced from table "tokens". 
app/controllers/hosts_controller.rb:401:in `block in submit_multiple_destroy'
app/controllers/hosts_controller.rb:401:in `submit_multiple_destroy'
app/models/concerns/foreman/thread_session.rb:33:in `clear_thread'
lib/middleware/catch_json_parse_errors.rb:9:in `call'



In the foreman logs I have:
==> /var/log/foreman-proxy/proxy.log <==

==> /var/log/foreman/production.log <==


Started GET "/hosts" for 10.10.57.157 at 2014-12-24 14:25:37 +0000
Processing by HostsController#index as HTML
  Rendered hosts/_list.html.erb (29.5ms)
  Rendered hosts/index.html.erb within layouts/application (36.2ms)
  Rendered common/_searchbar.html.erb (8.6ms)
  Rendered home/_user_dropdown.html.erb (2.0ms)
Read fragment views/tabs_and_title_records-3 (0.2ms)
  Rendered home/_topbar.html.erb (3.2ms)
  Rendered layouts/base.html.erb (5.2ms)
Completed 200 OK in 74ms (Views: 51.5ms | ActiveRecord: 5.8ms)


Started DELETE "/hosts/mac000af7799318.example.com" for 10.10.57.157 at 2014-12-24 14:25:42 +0000
Processing by HostsController#destroy as HTML
  Parameters: {"authenticity_token"=>"dDBCa3y0KzynOCieQ/jOhZtsHrklRWkqLzPiqyU2Ppc=", "id"=>"mac000af7799318.example.com"}
Operation FAILED: ERROR:  update or delete on table "hosts" violates foreign key constraint "tokens_host_id_fk" on table "tokens"
DETAIL:  Key (id)=(18) is still referenced from table "tokens".

  Rendered common/500.html.erb within layouts/application (7.5ms)
  Rendered layouts/base.html.erb (2.2ms)
Completed 500 Internal Server Error in 86ms (Views: 11.9ms | ActiveRecord: 18.9ms)




Expected result:
Should always be able to delete any host.

Comment 1 Alexander Chuzhoy 2014-12-24 14:42:33 UTC
As a workaround:
1. moved the host to production environment (from Discovery)
2. assigned it to "base_RedHat_7" host group 
3. turned the host to "managed" in the UI 
and then was able to delete it.
Probably a single step from above could do the trick