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 1466240

Summary: GET /docker/api/v2/containers returns SQL error when sending optional compute_resource_id
Product: Red Hat Satellite Reporter: Stanislav Tkachenko <stkachen>
Component: Container Management - RuntimeAssignee: Marek Hulan <mhulan>
Status: CLOSED ERRATA QA Contact: Nikhil Kathole <nkathole>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.3.0CC: bkearney, mhulan, nkathole, sgraessl, zhunting
Target Milestone: UnspecifiedKeywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: tfm-rubygem-foreman_docker-3.1.0.1-1.fm1_14 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-02-21 16:54:37 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:

Description Stanislav Tkachenko 2017-06-29 10:23:57 UTC
Description of problem:
# With compute_resource_id
> $ curl -s -H "Content-Type: application/json" -H "Accept:application/json" -k -u "admin:changeme" -X GET -d '{"compute_resource_id": 1}' https://sat6.com/docker/api/v2/containers                                                                                                                 
> {
>   "error": {"message":"PG::Error: ERROR:  argument of WHERE must be type boolean, not type integer\nLINE 1: SELECT  \"containers\".* FROM \"containers\" WHERE (1) LIMIT 20 ...\n                                                        ^\n: SELECT  \"containers\".* FROM \"containers\" WHERE (1) LIMIT 20 OFFSET 0"}
> }


# Without compute_resource_id
> $ curl -s -H "Content-Type: application/json" -H "Accept:application/json" -k -u "admin:changeme" -X GET https://sat6.com/docker/api/v2/containers                                                                                                                  
> {
>  "total": 0,
> ...
> }

production log:
> 2017-06-29 04:42:18 a4fb040e [app] [I] Started GET "/docker/api/v2/containers" for 10.36.116.61 at 2017-06-29 04:42:18 -0400
> 2017-06-29 04:42:18 a4fb040e [app] [I] Processing by Api::V2::ContainersController#index as JSON
> 2017-06-29 04:42:18 a4fb040e [app] [I]   Parameters: {"compute_resource_id"=>1, "apiv"=>"v2", "container"=>{"compute_resource_id"=>1}}
> 2017-06-29 04:42:18 a4fb040e [app] [I]   Rendered /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_docker-3.1.0/app/views/api/v2/containers/index.json.rabl within api/v2/layouts/index_layout (4.1ms)
> 2017-06-29 04:42:18 a4fb040e [app] [W] Action failed
> | ActiveRecord::StatementInvalid: PG::Error: ERROR:  argument of WHERE must be type boolean, not type integer
> | LINE 1: SELECT  "containers".* FROM "containers" WHERE (1) LIMIT 20 ...
> |                                                         ^
> | : SELECT  "containers".* FROM "containers" WHERE (1) LIMIT 20 OFFSET 0


Version-Release number of selected component (if applicable):
* katello-3.4.1-1.el7sat.noarch
* foreman-1.15.1-1.el7sat.noarch
* satellite-6.3.0-16.0.beta.el7sat.noarch
* tfm-rubygem-foreman_docker-3.1.0-1.fm1_15.el7sat.noarch
* tfm-rubygem-docker-api-1.28.0-2.el7sat.noarch

How reproducible:
Always

Steps to Reproduce:
1. curl -s -H "Content-Type: application/json" -H "Accept:application/json" -k -u "admin:changeme" -X GET -d '{"compute_resource_id": 1}' https://sat6.com/docker/api/v2/containers      
2.
3.

Actual results:
SQL error

Expected results:
Containers should be listed

Additional info:

Comment 2 Sebastian Gräßl 2017-12-06 13:29:03 UTC
Created redmine issue http://projects.theforeman.org/issues/21893 from this bug

Comment 3 Marek Hulan 2017-12-11 15:46:13 UTC
PR available upstream

Comment 4 Satellite Program 2017-12-11 17:03:08 UTC
Upstream bug assigned to mhulan

Comment 5 Satellite Program 2017-12-11 17:03:12 UTC
Upstream bug assigned to mhulan

Comment 6 Satellite Program 2017-12-14 13:03:15 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue http://projects.theforeman.org/issues/21893 has been resolved.

