Skip to content

Commit

Permalink
(SIMP-6506) Out Of Memory Error (#190)
Browse files Browse the repository at this point in the history
- updated simp_version function to use Puppet::Util::Execution.execute
  instead of backtics.  This avoids a GLIBC error triggered by JRuby 9K.

SIMP-6506 #comment Also needs simp module update.
  • Loading branch information
jeannegreulich authored and trevor-vaughan committed May 10, 2019
1 parent 5e24a5d commit ae9a30a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 24 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* Thu May 09 2019 Jeanne Greulich <jeanne.greulich@onyxpoint.com> - 3.15.1-0
- Updated simp_version function to use Puppet::Util::Execution.execute
instead of backtics. This avioids a GLIBC error triggered by JRuby 9K when
backtics, system or %x are used.

* Fri Apr 12 2019 Michael Morrone <michael.morrone@onyxpoint.com> - 3.15.0-0
- Added `simplib__sshd_config` fact to check the contents of sshd_config file

Expand Down
16 changes: 10 additions & 6 deletions lib/puppet/functions/simplib/simp_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@
def simp_version(strip_whitespace = false)
retval = "unknown\n"

begin
# TODO Figure out under what circumstances the version string is prefaced
# with 'simp-'. This is not true for SIMP 6.x
if File.readable?('/etc/simp/simp.version')
# TODO Figure out under what circumstances the version string is prefaced
# with 'simp-'. This is not true for SIMP 6.x
version = File.read('/etc/simp/simp.version').gsub('simp-','')
retval = version unless version.strip.empty?
rescue
else
rpm_query = %q{PATH='/usr/local/bin:/usr/bin:/bin' rpm -q --qf '%{VERSION}-%{RELEASE}\n' simp 2>/dev/null}
version = `#{rpm_query}`
retval = version if $?.success?
begin
version = Puppet::Util::Execution.execute(rpm_query, :failonfail => true)
rescue Puppet::ExecutionFailure
version = nil
end
retval = version if version
end

retval.strip! if strip_whitespace
Expand Down
18 changes: 13 additions & 5 deletions lib/puppet/parser/functions/simp_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ module Puppet::Parser::Functions

retval = "unknown\n"

begin
retval = File.read('/etc/simp/simp.version').gsub('simp-','')
rescue
tmpval = %x{PATH='/usr/local/bin:/usr/bin:/bin'; rpm -q --qf '%{VERSION}-%{RELEASE}\n' simp}
$?.success? and retval = tmpval
if File.readable?('/etc/simp/simp.version')
# TODO Figure out under what circumstances the version string is prefaced
# with 'simp-'. This is not true for SIMP 6.x
version = File.read('/etc/simp/simp.version').gsub('simp-','')
retval = version unless version.strip.empty?
else
rpm_query = %q{PATH='/usr/local/bin:/usr/bin:/bin' rpm -q --qf '%{VERSION}-%{RELEASE}\n' simp 2>/dev/null}
begin
version = Puppet::Util::Execution.execute(rpm_query, :failonfail => true)
rescue Puppet::ExecutionFailure
version = nil
end
retval = version if version
end

retval
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simp-simplib",
"version": "3.15.0",
"version": "3.15.1",
"author": "SIMP Team",
"summary": "A collection of common SIMP functions, facts, and types",
"license": "Apache-2.0",
Expand Down
26 changes: 14 additions & 12 deletions spec/functions/simplib/simp_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
context 'a valid version exists in /etc/simp/simp.version' do
it 'should return the version with whitespace retained' do
File.expects(:read).with('/etc/simp/simp.version').returns(" 6.4.0-0\n")
File.stubs(:readable?).with('/etc/simp/simp.version').returns(true)
File.stubs(:read).with(regexp_matches(/metadata.json/), {:encoding => "utf-8"}).returns('')

is_expected.to run.and_return(" 6.4.0-0\n")
end

it "should return the version with 'simp-' stripped" do
File.stubs(:readable?).with('/etc/simp/simp.version').returns(true)
File.stubs(:read).with('/etc/simp/simp.version').returns("simp-5.4.0-0\n")
File.stubs(:read).with(regexp_matches(/metadata.json/), {:encoding => "utf-8"}).returns('')

is_expected.to run.and_return("5.4.0-0\n")
end

it 'should return the version with whitespace stripped when stripping is enabled' do
File.stubs(:readable?).with('/etc/simp/simp.version').returns(true)
File.stubs(:read).with('/etc/simp/simp.version').returns("6.4.0-0\n")
File.stubs(:read).with(regexp_matches(/metadata.json/), {:encoding => "utf-8"}).returns('')

Expand All @@ -28,6 +31,7 @@
context '/etc/simp/simp.version is empty' do
it 'should return unknown' do
File.stubs(:read).with('/etc/simp/simp.version').returns("")
File.stubs(:readable?).with('/etc/simp/simp.version').returns(true)
File.stubs(:read).with(regexp_matches(/metadata.json/), {:encoding => "utf-8"}).returns('')

is_expected.to run.and_return("unknown\n")
Expand All @@ -41,30 +45,28 @@

context 'rpm query succeeds' do
it 'should return the version with whitespace retained' do
File.stubs(:read).with('/etc/simp/simp.version').raises(Errno::ENOENT)
File.stubs(:read).with(regexp_matches(/metadata.json/), {:encoding => "utf-8"}).returns('')
subject.func.stubs(:`).with(rpm_query).returns("6.4.0-0\n")
$?.expects(:success?).returns(true)
File.stubs(:readable?).with('/etc/simp/simp.version').returns(false)
Puppet::Util::Execution.stubs(:execute).with(rpm_query, {:failonfail => true}).returns("6.4.0-0\n")

is_expected.to run.and_return("6.4.0-0\n")
end

it 'should return the version with whitespace stripped when stripping is enabled' do
File.stubs(:read).with('/etc/simp/simp.version').raises(Errno::ENOENT)
File.stubs(:read).with(regexp_matches(/metadata.json/), {:encoding => "utf-8"}).returns('')
subject.func.stubs(:`).with(rpm_query).returns("6.4.0-0\n")
$?.expects(:success?).returns(true)
File.stubs(:readable?).with('/etc/simp/simp.version').returns(false)
Puppet::Util::Execution.stubs(:execute).with(rpm_query, {:failonfail => true}).returns("6.4.0-0\n")

is_expected.to run.with_params(true).and_return('6.4.0-0')
end
end

context 'rpm query fails' do
it 'should return unknown' do
File.stubs(:read).with('/etc/simp/simp.version').raises(Errno::ENOENT)
File.stubs(:read).with(regexp_matches(/metadata.json/), {:encoding => "utf-8"}).returns('')
subject.func.stubs(:`).with(rpm_query).returns("package simp is not installed\n")
$?.expects(:success?).returns(false)
File.stubs(:readable?).with('/etc/simp/simp.version').returns(false)
Puppet::Util::Execution.stubs(:execute).with(rpm_query, {:failonfail => true}).raises(Puppet::ExecutionFailure, "Failed")
# ({
# :exitstatus => 2,
# :stdout => "package simp is not installed\n"
# })

is_expected.to run.and_return("unknown\n")
end
Expand Down

0 comments on commit ae9a30a

Please sign in to comment.