Bug 1356213

Summary: PostgresAdmin.runcmd fails when overrides to the default options are provided
Product: Red Hat CloudForms Management Engine Reporter: Joe Vlcek <jvlcek>
Component: ApplianceAssignee: Joe Vlcek <jvlcek>
Status: CLOSED ERRATA QA Contact: Alex Newman <anewman>
Severity: medium Docs Contact:
Priority: high    
Version: 5.7.0CC: abellott, anewman, gtanzill, jdeubel, jhardy, jvlcek, kbrock, obarenbo, simaishi
Target Milestone: GAKeywords: ZStream
Target Release: 5.7.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard: appliance:database
Fixed In Version: 5.7.0.0 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1438674 (view as bug list) Environment:
Last Closed: 2017-01-04 12:57:22 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:
Bug Depends On:    
Bug Blocks: 1438674    

Description Joe Vlcek 2016-07-13 17:17:29 UTC
Description of problem:

When invoking PostgresAdmin.runcmd with overrides to the default options
a traceback is produced.


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


How reproducible:

This issue can be observed using rails console on an appliance configured
with a database.


Steps to Reproduce:
1. Log into an appliance with a database
2. cd /var/www/miq/vmdb
3. bundle exec rails console
4. Run for following code segment:

require 'util/postgres_admin'

opts={}
opts[:dbname] = "vmdb_production"
opts[:hostname] = "127.0.0.1"
opts[:username] = "root"
opts[:password] = "<specify the configured root password>"

result = PostgresAdmin.runcmd("psql", opts, :command => "SELECT name FROM users ;")


Actual results:

Errno::ENOENT: No such file or directory @ unlink_internal - /root/.pgpass
	from /var/www/miq/vmdb/gems/pending/util/postgres_admin.rb:273:in `delete'
	from /var/www/miq/vmdb/gems/pending/util/postgres_admin.rb:273:in `ensure in with_pgpass_file'
	from /var/www/miq/vmdb/gems/pending/util/postgres_admin.rb:273:in `with_pgpass_file'
	from /var/www/miq/vmdb/gems/pending/util/postgres_admin.rb:258:in `runcmd_with_logging'
	from /var/www/miq/vmdb/gems/pending/util/postgres_admin.rb:253:in `runcmd'
	from (irb):9
	from /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/gems/railties-5.0.0.rc2/lib/rails/commands/console.rb:65:in `start'
	from /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/gems/railties-5.0.0.rc2/lib/rails/commands/console_helper.rb:9:in `start'
	from /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/gems/railties-5.0.0.rc2/lib/rails/commands/commands_tasks.rb:78:in `console'
	from /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/gems/railties-5.0.0.rc2/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
	from /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/gems/railties-5.0.0.rc2/lib/rails/commands.rb:18:in `<top (required)>'
	from bin/rails:4:in `require'
	from bin/rails:4:in `<main>'



Expected results:

irb(main):009:0* result = PostgresAdmin.runcmd("psql", opts, :command => "SELECT name FROM users ;")
=> "           name            \n---------------------------\n Administrator\n Consumption Administrator\n(2 rows)\n\n"

Comment 2 Joe Vlcek 2016-07-13 17:20:49 UTC
This issue is blocking www.pivotaltracker.com/projects/1608513

The source of the failure is the arguements to File.open are out of order in
gems/pending/util/postgres_admin.rb

10.8.99.217 sb> diff gems/pending/util/postgres_admin.rb.FIX gems/pending/util/postgres_admin.rb.ORIG 
270c270
<     File.open(PGPASS_FILE, "w", 0600) { |f| f.write pass } if opts[:password]
---
>     File.open(PGPASS_FILE, 0600, "w") { |f| f.write pass } if opts[:password]

Comment 3 Joe Vlcek 2016-07-18 14:23:22 UTC
This is fixed by Keenan Brock's commit: 

https://github.com/ManageIQ/manageiq/commit/0dcef4f71016b704afee8b5642a95f4946fe5041

Comment 4 Dave Johnson 2016-07-20 01:44:35 UTC
*** Bug 1356212 has been marked as a duplicate of this bug. ***

Comment 5 Alex Newman 2016-10-06 15:52:02 UTC
5.7.0.3

Comment 9 errata-xmlrpc 2017-01-04 12:57:22 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://rhn.redhat.com/errata/RHBA-2017-0012.html