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 1488475 - Specifying wrong content source id for host or hostgroup via hammer throws SQL error
Summary: Specifying wrong content source id for host or hostgroup via hammer throws SQ...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Content Management
Version: 6.3.0
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: 6.5.0
Assignee: Andrew Kofink
QA Contact: Mirek Długosz
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-09-05 13:27 UTC by Andrii Balakhtar
Modified: 2019-11-05 22:24 UTC (History)
9 users (show)

Fixed In Version: hammer-cli-katello-0.13.5-1
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-05-14 12:36:36 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 21689 0 Normal Closed Specifying wrong foreign key id for object (such as host or hostgroup) via hammer/api throws SQL error 2020-08-03 08:39:29 UTC
Foreman Issue Tracker 24528 0 Normal Closed Content Source resource_name is smart_proxy, which is confusing to users 2020-08-03 08:39:29 UTC
Foreman Issue Tracker 24559 0 Normal Closed Hostgroups should use AssociationExistsValidator for content_source 2020-08-03 08:39:29 UTC
Red Hat Product Errata RHSA-2019:1222 0 None None None 2019-05-14 12:36:54 UTC

Description Andrii Balakhtar 2017-09-05 13:27:26 UTC
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:

Comment 2 Andrew Kofink 2017-11-16 13:56:11 UTC
Created redmine issue http://projects.theforeman.org/issues/21689 from this bug

Comment 3 Andrew Kofink 2017-11-29 19:19:27 UTC
This would require a change in Foreman and across Katello potentially. It exists whenever a model has relationships to other models via foreign keys.

Comment 13 Patrick Creech 2018-09-24 14:49:23 UTC
snap 23, not 63

Comment 17 Mirek Długosz 2019-03-07 12:57:40 UTC
There are two error messages displayed: "Content Source not found" (when --content-source is passed) or "Content source with given ID not found" (when --content-source-id is passed). These are consistent with what Jan saw before fix had to be reverted.

The same error messages are displayed for host create/update and hostgroup create/update.


#v+
# hammer host create --name bz1488475-host-create --organization "Default Organization" --location "Default Location" --medium-id="1" --ip="1.2.3.4" --operatingsystem-id="1" --lifecycle-environment-id="1" --domain-id="1" --partition-table-id="1" --mac="40:8f:bf:b6:ca:7a" --content-view-id=1 --architecture-id=1 --root-password="testtesttest" --content-source "This does not exist"
Could not create the host:
  Error: Content Source not found.
# hammer host create --name bz1488475-host-create --organization "Default Organization" --location "Default Location" --ip="1.2.3.4" --operatingsystem-id="1" --lifecycle-environment-id="1" --domain-id="2" --partition-table-id="1" --mac="40:8f:bf:b6:ca:7a" --content-view-id=1 --architecture-id=1 --hostgroup-id 1 --root-password="testtesttest" --content-source-id=9999
Could not create the host:
  Content source with given ID not found

# hammer host update --id 3 --content-source "This does not exist"
Could not update the host:
  Error: Content Source not found.
# hammer host update --id 3 --content-source-id=9999
Could not update the host:
  Content source with given ID not found

# hammer hostgroup create --name bz1488475-hostgroup-create --content-source "This does not exist"
Could not create the hostgroup:
  Error: Content Source not found.
# hammer hostgroup create --name bz1488475-hostgroup-create --content-source-id 9999
Could not create the hostgroup:
  Content source with given ID not found

# hammer hostgroup update --id 2 --content-source "This does not exist"
Could not update the hostgroup:
  Error: Content Source not found.
# hammer hostgroup update --id 2 --content-source-id 9999
Could not update the hostgroup:
  Content source with given ID not found
#v-


Version:
Satellite 6.5 snap 18
tfm-rubygem-katello-3.10.0.24-1.el7sat.noarch
foreman-1.20.1.10-1.el7sat.noarch
pulp-server-2.18.0-0.1.rc.el7sat.noarch
satellite-6.5.0-6.beta.el7sat.noarch
tfm-rubygem-hammer_cli-0.15.1.1-1.el7sat.noarch
tfm-rubygem-hammer_cli_csv-2.3.1-3.el7sat.noarch
tfm-rubygem-hammer_cli_foreman-0.15.1-1.el7sat.noarch
tfm-rubygem-hammer_cli_foreman_admin-0.0.8-3.el7sat.noarch
tfm-rubygem-hammer_cli_foreman_ansible-0.1.1-3.el7sat.noarch
tfm-rubygem-hammer_cli_foreman_bootdisk-0.1.3.3-5.el7sat.noarch
tfm-rubygem-hammer_cli_foreman_discovery-1.0.0-3.el7sat.noarch
tfm-rubygem-hammer_cli_foreman_docker-0.0.6.1-1.el7sat.noarch
tfm-rubygem-hammer_cli_foreman_openscap-0.1.6-2.el7sat.noarch
tfm-rubygem-hammer_cli_foreman_remote_execution-0.1.0-2.el7sat.noarch
tfm-rubygem-hammer_cli_foreman_tasks-0.0.13-1.el7sat.noarch
tfm-rubygem-hammer_cli_foreman_templates-0.1.2-1.el7sat.noarch
tfm-rubygem-hammer_cli_foreman_virt_who_configure-0.0.3-3.el7sat.noarch
tfm-rubygem-hammer_cli_katello-0.16.0.9-1.el7sat.noarch

Comment 19 errata-xmlrpc 2019-05-14 12:36:36 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2019:1222


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