Comment 9 Nikhil Kathole 2018-01-10 10:09:13 UTC
VERIFIED

Version tested:
Satellite 6.3 snap 31

Steps:

# curl -s -H "Content-Type: application/json" -H "Accept:application/json" -k -u "admin:changeme" -X GET -d '{"compute_resource_id": 4}' https://sat6/docker/api/v2/containers
{
  "total": 1,
  "subtotal": 1,
  "page": 1,
  "per_page": 20,
  "search": null,
  "sort": {
    "by": null,
    "order": null
  },
  "results": [{"command":"","compute_resource_id":4,"compute_resource_name":"docker","entrypoint":"","cpu_set":"","cpu_shares":null,"memory":"","tty":true,"attach_stdin":true,"attach_stdout":true,"attach_stderr":true,"repository_name":"centos","tag":"latest","registry_id":null,"registry_name":null,"created_at":"2018-01-10 09:56:04 UTC","updated_at":"2018-01-10 09:56:04 UTC","id":1,"name":"jovial_rosalind","uuid":"93a45905ef61e66e2e7cbdbe06724e5a7c74755355bcb734df756822a40e6451"}]
}

# curl -s -H "Content-Type: application/json" -H "Accept:application/json" -k -u "admin:changeme" -X GET -d '{"compute_resource_id": 1}' https://sat6/docker/api/v2/containers
{
  "total": 0,
  "subtotal": 0,
  "page": 1,
  "per_page": 20,
  "search": null,
  "sort": {
    "by": null,
    "order": null
  },
  "results": []
}

# curl -s -H "Content-Type: application/json" -H "Accept:application/json" -k -u "admin:changeme" -X GET https://sgi-uv20-01.rhts
.eng.bos.redhat.com/docker/api/v2/containers
{
  "total": 1,
  "subtotal": 1,
  "page": 1,
  "per_page": 20,
  "search": null,
  "sort": {
    "by": null,
    "order": null
  },
  "results": [{"command":"","compute_resource_id":4,"compute_resource_name":"docker","entrypoint":"","cpu_set":"","cpu_shares":null,"memory":"","tty":true,"attach_stdin":true,"attach_stdout":true,"attach_stderr":true,"repository_name":"centos","tag":"latest","registry_id":null,"registry_name":null,"created_at":"2018-01-10 09:56:04 UTC","updated_at":"2018-01-10 09:56:04 UTC","id":1,"name":"jovial_rosalind","uuid":"93a45905ef61e66e2e7cbdbe06724e5a7c74755355bcb734df756822a40e6451"}]
}

production.log ==>

2018-01-10 05:00:57 1a18b08c [app] [I] Started GET "/docker/api/v2/containers" for IP at 2018-01-10 05:00:57 -0500
2018-01-10 05:00:57 1a18b08c [app] [I] Processing by Api::V2::ContainersController#index as JSON
2018-01-10 05:00:57 1a18b08c [app] [I]   Parameters: {"compute_resource_id"=>4, "apiv"=>"v2", "container"=>{"compute_resource_id"=>4}}
2018-01-10 05:00:57 1a18b08c [app] [I] Current user: foreman_admin (administrator)
2018-01-10 05:00:57 1a18b08c [app] [I] Authorized user admin(Admin User)
2018-01-10 05:00:57 1a18b08c [app] [I] Current user: admin (administrator)
2018-01-10 05:00:57 1a18b08c [app] [I] Expire fragment views/tabs_and_title_records-3 (0.1ms)
2018-01-10 05:00:57 1a18b08c [app] [I] Expire fragment views/tabs_and_title_records-3 (0.1ms)
2018-01-10 05:00:57 1a18b08c [app] [I]   Rendered /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_docker-3.1.0.1/app/views/api/v2/containers/index.json.rabl within api/v2/layouts/index_layout (8.0ms)
2018-01-10 05:00:57 1a18b08c [app] [I] Completed 200 OK in 41ms (Views: 11.3ms | ActiveRecord: 5.0ms)

Comment 10 Satellite Program 2018-02-21 16:54:37 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-2018:0336