Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix postgresql::sql task when password is not set #1226

Merged
merged 1 commit into from
Feb 1, 2021
Merged

Fix postgresql::sql task when password is not set #1226

merged 1 commit into from
Feb 1, 2021

Conversation

smortex
Copy link
Collaborator

@smortex smortex commented Jan 13, 2021

When password is not set, { 'PGPASSWORD' => password } unless password.nil? evaluates to nil, setting env_hash to nil.

nil is then passed as the first argument of Open3.capture3 which
result in an exception:

/opt/puppetlabs/puppet/lib/ruby/2.7.0/open3.rb:213:in `spawn': no implicit conversion of nil into String (TypeError)
	from /opt/puppetlabs/puppet/lib/ruby/2.7.0/open3.rb:213:in `popen_run'
	from /opt/puppetlabs/puppet/lib/ruby/2.7.0/open3.rb:101:in `popen3'
	from /opt/puppetlabs/puppet/lib/ruby/2.7.0/open3.rb:281:in `capture3'
	from /opt/puppetlabs/mcollective/tasks-spool/899e9e0635bb53f1a09b4716548ff69f/files/sql.rb:13:in `get'
	from /opt/puppetlabs/mcollective/tasks-spool/899e9e0635bb53f1a09b4716548ff69f/files/sql.rb:27:in `<main>'

Make sure env_hash is always a hash to fix this issue.

@smortex smortex requested a review from a team as a code owner January 13, 2021 22:59
@sheenaajay
Copy link
Contributor

Thank you @smortex for your contribution.

@sheenaajay sheenaajay self-assigned this Jan 18, 2021
@codecov-io
Copy link

codecov-io commented Jan 19, 2021

Codecov Report

Merging #1226 (404698e) into main (08e3a51) will increase coverage by 0.37%.
The diff coverage is 54.54%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1226      +/-   ##
==========================================
+ Coverage   65.81%   66.18%   +0.37%     
==========================================
  Files          14       14              
  Lines         351      349       -2     
==========================================
  Hits          231      231              
+ Misses        120      118       -2     
Impacted Files Coverage Δ
...ns/postgresql/postgresql_acls_to_resources_hash.rb 0.00% <0.00%> (ø)
...b/puppet/functions/postgresql/postgresql_escape.rb 0.00% <0.00%> (ø)
...puppet/functions/postgresql/postgresql_password.rb 0.00% <ø> (ø)
lib/puppet/functions/postgresql_escape.rb 0.00% <ø> (ø)
lib/puppet/functions/postgresql_password.rb 0.00% <ø> (ø)
lib/puppet/provider/postgresql_conf/parsed.rb 100.00% <ø> (ø)
.../puppet/provider/postgresql_conn_validator/ruby.rb 80.00% <ø> (ø)
lib/puppet/type/postgresql_conf.rb 93.33% <ø> (ø)
lib/puppet/type/postgresql_conn_validator.rb 100.00% <ø> (ø)
lib/puppet/type/postgresql_replication_slot.rb 100.00% <ø> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0cda7bd...404698e. Read the comment docs.

When password is not set, `{ 'PGPASSWORD' => password } unless
password.nil?` evaluates to `nil`, setting `env_hash` to `nil`.

`nil` is then passed as the first argument of `Open3.capture3` which
result in an exception:

```
/opt/puppetlabs/puppet/lib/ruby/2.7.0/open3.rb:213:in `spawn': no implicit conversion of nil into String (TypeError)
	from /opt/puppetlabs/puppet/lib/ruby/2.7.0/open3.rb:213:in `popen_run'
	from /opt/puppetlabs/puppet/lib/ruby/2.7.0/open3.rb:101:in `popen3'
	from /opt/puppetlabs/puppet/lib/ruby/2.7.0/open3.rb:281:in `capture3'
	from /opt/puppetlabs/mcollective/tasks-spool/899e9e0635bb53f1a09b4716548ff69f/files/sql.rb:13:in `get'
	from /opt/puppetlabs/mcollective/tasks-spool/899e9e0635bb53f1a09b4716548ff69f/files/sql.rb:27:in `<main>'
```

Make sure `env_hash` is always a hash to fix this issue.
@sheenaajay
Copy link
Contributor

Thanks @smortex . We have timeout issues on centos 8 for travis. We have opened a ticket for the issue. Will be disabling them till the issue is sorted. So that it wont hold any PRS. Thanks for your contribution.

@sheenaajay sheenaajay merged commit 7d965b9 into puppetlabs:main Feb 1, 2021
@smortex smortex deleted the fix-task branch February 1, 2021 22:43
cegeka-jenkins pushed a commit to cegeka/puppet-postgresql that referenced this pull request Feb 3, 2022
Fix postgresql::sql task when password is not set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants