Bug 1863597

Summary: Inventory plug-in configuration(--enable-foreman-plugin-inventory-upload) makes DB inconsistent.
Product: Red Hat Satellite Reporter: Amar Huchchanavar <ahuchcha>
Component: InstallationAssignee: satellite6-bugs <satellite6-bugs>
Status: CLOSED ERRATA QA Contact: Devendra Singh <desingh>
Severity: high Docs Contact:
Priority: urgent    
Version: 6.7.0CC: ahumbe, aruzicka, bkearney, cmarinea, egolov, ekohlvan, gpayelka, jaudet, kkinge, mawerner, mmccune, molasaga, saydas, smajumda, wpinheir, zhunting
Target Milestone: 6.10.0Keywords: FieldEngineering, PrioBumpField, PrioBumpGSS, PrioBumpPM, PrioBumpQA, SubscriptionWatch, Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: foreman-installer-2.0.0 Doc Type: Known Issue
Doc Text:
Inventory plug-in configuration(--enable-foreman-plugin-inventory-upload) makes DB inconsistent
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-11-16 14:09:27 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 Amar Huchchanavar 2020-08-03 16:50:36 UTC
Description of problem:

https://access.redhat.com/documentation/en-us/red_hat_insights/2020-04/html/remediating_issues_across_your_red_hat_satellite_infrastructure_using_red_hat_insights/configuring-your-satellite-infrastructure-to-communicate-with-insights

# satellite-installer \
--enable-foreman-plugin-inventory-upload \
--foreman-proxy-plugin-remote-execution-ssh-install-key true

This command causing the below issue.

Getting below error while accessing - Hosts -All Hosts.
~~~
Oops, we're sorry but something went wrong PG::UndefinedTable: ERROR: relation "insights_hits" does not exist LINE 8: WHERE a.attrelid = '"insights_hits"'::regclas... ^ : SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod, c.collname, col_description(a.attrelid, a.attnum) AS comment FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum LEFT JOIN pg_type t ON a.atttypid = t.oid LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation WHERE a.attrelid = '"insights_hits"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum
~~~

Version-Release number of selected component (if applicable):
Satellite 6.7

How reproducible:
Not Always

Steps to Reproduce:
1. Take Satellite 6.7
2. Try to configure inventory upload plugin
# satellite-installer \
--enable-foreman-plugin-inventory-upload \
--foreman-proxy-plugin-remote-execution-ssh-install-key true


