Project

General

Profile

Bug #21689

Specifying wrong foreign key id for object (such as host or hostgroup) via hammer/api throws SQL error

Added by Andrew Kofink over 2 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
-
Target version:
Difficulty:
Triaged:
Bugzilla link:
Fixed in Releases:
Found in Releases:

Description

Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1488475

Description of problem:
If you specify non-existent content source id for hammer host/hostgroup create/update command, SQL error is shown instead of validation message.

Version-Release number of selected component (if applicable):
Satellite 6.3.0 Snap 14

How reproducible:
Always

Steps to Reproduce:
1. Execute host/hostgroup create/update command with --content-source-id set to some nonexistent id:
hammer host create --medium-id="169" --ip="###.###.##.###" --location-id="2" --operatingsystem-id="3" --lifecycle-environment-id="593" --domain-id="1" --partition-table-id="87" --content-source-id="61340" --mac="40:8f:bf:b6:ca:7a" --content-view-id="618" --architecture-id="1" --organization="RshekR" --name="mYXwuGUHRd" --root-password="test"
2.
3.

Actual results:
[ERROR 2017-09-05 09:04:15 API] 500 Internal Server Error
[ERROR 2017-09-05 09:04:15 Exception] ERROR: insert or update on table "katello_content_facets" violates foreign key constraint "katello_content_facets_content_source_id_fk"
DETAIL: Key (content_source_id)=(61340) is not present in table "smart_proxies".

Could not create the host:
ERROR: insert or update on table "katello_content_facets" violates foreign key constraint "katello_content_facets_content_source_id_fk"
DETAIL: Key (content_source_id)=(61340) is not present in table "smart_proxies".
[ERROR 2017-09-05 09:04:15 Exception]

RestClient::InternalServerError (500 Internal Server Error):
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-1.8.0/lib/restclient/abstract_response.rb:74:in `return!'
/opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.0/lib/apipie_bindings/api.rb:352:in `block in rest_client_call_block'
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-1.8.0/lib/restclient/request.rb:493:in `process_result'
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-1.8.0/lib/restclient/request.rb:421:in `block in transmit'
/opt/rh/rh-ruby23/root/usr/share/ruby/net/http.rb:853:in `start'
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-1.8.0/lib/restclient/request.rb:413:in `transmit'
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-1.8.0/lib/restclient/request.rb:176:in `execute'
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-1.8.0/lib/restclient/request.rb:41:in `execute'
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-1.8.0/lib/restclient/resource.rb:67:in `post'
/opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.0/lib/apipie_bindings/api.rb:324:in `call_client'
/opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.0/lib/apipie_bindings/api.rb:240:in `http_call'
/opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.0/lib/apipie_bindings/api.rb:190:in `call_action'
/opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.0/lib/apipie_bindings/api.rb:185:in `call'
/opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.0/lib/apipie_bindings/resource.rb:21:in `call'
/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.10.2/lib/hammer_cli/apipie/command.rb:43:in `send_request'
/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_foreman-0.10.2/lib/hammer_cli_foreman/commands.rb:166:in `send_request'
/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.10.2/lib/hammer_cli/apipie/command.rb:34:in `execute'
/opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.0.0/lib/clamp/command.rb:68:in `run'
/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.10.2/lib/hammer_cli/abstract.rb:29:in `run'
/opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.0.0/lib/clamp/subcommand/execution.rb:11:in `execute'
/opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.0.0/lib/clamp/command.rb:68:in `run'
/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.10.2/lib/hammer_cli/abstract.rb:29:in `run'
/opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.0.0/lib/clamp/subcommand/execution.rb:11:in `execute'
/opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.0.0/lib/clamp/command.rb:68:in `run'
/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.10.2/lib/hammer_cli/abstract.rb:29:in `run'
/opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.0.0/lib/clamp/command.rb:133:in `run'
/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.10.2/bin/hammer:147:in `<top (required)>'
/usr/bin/hammer:23:in `load'
/usr/bin/hammer:23:in `<main>'

Expected results:
Some kind of validation message explaining that content source was not found by provided id should be shown.

Additional info:


Related issues

Related to Katello - Bug #24559: Hostgroups should use AssociationExistsValidator for content_sourceClosed
Copied to Foreman - Bug #21829: Specifying wrong foreign key id for object (such as host or hostgroup) via hammer/api throws SQL errorClosed2017-11-16

Associated revisions

Revision 18eb3558 (diff)
Added by Andrew Kofink about 2 years ago

Fixes #21689 - Validate content source in facet

This change should check that the content source exists in the
database only if a content_source_id is given for a host.

Requires https://github.com/theforeman/foreman/pull/5405

History

#1 Updated by The Foreman Bot over 2 years ago

  • Assignee set to Andrew Kofink
  • Status changed from New to Ready For Testing
  • Pull request https://github.com/Katello/katello/pull/7075 added

#2 Updated by Justin Sherrill over 2 years ago

  • Legacy Backlogs Release (now unused) set to 114
  • Subject changed from Specifying wrong content source id for host or hostgroup via hammer throws SQL error to Specifying wrong foreign key id for object (such as host or hostgroup) via hammer/api throws SQL error

#3 Updated by Justin Sherrill over 2 years ago

Foreman-only examples:

  1. hammer -p changeme hostgroup create --name=foobar123 --realm-id=99999
    Could not create the hostgroup:
    ERROR: insert or update on table "hostgroups" violates foreign key constraint "hostgroups_realms_id_fk"
    DETAIL: Key (realm_id)=(99999) is not present in table "realms".
  1. hammer -p changeme hostgroup create --name=foobar123 --operatingsystem-id=99999
    Could not create the hostgroup:
    ERROR: insert or update on table "hostgroups" violates foreign key constraint "hostgroups_operatingsystem_id_fk"
    DETAIL: Key (operatingsystem_id)=(99999) is not present in table "operatingsystems".

#4 Updated by Andrew Kofink over 2 years ago

  • Status changed from Ready For Testing to Assigned
  • Pull request deleted (https://github.com/Katello/katello/pull/7075)

#5 Updated by Andrew Kofink over 2 years ago

  • Copied to Bug #21829: Specifying wrong foreign key id for object (such as host or hostgroup) via hammer/api throws SQL error added

#6 Updated by The Foreman Bot about 2 years ago

  • Legacy Backlogs Release (now unused) deleted (114)
  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/Katello/katello/pull/7287 added

#7 Updated by Andrew Kofink about 2 years ago

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

#8 Updated by Justin Sherrill about 2 years ago

  • Legacy Backlogs Release (now unused) set to 338

#9 Updated by Andrew Kofink almost 2 years ago

  • Related to Bug #24559: Hostgroups should use AssociationExistsValidator for content_source added

Also available in: Atom PDF