Project

General

Profile

Actions

Bug #9597

closed

FK violation when trying to delete a discovered host after provision

Added by Ori Rabin about 9 years ago. Updated almost 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Discovery plugin
Target version:
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

When provision on a discovered host fails there is a token created that is not deleted.
Provisioning the same host again will create a new token for that host.
Trying to delete the host after provision deletes only the second token,
to avoid leaving an orphaned token the delete fails with a FK violation error

Steps to reproduce:
1. discover a host
2. try to provision that host but don't put anything in the host edit form
3. save
4. fill in correct values to provision the host
5. save
6. try to delete the new managed host that was created

expected result: host is deleted

actual result: an error:

ERROR:  update or delete on table "hosts" violates foreign key constraint "tokens_host_id_fk" on table "tokens" 


Related issues 3 (0 open3 closed)

Related to Discovery - Bug #10365: Migration to delete duplicate tokens doesn't work when there are no managed hostsClosedOri Rabin05/05/2015Actions
Related to Foreman - Bug #10535: Tokens are created for managed hosts after validationClosedOri Rabin05/18/2015Actions
Has duplicate Foreman - Bug #9900: ERROR: update or delete on table "hosts" violates foreign key constraint "tokens_host_id_fk" on table "tokens" DETAIL: Key (id)=(6) is still referenced from table "tokens"Duplicate03/25/2015Actions
Actions #2

Updated by The Foreman Bot about 9 years ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/foreman_discovery/pull/163 added
  • Pull request deleted ()
Actions #3

Updated by Ori Rabin about 9 years ago

I can only reproduce on a new DB, once I delete the token table I can't anymore.

Actions #4

Updated by Ori Rabin about 9 years ago

  • Target version set to Discovery Plugin 2.0.1
Actions #5

Updated by Stefan Lasiewski about 9 years ago

I've been testing the Discovery Plugin casually since 2.0.0-rc1, and it would be hard for me to pin down any specific steps that led to this.

In my particular case, we've been using The Foreman on an off since release 1.4. I have upgraded from 1.4 to 1.5, 1.6 and 1.7 over time. I started experimenting with the Discovery Plugin 2.0.0-rc1 soon after it came out and I have used it to discover a dozen physical hosts. I then upgraded to 2.0.0-rc2 and 2.0.0-1 soon after they were released.

I am attempting to provision 3 of these hosts. With two of the hosts, I cannot delete the host. Here's an example using the hammer CLI:

stefanl@puppet:~ $ hammer -d host delete --id 83
[ INFO 2015-03-02 10:53:53 Init] Initialization of Hammer CLI (0.1.3) has started...
[DEBUG 2015-03-02 10:53:53 Init] Running at ruby 1.8.7-p374
[ INFO 2015-03-02 10:53:53 Init] Configuration from the file /etc/hammer/cli_config.yml has been loaded
[ INFO 2015-03-02 10:53:53 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman.yml has been loaded
[ INFO 2015-03-02 10:53:53 Init] Configuration from the file /home/stefanl/.hammer/cli_config.yml has been loaded
[DEBUG 2015-03-02 10:53:54 Connection] Registered: foreman
[DEBUG 2015-03-02 10:53:54 API] Global headers: {
:content_type => "application/json",
:accept => "application/json;version=2",
"Accept-Language" => "en"
}
[ INFO 2015-03-02 10:53:54 Modules] Extension module hammer_cli_foreman (0.1.3) loaded
[DEBUG 2015-03-02 10:53:54 Init] Using locale 'en'
[DEBUG 2015-03-02 10:53:54 Init] 'mo' files for locale domain 'hammer-cli' loaded from '/usr/lib/ruby/gems/1.8/gems/hammer_cli-0.1.3/locale'
[DEBUG 2015-03-02 10:53:54 Init] 'mo' files for locale domain 'hammer-cli' loaded from '/usr/share/locale'
[DEBUG 2015-03-02 10:53:54 Init] 'mo' files for locale domain 'hammer-cli-foreman' loaded from '/usr/lib/ruby/gems/1.8/gems/hammer_cli_foreman-0.1.3/locale'
[DEBUG 2015-03-02 10:53:54 Init] 'mo' files for locale domain 'hammer-cli-foreman' loaded from '/usr/share/locale'
[ INFO 2015-03-02 10:53:54 HammerCLI::MainCommand] Called with options: {"option_debug"=>true}
[ INFO 2015-03-02 10:53:54 HammerCLIForeman::Host] Called with options: {}
[ INFO 2015-03-02 10:53:54 HammerCLIForeman::Host::DeleteCommand] Called with options: {"option_id"=>"83"}
[ INFO 2015-03-02 10:53:54 API] DELETE /api/hosts/83
[DEBUG 2015-03-02 10:53:54 API] Params: {}
[DEBUG 2015-03-02 10:53:54 API] Headers: {
:params => {}
}
[DEBUG 2015-03-02 10:53:56 API] 500 Internal Server Error {
"error" => {
"message" => "ERROR: update or delete on table \"hosts\" violates foreign key constraint \"tokens_host_id_fk\" on table \"tokens\"\nDETAIL: Key (id)=(83) is still referenced from table \"tokens\".\n"
}
}
[ERROR 2015-03-02 10:53:56 Exception] ERROR: update or delete on table "hosts" violates foreign key constraint "tokens_host_id_fk" on table "tokens"
DETAIL: Key (id)=(83) is still referenced from table "tokens".

Could not delete the host:
ERROR: update or delete on table "hosts" violates foreign key constraint "tokens_host_id_fk" on table "tokens"
DETAIL: Key (id)=(83) is still referenced from table "tokens".
[ERROR 2015-03-02 10:53:56 Exception]

RestClient::InternalServerError (500 Internal Server Error):
/usr/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/abstract_response.rb:48:in `return!'
/usr/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/request.rb:230:in `process_result'
/usr/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/request.rb:178:in `transmit'
/usr/lib/ruby/1.8/net/http.rb:543:in `start'
/usr/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/request.rb:172:in `transmit'
/usr/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/request.rb:64:in `execute'
/usr/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
/usr/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/resource.rb:97:in `delete'
/usr/lib/ruby/gems/1.8/gems/apipie-bindings-0.0.10/lib/apipie_bindings/api.rb:199:in `send'
/usr/lib/ruby/gems/1.8/gems/apipie-bindings-0.0.10/lib/apipie_bindings/api.rb:199:in `http_call'
/usr/lib/ruby/gems/1.8/gems/apipie-bindings-0.0.10/lib/apipie_bindings/api.rb:154:in `call'
/usr/lib/ruby/gems/1.8/gems/apipie-bindings-0.0.10/lib/apipie_bindings/resource.rb:14:in `call'
/usr/lib/ruby/gems/1.8/gems/hammer_cli-0.1.3/lib/hammer_cli/./apipie/command.rb:42:in `send_request'
/usr/lib/ruby/gems/1.8/gems/hammer_cli_foreman-0.1.3/lib/hammer_cli_foreman/commands.rb:164:in `send_request'
/usr/lib/ruby/gems/1.8/gems/hammer_cli-0.1.3/lib/hammer_cli/./apipie/command.rb:33:in `execute'
/usr/lib/ruby/gems/1.8/gems/clamp-0.6.3/lib/clamp/command.rb:67:in `run'
/usr/lib/ruby/gems/1.8/gems/hammer_cli-0.1.3/lib/hammer_cli/./apipie/../abstract.rb:22:in `run'
/usr/lib/ruby/gems/1.8/gems/clamp-0.6.3/lib/clamp/subcommand/execution.rb:11:in `execute'
/usr/lib/ruby/gems/1.8/gems/clamp-0.6.3/lib/clamp/command.rb:67:in `run'
/usr/lib/ruby/gems/1.8/gems/hammer_cli-0.1.3/lib/hammer_cli/./apipie/../abstract.rb:22:in `run'
/usr/lib/ruby/gems/1.8/gems/clamp-0.6.3/lib/clamp/subcommand/execution.rb:11:in `execute'
/usr/lib/ruby/gems/1.8/gems/clamp-0.6.3/lib/clamp/command.rb:67:in `run'
/usr/lib/ruby/gems/1.8/gems/hammer_cli-0.1.3/lib/hammer_cli/./apipie/../abstract.rb:22:in `run'
/usr/lib/ruby/gems/1.8/gems/clamp-0.6.3/lib/clamp/command.rb:125:in `run'
/usr/lib/ruby/gems/1.8/gems/hammer_cli-0.1.3/bin/hammer:106
/usr/bin/hammer:19:in `load'
/usr/bin/hammer:19
stefanl@puppet:~ $

Actions #6

Updated by Stefan Lasiewski about 9 years ago

And I don't really know rake at all, but I did follow some debugging advice from an earlier ticket (Bug 1109258) and I poked around on the rake console a bit. I'm not sure how helpful this could be, but I thought I would include it anyways.

[root@puppet ~]# foreman-rake console

Loading production environment (Rails 3.2.8)
irb(main):001:0>
irb(main):002:0*
irb(main):003:0* Token.where(:host_id =>
irb(main):004:1* Host.find_by_name("host4.test.example.org"))
Host::Managed Load (1.4ms) SELECT "hosts".* FROM "hosts" WHERE "hosts"."type" IN ('Host::Managed') AND "hosts"."name" = 'host4.test.example.org' LIMIT 1
Token Load (0.6ms) SELECT "tokens".* FROM "tokens" WHERE "tokens"."host_id" = 82
=> [#<Token id: 44, value: "45661f2c-dd01-4efq-aqq9-94eq12384224", expires: "2015-02-12 09:07:50", host_id: 82>, #<Token id: 43, value: "123d24ac-2731-4381-qe11-123123adq0q6", expires: "2015-02-12 09:03:27", host_id: 82>, #<Token id: 42, value: "98749f91-dd01-4dd4-983e-1231231fe920", expires: "2015-02-12 09:03:10", host_id: 82>, #<Token id: 41, value: "asdqf40fe-9q96-4cd9-ae34-12323c08fa7", expires: "2015-02-12 09:02:40", host_id: 82>, #<Token id: 40, value: "ertf6q2f-7c9c-434c-916e-12312328012f", expires: "2015-02-12 09:02:29", host_id: 82>]
irb(main):005:0>

Actions #7

Updated by Ori Rabin about 9 years ago

  • Pull request https://github.com/theforeman/foreman_discovery/pull/166 added
  • Pull request deleted (https://github.com/theforeman/foreman_discovery/pull/163)
Actions #8

Updated by Stefan Lasiewski about 9 years ago

This bug may also affect provisioning. I noticed that when I'm attempting to re-provision a server, it does not modify the file at /var/lib/tftpboot/pxelinux.cfg/01-00-33-44-55-66-77

As a workaround, I discovered that I can rename the host from something like 'webhost.example.org' to 'webhost-bad.example.org', assign a bogus MAC address to the primary interface, like 11:22:33:44:55:66 and delete any extra interfaces. The host is still in the list, with "host_id" = 82 but I can ignore it for now and delete it at some future point

Actions #9

Updated by Ori Rabin about 9 years ago

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

Updated by Lukas Zapletal about 9 years ago

  • Bugzilla link set to 1197477
Actions #11

Updated by Dominic Cleal about 9 years ago

  • Has duplicate Bug #9900: ERROR: update or delete on table "hosts" violates foreign key constraint "tokens_host_id_fk" on table "tokens" DETAIL: Key (id)=(6) is still referenced from table "tokens" added
Actions #12

Updated by Lukas Zapletal almost 9 years ago

  • Related to Bug #9777: Trying to delete a discovered host after a failed provisioning request fails added
Actions #13

Updated by Lukas Zapletal almost 9 years ago

  • Related to deleted (Bug #9777: Trying to delete a discovered host after a failed provisioning request fails)
Actions #14

Updated by Ori Rabin almost 9 years ago

  • Related to Bug #10365: Migration to delete duplicate tokens doesn't work when there are no managed hosts added
Actions #15

Updated by Dominic Cleal almost 9 years ago

  • Related to Bug #10535: Tokens are created for managed hosts after validation added
Actions

Also available in: Atom PDF