Actual results:
ActionView::Template::Error
PG::UndefinedTable: ERROR: relation "insights_hits" does not exist LINE 8: WHERE a.attrelid = '"insights_hits"'::regclas... ^ : SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod, c.collname, col_description(a.attrelid, a.attnum) AS comment FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum LEFT JOIN pg_type t ON a.atttypid = t.oid LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation WHERE a.attrelid = '"insights_hits"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:63:in `async_exec'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:63:in `block (2 levels) in query'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_
.
.
.
/usr/share/gems/gems/passenger-4.0.18/lib/phusion_passenger/rack/thread_handler_extension.rb:77:in `process_request'
/usr/share/gems/gems/passenger-4.0.18/lib/phusion_passenger/request_handler/thread_handler.rb:140:in `accept_and_process_next_request'
/usr/share/gems/gems/passenger-4.0.18/lib/phusion_passenger/request_handler/thread_handler.rb:108:in `main_loop'
/usr/share/gems/gems/passenger-4.0.18/lib/phusion_passenger/request_handler.rb:441:in `block (3 levels) in start_threads'
/opt/theforeman/tfm/root/usr/share/gems/gems/logging-2.2.2/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'

Expected results:
It should not throw that error.


Additional info:

Workaround Fix:
 # foreman-rake db:migrate --trace

Comment 4 jaudet 2020-08-11 15:39:28 UTC
I have a Satellite 6.7.2 and successfully executed `satellite-installer ...`, without hitting the error described above. However, when registering a client to the satellite, I hit a similar error:

[root@dhcp-2-168 ~]# subscription-manager register --org="Default_Organization" --environment="Library"
Registering to: my-sat.example.com:443/rhsm
Username: admin
Password: 
HTTP error (500 - Internal Server Error): PG::UndefinedTable: ERROR:  relation "insights_facets" does not exist
LINE 8:                WHERE a.attrelid = '"insights_facets"'::regcl...
                                          ^
:               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
                     c.collname, col_description(a.attrelid, a.attnum) AS comment
                FROM pg_attribute a
                LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
                LEFT JOIN pg_type t ON a.atttypid = t.oid
                LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
               WHERE a.attrelid = '"insights_facets"'::regclass
                 AND a.attnum > 0 AND NOT a.attisdropped
               ORDER BY a.attnum

Executing the workaround (`foreman-rake db:migrate --trace`) resolved the issue.

Comment 5 Mike McCune 2020-08-11 17:49:49 UTC
** WORKAROUND **

When installing the plugin, add the --upgrade flag:

satellite-installer \
--enable-foreman-plugin-inventory-upload \
--foreman-proxy-plugin-remote-execution-ssh-install-key true \
--upgrade

Will work to get this into the documentation as the technical solution to this will land in 6.8

Comment 6 Mike McCune 2020-08-11 17:53:13 UTC
Docs bug filed:

https://bugzilla.redhat.com/show_bug.cgi?id=1868118

Comment 9 Zach Huntington-Meath 2020-12-07 19:18:18 UTC
https://github.com/theforeman/puppet-foreman/commit/9c1787ad19b2cae407b25958095ecbf78757a959

Putting this here for now as it is the fix for this issue. I put this here because it failed trying to link this BZ to jira when I gave it this commit to link above.

Comment 10 Ewoud Kohl van Wijngaarden 2020-12-07 20:21:50 UTC
This should be part of foreman-installer 2.0.0 which was included in 6.8. At least in upstream it wasn't a safe thing to cherry pick due to db:migrate RPM post scripts. It was a combination of packaging and installer that allowed this to be fixed. I'm hesitant to picking this to 6.7.

Comment 11 Mike McCune 2020-12-08 18:18:18 UTC
This is a 6.7 bug only as it is solved in 6.8 with the installer. Adjusting bug to reflect this.

Comment 15 Devendra Singh 2021-07-08 09:28:15 UTC
Verified on 6.10 Snap7

Verification points:

1- Ran the installer command with "enable-foreman-plugin-rh-cloud" and "foreman-proxy-plugin-remote-execution-ssh-install-key", I didnt see any issue with that.

# satellite-installer --enable-foreman-plugin-rh-cloud --foreman-proxy-plugin-remote-execution-ssh-install-key true
2021-07-07 13:45:19 [NOTICE] [root] Loading installer configuration. This will take some time.
2021-07-07 13:45:26 [NOTICE] [root] Running installer with log based terminal output at level NOTICE.
2021-07-07 13:45:26 [NOTICE] [root] Use -l to set the terminal output log level to ERROR, WARN, NOTICE, INFO, or DEBUG. See --full-help for definitions.
......................
......................
Candlepin orphaned consumers: []
  Success!
2- Verified the enabled settings in installer helper

# satellite-installer --help|grep -A1 -e enable-foreman-plugin-rh-cloud -e foreman-proxy-plugin-remote-execution-ssh-install-key
    --[no-]enable-foreman-plugin-rh-cloud Enable 'foreman_plugin_rh_cloud' puppet module (default: true)

    --foreman-proxy-plugin-remote-execution-ssh-install-key  Automatically install generated SSH key to root authorized keys
                                  which allows managing this host through Remote Execution (current: true)



3- Register the client with satellite and it works.

4- Verified the fixed in a package.

# rpm -qa|grep foreman-installer-2
foreman-installer-2.5.1-1.el7sat.noarch

Comment 19 errata-xmlrpc 2021-11-16 14:09:27 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 (Moderate: Satellite 6.10 Release), 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-2021:4702